OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_ | 5 #ifndef GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_ |
6 #define GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_ | 6 #define GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1090 PermissionType type_; | 1090 PermissionType type_; |
1091 PermissionRole role_; | 1091 PermissionRole role_; |
1092 std::string value_; | 1092 std::string value_; |
1093 | 1093 |
1094 DISALLOW_COPY_AND_ASSIGN(PermissionsInsertRequest); | 1094 DISALLOW_COPY_AND_ASSIGN(PermissionsInsertRequest); |
1095 }; | 1095 }; |
1096 | 1096 |
1097 //========================== BatchUploadRequest ========================== | 1097 //========================== BatchUploadRequest ========================== |
1098 | 1098 |
1099 struct BatchUploadChildEntry { | 1099 struct BatchUploadChildEntry { |
1100 explicit BatchUploadChildEntry(UrlFetchRequestBase* request) | 1100 BatchUploadChildEntry() : request(NULL), prepared(false) {} |
1101 explicit BatchUploadChildEntry(BatchableRequestBase* request) | |
1101 : request(request), prepared(false) {} | 1102 : request(request), prepared(false) {} |
1102 UrlFetchRequestBase* request; | 1103 BatchableRequestBase* request; |
1103 bool prepared; | 1104 bool prepared; |
1104 }; | 1105 }; |
1105 | 1106 |
1106 class BatchUploadRequest : public UrlFetchRequestBase { | 1107 class BatchUploadRequest : public UrlFetchRequestBase { |
1107 public: | 1108 public: |
1108 BatchUploadRequest(RequestSender* sender, | 1109 BatchUploadRequest(RequestSender* sender, |
1109 const DriveApiUrlGenerator& url_generator); | 1110 const DriveApiUrlGenerator& url_generator); |
1110 ~BatchUploadRequest() override; | 1111 ~BatchUploadRequest() override; |
1111 | 1112 |
1112 // Adds request to the batch request. | 1113 // Adds request to the batch request. |
1113 void AddRequest(UrlFetchRequestBase* request); | 1114 void AddRequest(BatchableRequestBase* request); |
1114 | 1115 |
1115 // Completes building batch upload request, and starts to send the request to | 1116 // Completes building batch upload request, and starts to send the request to |
1116 // server. | 1117 // server. |
1117 void Commit(); | 1118 void Commit(); |
1118 | 1119 |
1119 // Obtains weak pointer of this. | 1120 // Obtains weak pointer of this. |
1120 base::WeakPtr<BatchUploadRequest> GetWeakPtrAsBatchUploadRequest(); | 1121 base::WeakPtr<BatchUploadRequest> GetWeakPtrAsBatchUploadRequest(); |
1121 | 1122 |
1123 // Set boundary. Only tests can use this method. | |
1124 void SetBoundaryForTesting(const std::string& boundary); | |
1125 | |
1122 // Obtains reference to RequestSender that owns the request. | 1126 // Obtains reference to RequestSender that owns the request. |
1123 RequestSender* sender() const { return sender_; } | 1127 RequestSender* sender() const { return sender_; } |
1128 | |
1129 // Obtains URLGenerator. | |
1124 DriveApiUrlGenerator url_generator() const { return url_generator_; } | 1130 DriveApiUrlGenerator url_generator() const { return url_generator_; } |
kinaba
2015/04/13 08:25:27
const DriveApiUrlGenerator& ?
hirono
2015/04/13 09:16:10
Done.
| |
1125 | 1131 |
1126 // Returns URL of this request. | 1132 // UrlFetchRequestBase overrides. |
1133 void Prepare(const PrepareCallback& callback) override; | |
1134 void Cancel() override; | |
1127 GURL GetURL() const override; | 1135 GURL GetURL() const override; |
1128 | 1136 net::URLFetcher::RequestType GetRequestType() const override; |
1137 std::vector<std::string> GetExtraRequestHeaders() const override; | |
1138 bool GetContentData( | |
1139 std::string* upload_content_type, | |
1140 std::string* upload_content) override; | |
1129 void ProcessURLFetchResults(const net::URLFetcher* source) override; | 1141 void ProcessURLFetchResults(const net::URLFetcher* source) override; |
1130 void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override; | 1142 void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override; |
1131 | 1143 |
1132 private: | 1144 private: |
1145 typedef void* RequestID; | |
1146 // Called after child requests' |Prepare| method. | |
1147 void OnChildRequestPrepared(RequestID request_id, DriveApiErrorCode result); | |
1148 | |
1149 // Complete |Prepare| if possible. | |
1150 void MayCompletePrepare(); | |
1151 | |
1152 // Process result for each child. | |
1153 void ProcessURLFetchResultsForChild(RequestID id, const std::string& body); | |
1154 | |
1133 RequestSender* const sender_; | 1155 RequestSender* const sender_; |
1134 const DriveApiUrlGenerator url_generator_; | 1156 const DriveApiUrlGenerator url_generator_; |
1135 std::vector<BatchUploadChildEntry> child_requests_; | 1157 std::map<RequestID, BatchUploadChildEntry> child_requests_; |
1158 | |
1159 PrepareCallback prepare_callback_; | |
1160 bool committed_; | |
1161 | |
1162 // Boundary of multipart body. | |
1163 std::string boundary_; | |
1164 | |
1165 // Multipart of child requests. | |
1166 ContentTypeAndData upload_content_; | |
1136 | 1167 |
1137 // Note: This should remain the last member so it'll be destroyed and | 1168 // Note: This should remain the last member so it'll be destroyed and |
1138 // invalidate its weak pointers before any other members are destroyed. | 1169 // invalidate its weak pointers before any other members are destroyed. |
1139 base::WeakPtrFactory<BatchUploadRequest> weak_ptr_factory_; | 1170 base::WeakPtrFactory<BatchUploadRequest> weak_ptr_factory_; |
1140 | 1171 |
1141 DISALLOW_COPY_AND_ASSIGN(BatchUploadRequest); | 1172 DISALLOW_COPY_AND_ASSIGN(BatchUploadRequest); |
1142 }; | 1173 }; |
1143 | 1174 |
1144 } // namespace drive | 1175 } // namespace drive |
1145 } // namespace google_apis | 1176 } // namespace google_apis |
1146 | 1177 |
1147 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_ | 1178 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_ |
OLD | NEW |