Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// Copyright 2020 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
 
15
#import "FirebasePerformance/Sources/AppActivity/FPRTraceBackgroundActivityTracker.h"
16
 
17
#import "FirebasePerformance/Sources/AppActivity/FPRSessionDetails.h"
18
 
19
#import "FirebasePerformance/Sources/FIRPerformance+Internal.h"
20
 
21
/** Possible checkpoint states of network trace */
22
typedef NS_ENUM(NSInteger, FPRNetworkTraceCheckpointState) {
23
  FPRNetworkTraceCheckpointStateUnknown,
24
 
25
  // Network request has been initiated.
26
  FPRNetworkTraceCheckpointStateInitiated,
27
 
28
  // Network request is completed (All necessary uploads for the request is complete).
29
  FPRNetworkTraceCheckpointStateRequestCompleted,
30
 
31
  // Network request has received its first response. There could be more.
32
  FPRNetworkTraceCheckpointStateResponseReceived,
33
 
34
  // Network request has completed (Could be network error/request successful completion).
35
  FPRNetworkTraceCheckpointStateResponseCompleted
36
};
37
 
38
@protocol FPRNetworkResponseHandler <NSObject>
39
 
40
/**
41
 * Records the size of the file that is uploaded during the request.
42
 *
43
 * @param URL The URL object that is being used for uploading from the network request.
44
 */
45
- (void)didUploadFileWithURL:(nullable NSURL *)URL;
46
 
47
/**
48
 * Records the amount of data that is fetched during the request. This can be called multiple times
49
 * when the network delegate comes back with some data.
50
 *
51
 * @param data The data object as received from the network request.
52
 */
53
- (void)didReceiveData:(nullable NSData *)data;
54
 
55
/**
56
 * Records the size of the file that is fetched during the request. This can be called multiple
57
 * times when the network delegate comes back with some data.
58
 *
59
 * @param URL The URL object as received from the network request.
60
 */
61
- (void)didReceiveFileURL:(nullable NSURL *)URL;
62
 
63
/**
64
 * Records the end state of the network request. This is usually called at the end of the network
65
 * request with a valid response or an error.
66
 *
67
 * @param response Response of the network request.
68
 * @param error Error with the network request.
69
 */
70
- (void)didCompleteRequestWithResponse:(nullable NSURLResponse *)response
71
                                 error:(nullable NSError *)error;
72
 
73
@end
74
 
75
/**
76
 * FPRNetworkTrace object contains information about an NSURLRequest. Every object contains
77
 * information about the URL, type of request, and details of the response.
78
 */
79
NS_EXTENSION_UNAVAILABLE("Firebase Performance is not supported for extensions.")
80
@interface FPRNetworkTrace : NSObject <FPRNetworkResponseHandler, FIRPerformanceAttributable>
81
 
82
/** @brief Start time of the trace since epoch. */
83
@property(nonatomic, assign, readonly) NSTimeInterval startTimeSinceEpoch;
84
 
85
/** @brief The size of the request. The value is in bytes. */
86
@property(nonatomic) int64_t requestSize;
87
 
88
/** @brief The response size for the request. The value is in bytes. */
89
@property(nonatomic) int64_t responseSize;
90
 
91
/** @brief The HTTP response code for the request. */
92
@property(nonatomic) int32_t responseCode;
93
 
94
/** @brief Yes if a valid response code is set, NO otherwise. */
95
@property(nonatomic) BOOL hasValidResponseCode;
96
 
97
/** @brief The content type of the request as received from the server. */
98
@property(nonatomic, copy, nullable) NSString *responseContentType;
99
 
100
/** @brief The checkpoint states for the request. The key to the dictionary is the value referred in
101
 * enum FPRNetworkTraceCheckpointState mentioned above. The value is the number of seconds since the
102
 * reference date.
103
 */
104
@property(nonatomic, readonly, nullable) NSDictionary<NSString *, NSNumber *> *checkpointStates;
105
 
