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..5d543250d82a2e17c06a72b97ebc0eb2a40cab01 100644 |
--- a/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc |
+++ b/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc |
@@ -16,8 +16,12 @@ |
#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 "google_apis/drive/auth_service.h" |
#include "webkit/common/fileapi/file_system_info.h" |
#include "webkit/common/fileapi/file_system_util.h" |
@@ -887,4 +891,83 @@ void FileBrowserPrivateRequestDriveShareFunction::OnAddPermission( |
SendResponse(error == drive::FILE_ERROR_OK); |
} |
+FileBrowserPrivateGetDownloadUrlFunction:: |
+ FileBrowserPrivateGetDownloadUrlFunction() { |
+} |
+ |
+FileBrowserPrivateGetDownloadUrlFunction:: |
+ ~FileBrowserPrivateGetDownloadUrlFunction() { |
+} |
+ |
+bool FileBrowserPrivateGetDownloadUrlFunction::RunAsync() { |
+ using extensions::api::file_browser_private::GetShareUrl::Params; |
+ const scoped_ptr<Params> params(Params::Create(*args_)); |
+ EXTENSION_FUNCTION_VALIDATE(params); |
+ |
+ // Start getting the file info. |
+ drive::FileSystemInterface* const file_system = |
+ drive::util::GetFileSystemByProfile(GetProfile()); |
+ if (!file_system) { |
+ // |file_system| is NULL if Drive is disabled or not mounted. |
+ return false; |
+ } |
+ |
+ const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
+ render_view_host(), GetProfile(), GURL(params->url)); |
+ DCHECK(drive::util::IsUnderDriveMountPoint(path)); |
+ base::FilePath file_path = drive::util::ExtractDrivePath(path); |
+ |
+ file_system->GetResourceEntry( |
+ file_path, |
+ base::Bind(&FileBrowserPrivateGetDownloadUrlFunction::OnGetResourceEntry, |
+ this)); |
+ return true; |
+} |
+ |
+void FileBrowserPrivateGetDownloadUrlFunction::OnGetResourceEntry( |
+ drive::FileError error, |
+ scoped_ptr<drive::ResourceEntry> entry) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ if (error != drive::FILE_ERROR_OK) { |
+ SetError("Download Url for this item is not available."); |
+ SendResponse(false); |
+ return; |
+ } |
+ |
+ download_url_ = |
+ std::string("https://www.googledrive.com/host/" + entry->resource_id()); |
kinaba
2014/07/14 04:22:22
std::string() is not necessary.
What about using
yoshiki
2014/07/15 15:17:20
Done.
|
+ |
+ ProfileOAuth2TokenService* oauth2_token_service = |
+ ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); |
+ SigninManagerBase* signin_manager = |
+ SigninManagerFactory::GetForProfile(GetProfile()); |
+ const std::string& account_id = signin_manager->GetAuthenticatedAccountId(); |
+ std::vector<std::string> scopes; |
+ scopes.push_back("https://www.googleapis.com/auth/drive.readonly"); |
+ |
+ auth_service_.reset( |
+ new google_apis::AuthService(oauth2_token_service, |
+ account_id, |
+ g_browser_process->system_request_context(), |
hashimoto
2014/07/14 04:46:35
How about getting a RequestContext from Profile in
yoshiki
2014/07/15 15:17:20
Thanks for information. Done.
|
+ scopes)); |
+ auth_service_->StartAuthentication(base::Bind( |
+ &FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched, this)); |
+} |
+ |
+void FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched( |
+ google_apis::GDataErrorCode code, |
+ const std::string& access_token) { |
+ if (code != google_apis::HTTP_SUCCESS) { |
+ SetError("Not able to fetch the token."); |
+ SendResponse(false); |
+ return; |
+ } |
+ |
+ const std::string url = download_url_ + "?access_token=" + access_token; |
+ SetResult(new base::StringValue(url)); |
+ |
+ SendResponse(true); |
+} |
+ |
} // namespace extensions |