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 #include "components/drive/service/drive_api_service.h" | 5 #include "components/drive/service/drive_api_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 base::SequencedTaskRunner* task_runner, | 182 base::SequencedTaskRunner* task_runner, |
183 const google_apis::DriveApiUrlGenerator& url_generator, | 183 const google_apis::DriveApiUrlGenerator& url_generator, |
184 const google_apis::CancelCallback& cancel_callback) | 184 const google_apis::CancelCallback& cancel_callback) |
185 : batch_request_(batch_request), | 185 : batch_request_(batch_request), |
186 task_runner_(task_runner), | 186 task_runner_(task_runner), |
187 url_generator_(url_generator), | 187 url_generator_(url_generator), |
188 cancel_callback_(cancel_callback) { | 188 cancel_callback_(cancel_callback) { |
189 } | 189 } |
190 | 190 |
191 BatchRequestConfigurator::~BatchRequestConfigurator() { | 191 BatchRequestConfigurator::~BatchRequestConfigurator() { |
| 192 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
192 // The batch requst has not been committed. | 193 // The batch requst has not been committed. |
193 if (batch_request_) | 194 if (batch_request_) |
194 cancel_callback_.Run(); | 195 cancel_callback_.Run(); |
195 } | 196 } |
196 | 197 |
197 google_apis::CancelCallback BatchRequestConfigurator::MultipartUploadNewFile( | 198 google_apis::CancelCallback BatchRequestConfigurator::MultipartUploadNewFile( |
198 const std::string& content_type, | 199 const std::string& content_type, |
199 int64_t content_length, | 200 int64_t content_length, |
200 const std::string& parent_resource_id, | 201 const std::string& parent_resource_id, |
201 const std::string& title, | 202 const std::string& title, |
202 const base::FilePath& local_file_path, | 203 const base::FilePath& local_file_path, |
203 const UploadNewFileOptions& options, | 204 const UploadNewFileOptions& options, |
204 const google_apis::FileResourceCallback& callback, | 205 const google_apis::FileResourceCallback& callback, |
205 const google_apis::ProgressCallback& progress_callback) { | 206 const google_apis::ProgressCallback& progress_callback) { |
206 DCHECK(CalledOnValidThread()); | 207 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
207 DCHECK(!callback.is_null()); | 208 DCHECK(!callback.is_null()); |
208 | 209 |
209 std::unique_ptr<google_apis::BatchableDelegate> delegate( | 210 std::unique_ptr<google_apis::BatchableDelegate> delegate( |
210 new google_apis::drive::MultipartUploadNewFileDelegate( | 211 new google_apis::drive::MultipartUploadNewFileDelegate( |
211 task_runner_.get(), title, parent_resource_id, content_type, | 212 task_runner_.get(), title, parent_resource_id, content_type, |
212 content_length, options.modified_date, options.last_viewed_by_me_date, | 213 content_length, options.modified_date, options.last_viewed_by_me_date, |
213 local_file_path, options.properties, url_generator_, callback, | 214 local_file_path, options.properties, url_generator_, callback, |
214 progress_callback)); | 215 progress_callback)); |
215 // Batch request can be null when pre-authorization for the requst is failed | 216 // Batch request can be null when pre-authorization for the requst is failed |
216 // in request sender. | 217 // in request sender. |
217 if (batch_request_) | 218 if (batch_request_) |
218 batch_request_->AddRequest(delegate.release()); | 219 batch_request_->AddRequest(delegate.release()); |
219 else | 220 else |
220 delegate->NotifyError(DRIVE_OTHER_ERROR); | 221 delegate->NotifyError(DRIVE_OTHER_ERROR); |
221 return cancel_callback_; | 222 return cancel_callback_; |
222 } | 223 } |
223 | 224 |
224 google_apis::CancelCallback | 225 google_apis::CancelCallback |
225 BatchRequestConfigurator::MultipartUploadExistingFile( | 226 BatchRequestConfigurator::MultipartUploadExistingFile( |
226 const std::string& content_type, | 227 const std::string& content_type, |
227 int64_t content_length, | 228 int64_t content_length, |
228 const std::string& resource_id, | 229 const std::string& resource_id, |
229 const base::FilePath& local_file_path, | 230 const base::FilePath& local_file_path, |
230 const UploadExistingFileOptions& options, | 231 const UploadExistingFileOptions& options, |
231 const google_apis::FileResourceCallback& callback, | 232 const google_apis::FileResourceCallback& callback, |
232 const google_apis::ProgressCallback& progress_callback) { | 233 const google_apis::ProgressCallback& progress_callback) { |
233 DCHECK(CalledOnValidThread()); | 234 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
234 DCHECK(!callback.is_null()); | 235 DCHECK(!callback.is_null()); |
235 | 236 |
236 std::unique_ptr<google_apis::BatchableDelegate> delegate( | 237 std::unique_ptr<google_apis::BatchableDelegate> delegate( |
237 new google_apis::drive::MultipartUploadExistingFileDelegate( | 238 new google_apis::drive::MultipartUploadExistingFileDelegate( |
238 task_runner_.get(), options.title, resource_id, | 239 task_runner_.get(), options.title, resource_id, |
239 options.parent_resource_id, content_type, content_length, | 240 options.parent_resource_id, content_type, content_length, |
240 options.modified_date, options.last_viewed_by_me_date, | 241 options.modified_date, options.last_viewed_by_me_date, |
241 local_file_path, options.etag, options.properties, url_generator_, | 242 local_file_path, options.etag, options.properties, url_generator_, |
242 callback, progress_callback)); | 243 callback, progress_callback)); |
243 // Batch request can be null when pre-authorization for the requst is failed | 244 // Batch request can be null when pre-authorization for the requst is failed |
244 // in request sender. | 245 // in request sender. |
245 if (batch_request_) | 246 if (batch_request_) |
246 batch_request_->AddRequest(delegate.release()); | 247 batch_request_->AddRequest(delegate.release()); |
247 else | 248 else |
248 delegate->NotifyError(DRIVE_OTHER_ERROR); | 249 delegate->NotifyError(DRIVE_OTHER_ERROR); |
249 return cancel_callback_; | 250 return cancel_callback_; |
250 } | 251 } |
251 | 252 |
252 void BatchRequestConfigurator::Commit() { | 253 void BatchRequestConfigurator::Commit() { |
253 DCHECK(CalledOnValidThread()); | 254 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
254 if (!batch_request_) | 255 if (!batch_request_) |
255 return; | 256 return; |
256 batch_request_->Commit(); | 257 batch_request_->Commit(); |
257 batch_request_.reset(); | 258 batch_request_.reset(); |
258 } | 259 } |
259 | 260 |
260 DriveAPIService::DriveAPIService( | 261 DriveAPIService::DriveAPIService( |
261 OAuth2TokenService* oauth2_token_service, | 262 OAuth2TokenService* oauth2_token_service, |
262 net::URLRequestContextGetter* url_request_context_getter, | 263 net::URLRequestContextGetter* url_request_context_getter, |
263 base::SequencedTaskRunner* blocking_task_runner, | 264 base::SequencedTaskRunner* blocking_task_runner, |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 // RequestSender before the request is committed because the request has a | 915 // RequestSender before the request is committed because the request has a |
915 // reference to RequestSender and we should ensure to delete the request when | 916 // reference to RequestSender and we should ensure to delete the request when |
916 // the sender is deleted. Resolve the circulating dependency and fix it. | 917 // the sender is deleted. Resolve the circulating dependency and fix it. |
917 const google_apis::CancelCallback callback = | 918 const google_apis::CancelCallback callback = |
918 sender_->StartRequestWithAuthRetry(std::move(request)); | 919 sender_->StartRequestWithAuthRetry(std::move(request)); |
919 return base::MakeUnique<BatchRequestConfigurator>( | 920 return base::MakeUnique<BatchRequestConfigurator>( |
920 weak_ref, sender_->blocking_task_runner(), url_generator_, callback); | 921 weak_ref, sender_->blocking_task_runner(), url_generator_, callback); |
921 } | 922 } |
922 | 923 |
923 } // namespace drive | 924 } // namespace drive |
OLD | NEW |