| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/extensions/file_manager/private_api_drive.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_drive.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 scoped_ptr<drive::ResourceEntry> entry) { | 1027 scoped_ptr<drive::ResourceEntry> entry) { |
| 1028 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1028 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1029 | 1029 |
| 1030 if (error != drive::FILE_ERROR_OK) { | 1030 if (error != drive::FILE_ERROR_OK) { |
| 1031 SetError("Download Url for this item is not available."); | 1031 SetError("Download Url for this item is not available."); |
| 1032 SetResult(new base::StringValue("")); // Intentionally returns a blank. | 1032 SetResult(new base::StringValue("")); // Intentionally returns a blank. |
| 1033 SendResponse(false); | 1033 SendResponse(false); |
| 1034 return; | 1034 return; |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 download_url_ = | 1037 DriveApiUrlGenerator url_generator( |
| 1038 google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction + | 1038 (GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction)), |
| 1039 entry->resource_id(); | 1039 (GURL(google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction))); |
| 1040 download_url_ = url_generator.GenerateDownloadFileUrl(entry->resource_id()); |
| 1040 | 1041 |
| 1041 ProfileOAuth2TokenService* oauth2_token_service = | 1042 ProfileOAuth2TokenService* oauth2_token_service = |
| 1042 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); | 1043 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); |
| 1043 SigninManagerBase* signin_manager = | 1044 SigninManagerBase* signin_manager = |
| 1044 SigninManagerFactory::GetForProfile(GetProfile()); | 1045 SigninManagerFactory::GetForProfile(GetProfile()); |
| 1045 const std::string& account_id = signin_manager->GetAuthenticatedAccountId(); | 1046 const std::string& account_id = signin_manager->GetAuthenticatedAccountId(); |
| 1046 std::vector<std::string> scopes; | 1047 std::vector<std::string> scopes; |
| 1047 scopes.push_back("https://www.googleapis.com/auth/drive.readonly"); | 1048 scopes.push_back("https://www.googleapis.com/auth/drive.readonly"); |
| 1048 | 1049 |
| 1049 auth_service_.reset( | 1050 auth_service_.reset( |
| 1050 new google_apis::AuthService(oauth2_token_service, | 1051 new google_apis::AuthService(oauth2_token_service, |
| 1051 account_id, | 1052 account_id, |
| 1052 GetProfile()->GetRequestContext(), | 1053 GetProfile()->GetRequestContext(), |
| 1053 scopes)); | 1054 scopes)); |
| 1054 auth_service_->StartAuthentication(base::Bind( | 1055 auth_service_->StartAuthentication(base::Bind( |
| 1055 &FileManagerPrivateGetDownloadUrlFunction::OnTokenFetched, this)); | 1056 &FileManagerPrivateGetDownloadUrlFunction::OnTokenFetched, this)); |
| 1056 } | 1057 } |
| 1057 | 1058 |
| 1058 void FileManagerPrivateGetDownloadUrlFunction::OnTokenFetched( | 1059 void FileManagerPrivateGetDownloadUrlFunction::OnTokenFetched( |
| 1059 google_apis::DriveApiErrorCode code, | 1060 google_apis::DriveApiErrorCode code, |
| 1060 const std::string& access_token) { | 1061 const std::string& access_token) { |
| 1061 if (code != google_apis::HTTP_SUCCESS) { | 1062 if (code != google_apis::HTTP_SUCCESS) { |
| 1062 SetError("Not able to fetch the token."); | 1063 SetError("Not able to fetch the token."); |
| 1063 SetResult(new base::StringValue("")); // Intentionally returns a blank. | 1064 SetResult(new base::StringValue("")); // Intentionally returns a blank. |
| 1064 SendResponse(false); | 1065 SendResponse(false); |
| 1065 return; | 1066 return; |
| 1066 } | 1067 } |
| 1067 | 1068 |
| 1068 const std::string url = download_url_ + "?access_token=" + access_token; | 1069 const std::string url = |
| 1070 download_url_.Resolve("?access_token=" + access_token).spec(); |
| 1069 SetResult(new base::StringValue(url)); | 1071 SetResult(new base::StringValue(url)); |
| 1070 | 1072 |
| 1071 SendResponse(true); | 1073 SendResponse(true); |
| 1072 } | 1074 } |
| 1073 | 1075 |
| 1074 } // namespace extensions | 1076 } // namespace extensions |
| OLD | NEW |