| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 using google_apis::UploadRangeResponse; | 58 using google_apis::UploadRangeResponse; |
| 59 using google_apis::drive::ContinueGetFileListRequest; | 59 using google_apis::drive::ContinueGetFileListRequest; |
| 60 using google_apis::drive::CopyResourceRequest; | 60 using google_apis::drive::CopyResourceRequest; |
| 61 using google_apis::drive::CreateDirectoryRequest; | 61 using google_apis::drive::CreateDirectoryRequest; |
| 62 using google_apis::drive::DeleteResourceRequest; | 62 using google_apis::drive::DeleteResourceRequest; |
| 63 using google_apis::drive::DownloadFileRequest; | 63 using google_apis::drive::DownloadFileRequest; |
| 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; |
| 67 using google_apis::drive::InsertResourceRequest; | 67 using google_apis::drive::InsertResourceRequest; |
| 68 using google_apis::drive::RenameResourceRequest; | 68 using google_apis::drive::MoveResourceRequest; |
| 69 using google_apis::drive::ResumeUploadRequest; | 69 using google_apis::drive::ResumeUploadRequest; |
| 70 using google_apis::drive::TouchResourceRequest; | 70 using google_apis::drive::TouchResourceRequest; |
| 71 using google_apis::drive::TrashResourceRequest; | 71 using google_apis::drive::TrashResourceRequest; |
| 72 | 72 |
| 73 namespace drive { | 73 namespace drive { |
| 74 | 74 |
| 75 namespace { | 75 namespace { |
| 76 | 76 |
| 77 // OAuth2 scopes for Drive API. | 77 // OAuth2 scopes for Drive API. |
| 78 const char kDriveScope[] = "https://www.googleapis.com/auth/drive"; | 78 const char kDriveScope[] = "https://www.googleapis.com/auth/drive"; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 if (open_with_links[i].app_id == app_id) { | 252 if (open_with_links[i].app_id == app_id) { |
| 253 callback.Run(HTTP_SUCCESS, open_with_links[i].open_url); | 253 callback.Run(HTTP_SUCCESS, open_with_links[i].open_url); |
| 254 return; | 254 return; |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 | 257 |
| 258 // Not found. | 258 // Not found. |
| 259 callback.Run(GDATA_OTHER_ERROR, GURL()); | 259 callback.Run(GDATA_OTHER_ERROR, GURL()); |
| 260 } | 260 } |
| 261 | 261 |
| 262 // Ignores the |entry|, and runs the |callback|. |
| 263 void EntryActionCallbackAdapter( |
| 264 const EntryActionCallback& callback, |
| 265 GDataErrorCode error, scoped_ptr<FileResource> entry) { |
| 266 callback.Run(error); |
| 267 } |
| 268 |
| 262 // The resource ID for the root directory for Drive API is defined in the spec: | 269 // The resource ID for the root directory for Drive API is defined in the spec: |
| 263 // https://developers.google.com/drive/folder | 270 // https://developers.google.com/drive/folder |
| 264 const char kDriveApiRootDirectoryResourceId[] = "root"; | 271 const char kDriveApiRootDirectoryResourceId[] = "root"; |
| 265 | 272 |
| 266 } // namespace | 273 } // namespace |
| 267 | 274 |
| 268 DriveAPIService::DriveAPIService( | 275 DriveAPIService::DriveAPIService( |
| 269 OAuth2TokenService* oauth2_token_service, | 276 OAuth2TokenService* oauth2_token_service, |
| 270 net::URLRequestContextGetter* url_request_context_getter, | 277 net::URLRequestContextGetter* url_request_context_getter, |
| 271 base::TaskRunner* blocking_task_runner, | 278 base::TaskRunner* blocking_task_runner, |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 } | 608 } |
| 602 | 609 |
| 603 CancelCallback DriveAPIService::MoveResource( | 610 CancelCallback DriveAPIService::MoveResource( |
| 604 const std::string& resource_id, | 611 const std::string& resource_id, |
| 605 const std::string& parent_resource_id, | 612 const std::string& parent_resource_id, |
| 606 const std::string& new_title, | 613 const std::string& new_title, |
| 607 const GetResourceEntryCallback& callback) { | 614 const GetResourceEntryCallback& callback) { |
| 608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 615 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 609 DCHECK(!callback.is_null()); | 616 DCHECK(!callback.is_null()); |
| 610 | 617 |
| 611 // TODO(hidehiko): Implement this. | 618 return sender_->StartRequestWithRetry( |
| 612 NOTIMPLEMENTED(); | 619 new MoveResourceRequest( |
| 613 return CancelCallback(); | 620 sender_.get(), |
| 621 url_generator_, |
| 622 resource_id, |
| 623 parent_resource_id, |
| 624 new_title, |
| 625 base::Bind(&ParseResourceEntryAndRun, callback))); |
| 614 } | 626 } |
| 615 | 627 |
| 616 CancelCallback DriveAPIService::RenameResource( | 628 CancelCallback DriveAPIService::RenameResource( |
| 617 const std::string& resource_id, | 629 const std::string& resource_id, |
| 618 const std::string& new_title, | 630 const std::string& new_title, |
| 619 const EntryActionCallback& callback) { | 631 const EntryActionCallback& callback) { |
| 620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 621 DCHECK(!callback.is_null()); | 633 DCHECK(!callback.is_null()); |
| 622 | 634 |
| 623 return sender_->StartRequestWithRetry( | 635 return sender_->StartRequestWithRetry( |
| 624 new RenameResourceRequest( | 636 new MoveResourceRequest( |
| 625 sender_.get(), | 637 sender_.get(), |
| 626 url_generator_, | 638 url_generator_, |
| 627 resource_id, | 639 resource_id, |
| 640 std::string(), |
| 628 new_title, | 641 new_title, |
| 629 callback)); | 642 base::Bind(&EntryActionCallbackAdapter, callback))); |
| 630 } | 643 } |
| 631 | 644 |
| 632 CancelCallback DriveAPIService::TouchResource( | 645 CancelCallback DriveAPIService::TouchResource( |
| 633 const std::string& resource_id, | 646 const std::string& resource_id, |
| 634 const base::Time& modified_date, | 647 const base::Time& modified_date, |
| 635 const base::Time& last_viewed_by_me_date, | 648 const base::Time& last_viewed_by_me_date, |
| 636 const GetResourceEntryCallback& callback) { | 649 const GetResourceEntryCallback& callback) { |
| 637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 638 DCHECK(!modified_date.is_null()); | 651 DCHECK(!modified_date.is_null()); |
| 639 DCHECK(!last_viewed_by_me_date.is_null()); | 652 DCHECK(!last_viewed_by_me_date.is_null()); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 if (CanSendRequest()) { | 826 if (CanSendRequest()) { |
| 814 FOR_EACH_OBSERVER( | 827 FOR_EACH_OBSERVER( |
| 815 DriveServiceObserver, observers_, OnReadyToSendRequests()); | 828 DriveServiceObserver, observers_, OnReadyToSendRequests()); |
| 816 } else if (!HasRefreshToken()) { | 829 } else if (!HasRefreshToken()) { |
| 817 FOR_EACH_OBSERVER( | 830 FOR_EACH_OBSERVER( |
| 818 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); | 831 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); |
| 819 } | 832 } |
| 820 } | 833 } |
| 821 | 834 |
| 822 } // namespace drive | 835 } // namespace drive |
| OLD | NEW |