Chromium Code Reviews| Index: chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc |
| diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc |
| index e0685b2a491db9d7fd4ca3d20de1ba86b789074c..3a4f4b617843a8d9966635a295e798c14c350abd 100644 |
| --- a/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc |
| +++ b/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc |
| @@ -6,6 +6,7 @@ |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| +#include "chrome/browser/chromeos/drive/drive_readonly_token_fetcher.h" |
| #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
| #include "chrome/browser/chromeos/file_manager/file_tasks.h" |
| #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
| @@ -16,7 +17,10 @@ |
| #include "chrome/browser/drive/event_logger.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| -#include "chrome/common/extensions/api/file_browser_private.h" |
| +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| +#include "chrome/browser/signin/signin_manager_factory.h" |
| +#include "components/signin/core/browser/profile_oauth2_token_service.h" |
| +#include "components/signin/core/browser/signin_manager.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "webkit/common/fileapi/file_system_info.h" |
| #include "webkit/common/fileapi/file_system_util.h" |
| @@ -887,4 +891,70 @@ void FileBrowserPrivateRequestDriveShareFunction::OnAddPermission( |
| SendResponse(error == drive::FILE_ERROR_OK); |
| } |
| +bool FileBrowserPrivateGetDownloadUrlFunction::RunAsync() { |
| + using extensions::api::file_browser_private::GetShareUrl::Params; |
| + const scoped_ptr<Params> params(Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params); |
| + |
| + const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
| + render_view_host(), GetProfile(), GURL(params->url)); |
| + DCHECK(drive::util::IsUnderDriveMountPoint(path)); |
| + |
| + file_path_ = drive::util::ExtractDrivePath(path); |
| + |
| + drive::FileSystemInterface* const file_system = |
| + drive::util::GetFileSystemByProfile(GetProfile()); |
| + if (!file_system) { |
| + // |file_system| is NULL if Drive is disabled. |
| + return false; |
| + } |
| + |
| + file_system->GetDownloadUrl( |
| + file_path_, |
| + base::Bind(&FileBrowserPrivateGetDownloadUrlFunction::OnGetDownloadUrl, |
| + this)); |
| + return true; |
| +} |
| + |
| +void FileBrowserPrivateGetDownloadUrlFunction::OnGetDownloadUrl( |
| + drive::FileError error, |
| + const GURL& download_url) { |
| + if (error != drive::FILE_ERROR_OK) { |
| + SetError("Download Url for this item is not available."); |
| + SendResponse(false); |
| + return; |
| + } |
| + |
| + drive::DriveServiceInterface* const drive_service = |
|
kinaba
2014/07/09 06:02:47
Looks unused.
yoshiki
2014/07/11 13:48:50
Done.
|
| + drive::util::GetDriveServiceByProfile(GetProfile()); |
| + if (!drive_service) { |
| + // DriveService is not available. |
| + SetResult(new base::StringValue("")); |
| + SendResponse(true); |
| + } |
| + |
| + download_url_ = download_url.spec(); |
| + |
| + ProfileOAuth2TokenService* oauth2_token_service = |
| + ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); |
| + SigninManagerBase* signin_manager = |
| + SigninManagerFactory::GetForProfile(GetProfile()); |
| + const std::string& account_id = signin_manager->GetAuthenticatedAccountId(); |
| + |
| + new drive::DriveReadonlyTokenFetcher( |
| + account_id, |
| + oauth2_token_service, |
| + base::Bind(&FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched, |
| + this)); |
| +} |
| + |
| +void FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched( |
| + google_apis::GDataErrorCode code, |
| + const std::string& access_token) { |
|
kinaba
2014/07/09 06:02:47
Please check the error |code|.
yoshiki
2014/07/11 13:48:50
Done.
|
| + const std::string url = download_url_ + "&access_token=" + access_token; |
| + SetResult(new base::StringValue(url)); |
| + |
| + SendResponse(true); |
| +} |
| + |
| } // namespace extensions |