Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: chrome/browser/drive/drive_api_service.cc

Issue 23549003: Refactor GetChangelistRequest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/google_apis/drive_api_requests.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/drive/drive_api_service.h" 5 #include "chrome/browser/drive/drive_api_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 18 matching lines...) Expand all
29 using google_apis::CancelCallback; 29 using google_apis::CancelCallback;
30 using google_apis::ChangeList; 30 using google_apis::ChangeList;
31 using google_apis::DownloadActionCallback; 31 using google_apis::DownloadActionCallback;
32 using google_apis::EntryActionCallback; 32 using google_apis::EntryActionCallback;
33 using google_apis::FileList; 33 using google_apis::FileList;
34 using google_apis::FileResource; 34 using google_apis::FileResource;
35 using google_apis::GDATA_OTHER_ERROR; 35 using google_apis::GDATA_OTHER_ERROR;
36 using google_apis::GDATA_PARSE_ERROR; 36 using google_apis::GDATA_PARSE_ERROR;
37 using google_apis::GDataErrorCode; 37 using google_apis::GDataErrorCode;
38 using google_apis::AboutResourceCallback; 38 using google_apis::AboutResourceCallback;
39 using google_apis::GetChangelistRequest;
40 using google_apis::GetContentCallback; 39 using google_apis::GetContentCallback;
41 using google_apis::GetResourceEntryCallback; 40 using google_apis::GetResourceEntryCallback;
42 using google_apis::GetResourceEntryRequest; 41 using google_apis::GetResourceEntryRequest;
43 using google_apis::GetResourceListCallback; 42 using google_apis::GetResourceListCallback;
44 using google_apis::GetShareUrlCallback; 43 using google_apis::GetShareUrlCallback;
45 using google_apis::HTTP_NOT_IMPLEMENTED; 44 using google_apis::HTTP_NOT_IMPLEMENTED;
46 using google_apis::HTTP_SUCCESS; 45 using google_apis::HTTP_SUCCESS;
47 using google_apis::InitiateUploadCallback; 46 using google_apis::InitiateUploadCallback;
48 using google_apis::Link; 47 using google_apis::Link;
49 using google_apis::ProgressCallback; 48 using google_apis::ProgressCallback;
50 using google_apis::RequestSender; 49 using google_apis::RequestSender;
51 using google_apis::ResourceEntry; 50 using google_apis::ResourceEntry;
52 using google_apis::ResourceList; 51 using google_apis::ResourceList;
53 using google_apis::UploadRangeCallback; 52 using google_apis::UploadRangeCallback;
54 using google_apis::UploadRangeResponse; 53 using google_apis::UploadRangeResponse;
55 using google_apis::drive::AboutGetRequest; 54 using google_apis::drive::AboutGetRequest;
56 using google_apis::drive::AppsListRequest; 55 using google_apis::drive::AppsListRequest;
56 using google_apis::drive::ChangesListRequest;
57 using google_apis::drive::ContinueGetFileListRequest; 57 using google_apis::drive::ContinueGetFileListRequest;
58 using google_apis::drive::CopyResourceRequest; 58 using google_apis::drive::CopyResourceRequest;
59 using google_apis::drive::CreateDirectoryRequest; 59 using google_apis::drive::CreateDirectoryRequest;
60 using google_apis::drive::DeleteResourceRequest; 60 using google_apis::drive::DeleteResourceRequest;
61 using google_apis::drive::DownloadFileRequest; 61 using google_apis::drive::DownloadFileRequest;
62 using google_apis::drive::FilesGetRequest; 62 using google_apis::drive::FilesGetRequest;
63 using google_apis::drive::FilesListRequest; 63 using google_apis::drive::FilesListRequest;
64 using google_apis::drive::GetUploadStatusRequest; 64 using google_apis::drive::GetUploadStatusRequest;
65 using google_apis::drive::InitiateUploadExistingFileRequest; 65 using google_apis::drive::InitiateUploadExistingFileRequest;
66 using google_apis::drive::InitiateUploadNewFileRequest; 66 using google_apis::drive::InitiateUploadNewFileRequest;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 203 }
204 204
205 // Convert the value on blocking pool. 205 // Convert the value on blocking pool.
206 base::PostTaskAndReplyWithResult( 206 base::PostTaskAndReplyWithResult(
207 blocking_task_runner.get(), 207 blocking_task_runner.get(),
208 FROM_HERE, 208 FROM_HERE,
209 base::Bind(&ConvertFileListToResourceList, base::Passed(&value)), 209 base::Bind(&ConvertFileListToResourceList, base::Passed(&value)),
210 base::Bind(&DidParseResourceListOnBlockingPool, callback)); 210 base::Bind(&DidParseResourceListOnBlockingPool, callback));
211 } 211 }
212 212
213 // Thin adapter of CreateFromChangeList.
214 scoped_ptr<ResourceList> ConvertChangeListToResourceList(
215 scoped_ptr<ChangeList> change_list) {
216 return ResourceList::CreateFromChangeList(*change_list);
217 }
218
219 // Converts the FileList value to ResourceList on blocking pool and runs
220 // |callback| on the UI thread.
221 void ConvertChangeListToResourceListOnBlockingPoolAndRun(
222 scoped_refptr<base::TaskRunner> blocking_task_runner,
223 const GetResourceListCallback& callback,
224 GDataErrorCode error,
225 scoped_ptr<ChangeList> value) {
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
227 DCHECK(!callback.is_null());
228
229 if (!value) {
230 callback.Run(error, scoped_ptr<ResourceList>());
231 return;
232 }
233
234 // Convert the value on blocking pool.
235 base::PostTaskAndReplyWithResult(
236 blocking_task_runner.get(),
237 FROM_HERE,
238 base::Bind(&ConvertChangeListToResourceList, base::Passed(&value)),
239 base::Bind(&DidParseResourceListOnBlockingPool, callback));
240 }
241
213 // Parses the FileResource value to ResourceEntry for upload range request, 242 // Parses the FileResource value to ResourceEntry for upload range request,
214 // and runs |callback| on the UI thread. 243 // and runs |callback| on the UI thread.
215 void ParseResourceEntryForUploadRangeAndRun( 244 void ParseResourceEntryForUploadRangeAndRun(
216 const UploadRangeCallback& callback, 245 const UploadRangeCallback& callback,
217 const UploadRangeResponse& response, 246 const UploadRangeResponse& response,
218 scoped_ptr<FileResource> value) { 247 scoped_ptr<FileResource> value) {
219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
220 DCHECK(!callback.is_null()); 249 DCHECK(!callback.is_null());
221 250
222 if (!value) { 251 if (!value) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 373
345 CancelCallback DriveAPIService::GetAllResourceList( 374 CancelCallback DriveAPIService::GetAllResourceList(
346 const GetResourceListCallback& callback) { 375 const GetResourceListCallback& callback) {
347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
348 DCHECK(!callback.is_null()); 377 DCHECK(!callback.is_null());
349 378
350 // The simplest way to fetch the all resources list looks files.list method, 379 // The simplest way to fetch the all resources list looks files.list method,
351 // but it seems impossible to know the returned list's changestamp. 380 // but it seems impossible to know the returned list's changestamp.
352 // Thus, instead, we use changes.list method with includeDeleted=false here. 381 // Thus, instead, we use changes.list method with includeDeleted=false here.
353 // The returned list should contain only resources currently existing. 382 // The returned list should contain only resources currently existing.
354 return sender_->StartRequestWithRetry( 383 ChangesListRequest* request = new ChangesListRequest(
355 new GetChangelistRequest( 384 sender_.get(), url_generator_,
356 sender_.get(), 385 base::Bind(&ConvertChangeListToResourceListOnBlockingPoolAndRun,
357 url_generator_, 386 blocking_task_runner_, callback));
358 false, // include deleted 387 request->set_include_deleted(false);
359 0, 388 return sender_->StartRequestWithRetry(request);
360 kMaxNumFilesResourcePerRequest,
361 base::Bind(&ParseResourceListOnBlockingPoolAndRun,
362 blocking_task_runner_,
363 callback)));
364 } 389 }
365 390
366 CancelCallback DriveAPIService::GetResourceListInDirectory( 391 CancelCallback DriveAPIService::GetResourceListInDirectory(
367 const std::string& directory_resource_id, 392 const std::string& directory_resource_id,
368 const GetResourceListCallback& callback) { 393 const GetResourceListCallback& callback) {
369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
370 DCHECK(!directory_resource_id.empty()); 395 DCHECK(!directory_resource_id.empty());
371 DCHECK(!callback.is_null()); 396 DCHECK(!callback.is_null());
372 397
373 // Because children.list method on Drive API v2 returns only the list of 398 // Because children.list method on Drive API v2 returns only the list of
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 458
434 return sender_->StartRequestWithRetry(request); 459 return sender_->StartRequestWithRetry(request);
435 } 460 }
436 461
437 CancelCallback DriveAPIService::GetChangeList( 462 CancelCallback DriveAPIService::GetChangeList(
438 int64 start_changestamp, 463 int64 start_changestamp,
439 const GetResourceListCallback& callback) { 464 const GetResourceListCallback& callback) {
440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 465 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
441 DCHECK(!callback.is_null()); 466 DCHECK(!callback.is_null());
442 467
443 return sender_->StartRequestWithRetry( 468 ChangesListRequest* request = new ChangesListRequest(
444 new GetChangelistRequest( 469 sender_.get(), url_generator_,
445 sender_.get(), 470 base::Bind(&ConvertChangeListToResourceListOnBlockingPoolAndRun,
446 url_generator_, 471 blocking_task_runner_, callback));
447 true, // include deleted 472 request->set_max_results(kMaxNumFilesResourcePerRequest);
448 start_changestamp, 473 request->set_start_change_id(start_changestamp);
449 kMaxNumFilesResourcePerRequest, 474 return sender_->StartRequestWithRetry(request);
450 base::Bind(&ParseResourceListOnBlockingPoolAndRun,
451 blocking_task_runner_,
452 callback)));
453 } 475 }
454 476
455 CancelCallback DriveAPIService::ContinueGetResourceList( 477 CancelCallback DriveAPIService::ContinueGetResourceList(
456 const GURL& override_url, 478 const GURL& override_url,
457 const GetResourceListCallback& callback) { 479 const GetResourceListCallback& callback) {
458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
459 DCHECK(!callback.is_null()); 481 DCHECK(!callback.is_null());
460 482
461 return sender_->StartRequestWithRetry( 483 return sender_->StartRequestWithRetry(
462 new ContinueGetFileListRequest( 484 new ContinueGetFileListRequest(
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 if (CanSendRequest()) { 843 if (CanSendRequest()) {
822 FOR_EACH_OBSERVER( 844 FOR_EACH_OBSERVER(
823 DriveServiceObserver, observers_, OnReadyToSendRequests()); 845 DriveServiceObserver, observers_, OnReadyToSendRequests());
824 } else if (!HasRefreshToken()) { 846 } else if (!HasRefreshToken()) {
825 FOR_EACH_OBSERVER( 847 FOR_EACH_OBSERVER(
826 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); 848 DriveServiceObserver, observers_, OnRefreshTokenInvalid());
827 } 849 }
828 } 850 }
829 851
830 } // namespace drive 852 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/google_apis/drive_api_requests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698