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" |
11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/task_runner_util.h" | 13 #include "base/task_runner_util.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/drive/drive_api_util.h" | 15 #include "chrome/browser/drive/drive_api_util.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "google_apis/drive/auth_service.h" | 17 #include "google_apis/drive/auth_service.h" |
18 #include "google_apis/drive/drive_api_parser.h" | 18 #include "google_apis/drive/drive_api_parser.h" |
19 #include "google_apis/drive/drive_api_requests.h" | 19 #include "google_apis/drive/drive_api_requests.h" |
20 #include "google_apis/drive/gdata_errorcode.h" | 20 #include "google_apis/drive/gdata_errorcode.h" |
21 #include "google_apis/drive/gdata_wapi_parser.h" | 21 #include "google_apis/drive/gdata_wapi_parser.h" |
22 #include "google_apis/drive/gdata_wapi_requests.h" | 22 #include "google_apis/drive/gdata_wapi_requests.h" |
23 #include "google_apis/drive/request_sender.h" | 23 #include "google_apis/drive/request_sender.h" |
| 24 #include "google_apis/google_api_keys.h" |
24 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
25 | 26 |
26 using content::BrowserThread; | 27 using content::BrowserThread; |
27 using google_apis::AppList; | 28 using google_apis::AppList; |
28 using google_apis::AppListCallback; | 29 using google_apis::AppListCallback; |
29 using google_apis::AuthStatusCallback; | 30 using google_apis::AuthStatusCallback; |
30 using google_apis::AuthorizeAppCallback; | 31 using google_apis::AuthorizeAppCallback; |
31 using google_apis::CancelCallback; | 32 using google_apis::CancelCallback; |
32 using google_apis::ChangeList; | 33 using google_apis::ChangeList; |
33 using google_apis::DownloadActionCallback; | 34 using google_apis::DownloadActionCallback; |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 callback))); | 778 callback))); |
778 } | 779 } |
779 | 780 |
780 CancelCallback DriveAPIService::AuthorizeApp( | 781 CancelCallback DriveAPIService::AuthorizeApp( |
781 const std::string& resource_id, | 782 const std::string& resource_id, |
782 const std::string& app_id, | 783 const std::string& app_id, |
783 const AuthorizeAppCallback& callback) { | 784 const AuthorizeAppCallback& callback) { |
784 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 785 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
785 DCHECK(!callback.is_null()); | 786 DCHECK(!callback.is_null()); |
786 | 787 |
787 FilesGetRequest* request = new FilesGetRequest( | 788 // Files.Authorize is only available for whitelisted clients like official |
788 sender_.get(), url_generator_, | 789 // Google Chrome. In other cases, we fall back to Files.Get that returns the |
789 base::Bind(&ExtractOpenUrlAndRun, app_id, callback)); | 790 // same value as Files.Authorize without doing authorization. In that case, |
790 request->set_file_id(resource_id); | 791 // the app can open if it was authorized by other means (from whitelisted |
791 request->set_fields(kFileResourceOpenWithLinksFields); | 792 // clients or drive.google.com web UI.) |
792 return sender_->StartRequestWithRetry(request); | 793 if (google_apis::IsGoogleChromeAPIKeyUsed()) { |
| 794 google_apis::drive::FilesAuthorizeRequest* request = |
| 795 new google_apis::drive::FilesAuthorizeRequest( |
| 796 sender_.get(), url_generator_, |
| 797 base::Bind(&ExtractOpenUrlAndRun, app_id, callback)); |
| 798 request->set_app_id(app_id); |
| 799 request->set_file_id(resource_id); |
| 800 request->set_fields(kFileResourceOpenWithLinksFields); |
| 801 return sender_->StartRequestWithRetry(request); |
| 802 } else { |
| 803 FilesGetRequest* request = new FilesGetRequest( |
| 804 sender_.get(), url_generator_, |
| 805 base::Bind(&ExtractOpenUrlAndRun, app_id, callback)); |
| 806 request->set_file_id(resource_id); |
| 807 request->set_fields(kFileResourceOpenWithLinksFields); |
| 808 return sender_->StartRequestWithRetry(request); |
| 809 } |
793 } | 810 } |
794 | 811 |
795 CancelCallback DriveAPIService::UninstallApp( | 812 CancelCallback DriveAPIService::UninstallApp( |
796 const std::string& app_id, | 813 const std::string& app_id, |
797 const google_apis::EntryActionCallback& callback) { | 814 const google_apis::EntryActionCallback& callback) { |
798 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 815 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
799 DCHECK(!callback.is_null()); | 816 DCHECK(!callback.is_null()); |
800 | 817 |
801 google_apis::drive::AppsDeleteRequest* request = | 818 google_apis::drive::AppsDeleteRequest* request = |
802 new google_apis::drive::AppsDeleteRequest(sender_.get(), url_generator_, | 819 new google_apis::drive::AppsDeleteRequest(sender_.get(), url_generator_, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 if (CanSendRequest()) { | 895 if (CanSendRequest()) { |
879 FOR_EACH_OBSERVER( | 896 FOR_EACH_OBSERVER( |
880 DriveServiceObserver, observers_, OnReadyToSendRequests()); | 897 DriveServiceObserver, observers_, OnReadyToSendRequests()); |
881 } else if (!HasRefreshToken()) { | 898 } else if (!HasRefreshToken()) { |
882 FOR_EACH_OBSERVER( | 899 FOR_EACH_OBSERVER( |
883 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); | 900 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); |
884 } | 901 } |
885 } | 902 } |
886 | 903 |
887 } // namespace drive | 904 } // namespace drive |
OLD | NEW |