106
/** @brief The network request object. */
107
@property(nonatomic, readonly, nullable) NSURLRequest *URLRequest;
108
 
109
/** @brief The URL string with all the query params cleaned. The URL string will be of the format:
110
 *  scheme:[//[user:password@]host[:port]][/]path.
111
 */
112
@property(nonatomic, readonly, nullable) NSString *trimmedURLString;
113
 
114
/** @brief Error object received with the network response. */
115
@property(nonatomic, readonly, nullable) NSError *responseError;
116
 
117
/** Background state of the trace. */
118
@property(nonatomic, readonly) FPRTraceState backgroundTraceState;
119
 
120
/** @brief List of sessions the trace is associated with. */
121
@property(nonnull, atomic, readonly) NSArray<FPRSessionDetails *> *sessions;
122
 
123
/** @brief Serial queue to manage usage of session Ids. */
124
@property(nonatomic, readonly, nonnull) dispatch_queue_t sessionIdSerialQueue;
125
 
126
/**
127
 * Associate a network trace to an object project. This uses ObjC runtime to associate the network
128
 * trace with the object provided.
129
 *
130
 * @param networkTrace Network trace object to be associated with the provided object.
131
 * @param object The provided object to whom the network trace object will be associated with.
132
 */
133
+ (void)addNetworkTrace:(nonnull FPRNetworkTrace *)networkTrace toObject:(nonnull id)object;
134
 
135
/**
136
 * Gets the network trace associated with the provided object. If the network trace is not
137
 * associated with the object, return nil. This uses ObjC runtime to fetch the object.
138
 *
139
 * @param object The provided object from which the network object would be fetched.
140
 * @return The network trace object associated with the provided object.
141
 */
142
+ (nullable FPRNetworkTrace *)networkTraceFromObject:(nonnull id)object;
143
 
144
/**
145
 * Remove the network trace associated with the provided object. If the network trace is not
146
 * associated with the object, does nothing. This uses ObjC runtime to remove the object.
147
 *
148
 * @param object The provided object from which the network object would be removed.
149
 */
150
+ (void)removeNetworkTraceFromObject:(nonnull id)object;
151
 
152
/**
153
 * Creates an instance of the FPRNetworkTrace with the provided URL and the HTTP method.
154
 *
155
 * @param URLRequest NSURLRequest object.
156
 * @return An instance of FPRNetworkTrace.
157
 */
158
- (nullable instancetype)initWithURLRequest:(nonnull NSURLRequest *)URLRequest
159
    NS_DESIGNATED_INITIALIZER;
160
 
161
- (nullable instancetype)init NS_UNAVAILABLE;
162
 
163
/**
164
 * Records the begining of the network request. This is usually called just before initiating the
165
 * request.
166
 */
167
- (void)start;
168
 
169
/**
170
 * Checkpoints a particular state of the network request. Checkpoint states are listed in the enum
171
 * FPRNetworkTraceCheckpointState mentioned above.
172
 *
173
 * @param state A state as mentioned in enum FPRNetworkTraceCheckpointState.
174
 */
175
- (void)checkpointState:(FPRNetworkTraceCheckpointState)state;
176
 
177
/**
178
 * Provides the time difference between the provided checkpoint states in seconds. If the starting
179
 * checkpoint state is greater than the ending checkpoint state, the return value will be negative.
180
 * If either of the states does not exist, returns 0.
181
 *
182
 * @param startState The starting checkpoint state.
183
 * @param endState The ending checkpoint state.
184
 * @return Difference between the ending checkpoint state and starting checkpoint state in seconds.
185
 */
186
- (NSTimeInterval)timeIntervalBetweenCheckpointState:(FPRNetworkTraceCheckpointState)startState
187
                                            andState:(FPRNetworkTraceCheckpointState)endState;
188
/**
189
 * Checks if the network trace is valid.
190
 *
191
 * @return true if the network trace is valid.
192
 */
193
- (BOOL)isValid;
194
 
195
@end