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

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

Issue 22909041: Refactor GetAboutRequest and GetApplistRequest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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
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/gdata_wapi_service.h" 5 #include "chrome/browser/drive/gdata_wapi_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"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/drive/drive_api_util.h" 13 #include "chrome/browser/drive/drive_api_util.h"
14 #include "chrome/browser/google_apis/auth_service.h" 14 #include "chrome/browser/google_apis/auth_service.h"
15 #include "chrome/browser/google_apis/drive_api_parser.h" 15 #include "chrome/browser/google_apis/drive_api_parser.h"
16 #include "chrome/browser/google_apis/gdata_errorcode.h" 16 #include "chrome/browser/google_apis/gdata_errorcode.h"
17 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 17 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
18 #include "chrome/browser/google_apis/gdata_wapi_requests.h" 18 #include "chrome/browser/google_apis/gdata_wapi_requests.h"
19 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" 19 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
20 #include "chrome/browser/google_apis/request_sender.h" 20 #include "chrome/browser/google_apis/request_sender.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 using google_apis::AboutResource; 24 using google_apis::AboutResource;
25 using google_apis::AboutResourceCallback;
25 using google_apis::AccountMetadata; 26 using google_apis::AccountMetadata;
26 using google_apis::AddResourceToDirectoryRequest; 27 using google_apis::AddResourceToDirectoryRequest;
27 using google_apis::AppList; 28 using google_apis::AppList;
29 using google_apis::AppListCallback;
30 using google_apis::AuthService;
28 using google_apis::AuthStatusCallback; 31 using google_apis::AuthStatusCallback;
29 using google_apis::AuthorizeAppCallback; 32 using google_apis::AuthorizeAppCallback;
30 using google_apis::AuthorizeAppRequest; 33 using google_apis::AuthorizeAppRequest;
31 using google_apis::AuthService;
32 using google_apis::CancelCallback; 34 using google_apis::CancelCallback;
33 using google_apis::CopyHostedDocumentRequest; 35 using google_apis::CopyHostedDocumentRequest;
34 using google_apis::CreateDirectoryRequest; 36 using google_apis::CreateDirectoryRequest;
35 using google_apis::DeleteResourceRequest; 37 using google_apis::DeleteResourceRequest;
36 using google_apis::DownloadActionCallback; 38 using google_apis::DownloadActionCallback;
37 using google_apis::DownloadFileRequest; 39 using google_apis::DownloadFileRequest;
38 using google_apis::EntryActionCallback; 40 using google_apis::EntryActionCallback;
41 using google_apis::GDATA_PARSE_ERROR;
39 using google_apis::GDataErrorCode; 42 using google_apis::GDataErrorCode;
40 using google_apis::GDATA_PARSE_ERROR;
41 using google_apis::GetAboutResourceCallback;
42 using google_apis::GetAccountMetadataRequest; 43 using google_apis::GetAccountMetadataRequest;
43 using google_apis::GetAppListCallback;
44 using google_apis::GetContentCallback; 44 using google_apis::GetContentCallback;
45 using google_apis::GetResourceEntryCallback; 45 using google_apis::GetResourceEntryCallback;
46 using google_apis::GetResourceEntryRequest; 46 using google_apis::GetResourceEntryRequest;
47 using google_apis::GetResourceListCallback; 47 using google_apis::GetResourceListCallback;
48 using google_apis::GetResourceListRequest; 48 using google_apis::GetResourceListRequest;
49 using google_apis::GetShareUrlCallback; 49 using google_apis::GetShareUrlCallback;
50 using google_apis::GetUploadStatusRequest; 50 using google_apis::GetUploadStatusRequest;
51 using google_apis::HTTP_NOT_IMPLEMENTED; 51 using google_apis::HTTP_NOT_IMPLEMENTED;
52 using google_apis::InitiateUploadCallback; 52 using google_apis::InitiateUploadCallback;
53 using google_apis::InitiateUploadExistingFileRequest; 53 using google_apis::InitiateUploadExistingFileRequest;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 google_apis::ResourceEntry::ExtractAndParse(*value); 90 google_apis::ResourceEntry::ExtractAndParse(*value);
91 if (!entry) { 91 if (!entry) {
92 callback.Run(GDATA_PARSE_ERROR, scoped_ptr<ResourceEntry>()); 92 callback.Run(GDATA_PARSE_ERROR, scoped_ptr<ResourceEntry>());
93 return; 93 return;
94 } 94 }
95 95
96 callback.Run(error, entry.Pass()); 96 callback.Run(error, entry.Pass());
97 } 97 }
98 98
99 void ParseAboutResourceAndRun( 99 void ParseAboutResourceAndRun(
100 const GetAboutResourceCallback& callback, 100 const AboutResourceCallback& callback,
101 GDataErrorCode error, 101 GDataErrorCode error,
102 scoped_ptr<AccountMetadata> account_metadata) { 102 scoped_ptr<AccountMetadata> account_metadata) {
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
104 DCHECK(!callback.is_null()); 104 DCHECK(!callback.is_null());
105 105
106 scoped_ptr<AboutResource> about_resource; 106 scoped_ptr<AboutResource> about_resource;
107 if (account_metadata) { 107 if (account_metadata) {
108 about_resource = AboutResource::CreateFromAccountMetadata( 108 about_resource = AboutResource::CreateFromAccountMetadata(
109 *account_metadata, kWapiRootDirectoryResourceId); 109 *account_metadata, kWapiRootDirectoryResourceId);
110 } 110 }
111 111
112 callback.Run(error, about_resource.Pass()); 112 callback.Run(error, about_resource.Pass());
113 } 113 }
114 114
115 void ParseAppListAndRun( 115 void ParseAppListAndRun(
116 const GetAppListCallback& callback, 116 const AppListCallback& callback,
117 GDataErrorCode error, 117 GDataErrorCode error,
118 scoped_ptr<AccountMetadata> account_metadata) { 118 scoped_ptr<AccountMetadata> account_metadata) {
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
120 DCHECK(!callback.is_null()); 120 DCHECK(!callback.is_null());
121 121
122 scoped_ptr<AppList> app_list; 122 scoped_ptr<AppList> app_list;
123 if (account_metadata) { 123 if (account_metadata) {
124 app_list = AppList::CreateFromAccountMetadata(*account_metadata); 124 app_list = AppList::CreateFromAccountMetadata(*account_metadata);
125 } 125 }
126 126
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return sender_->StartRequestWithRetry( 319 return sender_->StartRequestWithRetry(
320 new GetResourceEntryRequest(sender_.get(), 320 new GetResourceEntryRequest(sender_.get(),
321 url_generator_, 321 url_generator_,
322 resource_id, 322 resource_id,
323 embed_origin, 323 embed_origin,
324 base::Bind(&util::ParseShareUrlAndRun, 324 base::Bind(&util::ParseShareUrlAndRun,
325 callback))); 325 callback)));
326 } 326 }
327 327
328 CancelCallback GDataWapiService::GetAboutResource( 328 CancelCallback GDataWapiService::GetAboutResource(
329 const GetAboutResourceCallback& callback) { 329 const AboutResourceCallback& callback) {
330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
331 DCHECK(!callback.is_null()); 331 DCHECK(!callback.is_null());
332 332
333 return sender_->StartRequestWithRetry( 333 return sender_->StartRequestWithRetry(
334 new GetAccountMetadataRequest( 334 new GetAccountMetadataRequest(
335 sender_.get(), 335 sender_.get(),
336 url_generator_, 336 url_generator_,
337 base::Bind(&ParseAboutResourceAndRun, callback), 337 base::Bind(&ParseAboutResourceAndRun, callback),
338 false)); // Exclude installed apps. 338 false)); // Exclude installed apps.
339 } 339 }
340 340
341 CancelCallback GDataWapiService::GetAppList( 341 CancelCallback GDataWapiService::GetAppList(const AppListCallback& callback) {
342 const GetAppListCallback& callback) {
343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
344 DCHECK(!callback.is_null()); 343 DCHECK(!callback.is_null());
345 344
346 return sender_->StartRequestWithRetry( 345 return sender_->StartRequestWithRetry(
347 new GetAccountMetadataRequest(sender_.get(), 346 new GetAccountMetadataRequest(sender_.get(),
348 url_generator_, 347 url_generator_,
349 base::Bind(&ParseAppListAndRun, callback), 348 base::Bind(&ParseAppListAndRun, callback),
350 true)); // Include installed apps. 349 true)); // Include installed apps.
351 } 350 }
352 351
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 if (CanSendRequest()) { 644 if (CanSendRequest()) {
646 FOR_EACH_OBSERVER( 645 FOR_EACH_OBSERVER(
647 DriveServiceObserver, observers_, OnReadyToSendRequests()); 646 DriveServiceObserver, observers_, OnReadyToSendRequests());
648 } else if (!HasRefreshToken()) { 647 } else if (!HasRefreshToken()) {
649 FOR_EACH_OBSERVER( 648 FOR_EACH_OBSERVER(
650 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); 649 DriveServiceObserver, observers_, OnRefreshTokenInvalid());
651 } 650 }
652 } 651 }
653 652
654 } // namespace drive 653 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/drive/gdata_wapi_service.h ('k') | chrome/browser/google_apis/drive_api_requests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698