1 |
efrain |
1 |
/*
|
|
|
2 |
* Copyright 2020 Google LLC
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
#import <Foundation/Foundation.h>
|
|
|
18 |
|
|
|
19 |
#import "GoogleDataTransport/GDTCORLibrary/Internal/GDTCORUploader.h"
|
|
|
20 |
|
|
|
21 |
@protocol GDTCORStoragePromiseProtocol;
|
|
|
22 |
|
|
|
23 |
NS_ASSUME_NONNULL_BEGIN
|
|
|
24 |
|
|
|
25 |
/// The protocol defines methods to retrieve/update data shared between different upload operations.
|
|
|
26 |
@protocol GDTCCTUploadMetadataProvider <NSObject>
|
|
|
27 |
|
|
|
28 |
/** Returns a GDTCORClock object representing time after which a next upload attempt is allowed for
|
|
|
29 |
* the specified target. Upload is allowed now if `nil`. */
|
|
|
30 |
- (nullable GDTCORClock *)nextUploadTimeForTarget:(GDTCORTarget)target;
|
|
|
31 |
|
|
|
32 |
/** Stores or resets time after which a next upload attempt is allowed for the specified target. */
|
|
|
33 |
- (void)setNextUploadTime:(nullable GDTCORClock *)time forTarget:(GDTCORTarget)target;
|
|
|
34 |
|
|
|
35 |
/** Returns an API key for the specified target. */
|
|
|
36 |
- (nullable NSString *)APIKeyForTarget:(GDTCORTarget)target;
|
|
|
37 |
|
|
|
38 |
@end
|
|
|
39 |
|
|
|
40 |
/** Class capable of uploading events to the CCT backend. */
|
|
|
41 |
@interface GDTCCTUploadOperation : NSOperation
|
|
|
42 |
|
|
|
43 |
- (instancetype)init NS_UNAVAILABLE;
|
|
|
44 |
|
|
|
45 |
/** The designated initializer.
|
|
|
46 |
* @param target The events target to upload.
|
|
|
47 |
* @param conditions A set of upload conditions. The conditions affect the set of events to be
|
|
|
48 |
* uploaded, e.g. events with some QoS are not uploaded on a cellular network, etc.
|
|
|
49 |
* @param uploadURL The backend URL to upload the events.
|
|
|
50 |
* @param queue A queue to dispatch async upload steps.
|
|
|
51 |
* @param storage A storage object to fetch events for upload.
|
|
|
52 |
* @param metadataProvider An object to retrieve/update data shared between different upload
|
|
|
53 |
* operations.
|
|
|
54 |
* @return An instance of GDTCCTUploadOperation ready to be added to an NSOperationQueue.
|
|
|
55 |
*/
|
|
|
56 |
- (instancetype)initWithTarget:(GDTCORTarget)target
|
|
|
57 |
conditions:(GDTCORUploadConditions)conditions
|
|
|
58 |
uploadURL:(NSURL *)uploadURL
|
|
|
59 |
queue:(dispatch_queue_t)queue
|
|
|
60 |
storage:(id<GDTCORStoragePromiseProtocol>)storage
|
|
|
61 |
metadataProvider:(id<GDTCCTUploadMetadataProvider>)metadataProvider
|
|
|
62 |
NS_DESIGNATED_INITIALIZER;
|
|
|
63 |
|
|
|
64 |
/** YES if a batch upload attempt was performed. NO otherwise. If NO for the finished operation,
|
|
|
65 |
* then there were no events suitable for upload. */
|
|
|
66 |
@property(nonatomic, readonly) BOOL uploadAttempted;
|
|
|
67 |
|
|
|
68 |
/** The queue on which all CCT uploading will occur. */
|
|
|
69 |
@property(nonatomic, readonly) dispatch_queue_t uploaderQueue;
|
|
|
70 |
|
|
|
71 |
/** The current upload task. */
|
|
|
72 |
@property(nullable, nonatomic, readonly) NSURLSessionUploadTask *currentTask;
|
|
|
73 |
|
|
|
74 |
@end
|
|
|
75 |
|
|
|
76 |
NS_ASSUME_NONNULL_END
|