| 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 "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 13 matching lines...) Expand all Loading... |
| 24 #include "google_apis/google_api_keys.h" | 24 #include "google_apis/google_api_keys.h" |
| 25 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
| 26 | 26 |
| 27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 using google_apis::AppList; | 28 using google_apis::AppList; |
| 29 using google_apis::AppListCallback; | 29 using google_apis::AppListCallback; |
| 30 using google_apis::AuthStatusCallback; | 30 using google_apis::AuthStatusCallback; |
| 31 using google_apis::AuthorizeAppCallback; | 31 using google_apis::AuthorizeAppCallback; |
| 32 using google_apis::CancelCallback; | 32 using google_apis::CancelCallback; |
| 33 using google_apis::ChangeList; | 33 using google_apis::ChangeList; |
| 34 using google_apis::ChangeListCallback; |
| 34 using google_apis::DownloadActionCallback; | 35 using google_apis::DownloadActionCallback; |
| 35 using google_apis::EntryActionCallback; | 36 using google_apis::EntryActionCallback; |
| 36 using google_apis::FileList; | 37 using google_apis::FileList; |
| 37 using google_apis::FileResource; | 38 using google_apis::FileResource; |
| 38 using google_apis::GDATA_OTHER_ERROR; | 39 using google_apis::GDATA_OTHER_ERROR; |
| 39 using google_apis::GDATA_PARSE_ERROR; | 40 using google_apis::GDATA_PARSE_ERROR; |
| 40 using google_apis::GDataErrorCode; | 41 using google_apis::GDataErrorCode; |
| 41 using google_apis::AboutResourceCallback; | 42 using google_apis::AboutResourceCallback; |
| 42 using google_apis::GetContentCallback; | 43 using google_apis::GetContentCallback; |
| 43 using google_apis::GetResourceEntryCallback; | 44 using google_apis::GetResourceEntryCallback; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 179 } |
| 179 | 180 |
| 180 // Convert the value on blocking pool. | 181 // Convert the value on blocking pool. |
| 181 base::PostTaskAndReplyWithResult( | 182 base::PostTaskAndReplyWithResult( |
| 182 blocking_task_runner.get(), | 183 blocking_task_runner.get(), |
| 183 FROM_HERE, | 184 FROM_HERE, |
| 184 base::Bind(&ConvertFileListToResourceList, base::Passed(&value)), | 185 base::Bind(&ConvertFileListToResourceList, base::Passed(&value)), |
| 185 base::Bind(&DidConvertToResourceListOnBlockingPool, callback)); | 186 base::Bind(&DidConvertToResourceListOnBlockingPool, callback)); |
| 186 } | 187 } |
| 187 | 188 |
| 188 // Thin adapter of ConvertChangeListToResourceList. | |
| 189 scoped_ptr<ResourceList> ConvertChangeListToResourceList( | |
| 190 scoped_ptr<ChangeList> change_list) { | |
| 191 return util::ConvertChangeListToResourceList(*change_list); | |
| 192 } | |
| 193 | |
| 194 // Converts the FileList value to ResourceList on blocking pool and runs | |
| 195 // |callback| on the UI thread. | |
| 196 void ConvertChangeListToResourceListOnBlockingPoolAndRun( | |
| 197 scoped_refptr<base::TaskRunner> blocking_task_runner, | |
| 198 const GetResourceListCallback& callback, | |
| 199 GDataErrorCode error, | |
| 200 scoped_ptr<ChangeList> value) { | |
| 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 202 DCHECK(!callback.is_null()); | |
| 203 | |
| 204 if (!value) { | |
| 205 callback.Run(error, scoped_ptr<ResourceList>()); | |
| 206 return; | |
| 207 } | |
| 208 | |
| 209 // Convert the value on blocking pool. | |
| 210 base::PostTaskAndReplyWithResult( | |
| 211 blocking_task_runner.get(), | |
| 212 FROM_HERE, | |
| 213 base::Bind(&ConvertChangeListToResourceList, base::Passed(&value)), | |
| 214 base::Bind(&DidConvertToResourceListOnBlockingPool, callback)); | |
| 215 } | |
| 216 | |
| 217 // Converts the FileResource value to ResourceEntry for upload range request, | 189 // Converts the FileResource value to ResourceEntry for upload range request, |
| 218 // and runs |callback| on the UI thread. | 190 // and runs |callback| on the UI thread. |
| 219 void ConvertFileResourceToResourceEntryForUploadRangeAndRun( | 191 void ConvertFileResourceToResourceEntryForUploadRangeAndRun( |
| 220 const UploadRangeCallback& callback, | 192 const UploadRangeCallback& callback, |
| 221 const UploadRangeResponse& response, | 193 const UploadRangeResponse& response, |
| 222 scoped_ptr<FileResource> value) { | 194 scoped_ptr<FileResource> value) { |
| 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 224 DCHECK(!callback.is_null()); | 196 DCHECK(!callback.is_null()); |
| 225 | 197 |
| 226 if (!value) { | 198 if (!value) { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 base::Bind(&ConvertFileListToResourceListOnBlockingPoolAndRun, | 400 base::Bind(&ConvertFileListToResourceListOnBlockingPoolAndRun, |
| 429 blocking_task_runner_, callback)); | 401 blocking_task_runner_, callback)); |
| 430 request->set_max_results(kMaxNumFilesResourcePerRequest); | 402 request->set_max_results(kMaxNumFilesResourcePerRequest); |
| 431 request->set_q(query); | 403 request->set_q(query); |
| 432 request->set_fields(kFileListFields); | 404 request->set_fields(kFileListFields); |
| 433 return sender_->StartRequestWithRetry(request); | 405 return sender_->StartRequestWithRetry(request); |
| 434 } | 406 } |
| 435 | 407 |
| 436 CancelCallback DriveAPIService::GetChangeList( | 408 CancelCallback DriveAPIService::GetChangeList( |
| 437 int64 start_changestamp, | 409 int64 start_changestamp, |
| 438 const GetResourceListCallback& callback) { | 410 const ChangeListCallback& callback) { |
| 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 440 DCHECK(!callback.is_null()); | 412 DCHECK(!callback.is_null()); |
| 441 | 413 |
| 442 ChangesListRequest* request = new ChangesListRequest( | 414 ChangesListRequest* request = new ChangesListRequest( |
| 443 sender_.get(), url_generator_, | 415 sender_.get(), url_generator_, callback); |
| 444 base::Bind(&ConvertChangeListToResourceListOnBlockingPoolAndRun, | |
| 445 blocking_task_runner_, callback)); | |
| 446 request->set_max_results(kMaxNumFilesResourcePerRequest); | 416 request->set_max_results(kMaxNumFilesResourcePerRequest); |
| 447 request->set_start_change_id(start_changestamp); | 417 request->set_start_change_id(start_changestamp); |
| 448 request->set_fields(kChangeListFields); | 418 request->set_fields(kChangeListFields); |
| 449 return sender_->StartRequestWithRetry(request); | 419 return sender_->StartRequestWithRetry(request); |
| 450 } | 420 } |
| 451 | 421 |
| 452 CancelCallback DriveAPIService::GetRemainingChangeList( | 422 CancelCallback DriveAPIService::GetRemainingChangeList( |
| 453 const GURL& next_link, | 423 const GURL& next_link, |
| 454 const GetResourceListCallback& callback) { | 424 const ChangeListCallback& callback) { |
| 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 456 DCHECK(!next_link.is_empty()); | 426 DCHECK(!next_link.is_empty()); |
| 457 DCHECK(!callback.is_null()); | 427 DCHECK(!callback.is_null()); |
| 458 | 428 |
| 459 ChangesListNextPageRequest* request = new ChangesListNextPageRequest( | 429 ChangesListNextPageRequest* request = new ChangesListNextPageRequest( |
| 460 sender_.get(), | 430 sender_.get(), callback); |
| 461 base::Bind(&ConvertChangeListToResourceListOnBlockingPoolAndRun, | |
| 462 blocking_task_runner_, callback)); | |
| 463 request->set_next_link(next_link); | 431 request->set_next_link(next_link); |
| 464 request->set_fields(kChangeListFields); | 432 request->set_fields(kChangeListFields); |
| 465 return sender_->StartRequestWithRetry(request); | 433 return sender_->StartRequestWithRetry(request); |
| 466 } | 434 } |
| 467 | 435 |
| 468 CancelCallback DriveAPIService::GetRemainingFileList( | 436 CancelCallback DriveAPIService::GetRemainingFileList( |
| 469 const GURL& next_link, | 437 const GURL& next_link, |
| 470 const GetResourceListCallback& callback) { | 438 const GetResourceListCallback& callback) { |
| 471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 472 DCHECK(!next_link.is_empty()); | 440 DCHECK(!next_link.is_empty()); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 if (CanSendRequest()) { | 858 if (CanSendRequest()) { |
| 891 FOR_EACH_OBSERVER( | 859 FOR_EACH_OBSERVER( |
| 892 DriveServiceObserver, observers_, OnReadyToSendRequests()); | 860 DriveServiceObserver, observers_, OnReadyToSendRequests()); |
| 893 } else if (!HasRefreshToken()) { | 861 } else if (!HasRefreshToken()) { |
| 894 FOR_EACH_OBSERVER( | 862 FOR_EACH_OBSERVER( |
| 895 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); | 863 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); |
| 896 } | 864 } |
| 897 } | 865 } |
| 898 | 866 |
| 899 } // namespace drive | 867 } // namespace drive |
| OLD | NEW |