Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(774)

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc

Issue 371883003: Files.app: Add an private API to get a download URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed the comment Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/chromeos/drive/drive_integration_service.h" 8 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
9 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" 9 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
10 #include "chrome/browser/chromeos/file_manager/file_tasks.h" 10 #include "chrome/browser/chromeos/file_manager/file_tasks.h"
11 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" 11 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
12 #include "chrome/browser/chromeos/file_manager/url_util.h" 12 #include "chrome/browser/chromeos/file_manager/url_util.h"
13 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" 13 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
14 #include "chrome/browser/chromeos/profiles/profile_helper.h" 14 #include "chrome/browser/chromeos/profiles/profile_helper.h"
15 #include "chrome/browser/drive/drive_app_registry.h" 15 #include "chrome/browser/drive/drive_app_registry.h"
16 #include "chrome/browser/drive/event_logger.h" 16 #include "chrome/browser/drive/event_logger.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/common/extensions/api/file_browser_private.h" 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
20 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "components/signin/core/browser/profile_oauth2_token_service.h"
22 #include "components/signin/core/browser/signin_manager.h"
20 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 #include "google_apis/drive/auth_service.h"
21 #include "webkit/common/fileapi/file_system_info.h" 25 #include "webkit/common/fileapi/file_system_info.h"
22 #include "webkit/common/fileapi/file_system_util.h" 26 #include "webkit/common/fileapi/file_system_util.h"
23 27
24 using content::BrowserThread; 28 using content::BrowserThread;
25 29
26 using file_manager::util::EntryDefinition; 30 using file_manager::util::EntryDefinition;
27 using file_manager::util::EntryDefinitionCallback; 31 using file_manager::util::EntryDefinitionCallback;
28 using file_manager::util::EntryDefinitionList; 32 using file_manager::util::EntryDefinitionList;
29 using file_manager::util::EntryDefinitionListCallback; 33 using file_manager::util::EntryDefinitionListCallback;
30 using file_manager::util::FileDefinition; 34 using file_manager::util::FileDefinition;
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 base::Bind(&FileBrowserPrivateRequestDriveShareFunction::OnAddPermission, 884 base::Bind(&FileBrowserPrivateRequestDriveShareFunction::OnAddPermission,
881 this)); 885 this));
882 return true; 886 return true;
883 } 887 }
884 888
885 void FileBrowserPrivateRequestDriveShareFunction::OnAddPermission( 889 void FileBrowserPrivateRequestDriveShareFunction::OnAddPermission(
886 drive::FileError error) { 890 drive::FileError error) {
887 SendResponse(error == drive::FILE_ERROR_OK); 891 SendResponse(error == drive::FILE_ERROR_OK);
888 } 892 }
889 893
894 FileBrowserPrivateGetDownloadUrlFunction::
895 FileBrowserPrivateGetDownloadUrlFunction() {
896 }
897
898 FileBrowserPrivateGetDownloadUrlFunction::
899 ~FileBrowserPrivateGetDownloadUrlFunction() {
900 }
901
902 bool FileBrowserPrivateGetDownloadUrlFunction::RunAsync() {
903 using extensions::api::file_browser_private::GetShareUrl::Params;
904 const scoped_ptr<Params> params(Params::Create(*args_));
905 EXTENSION_FUNCTION_VALIDATE(params);
906
907 // Start getting the file info.
908 drive::FileSystemInterface* const file_system =
909 drive::util::GetFileSystemByProfile(GetProfile());
910 if (!file_system) {
911 // |file_system| is NULL if Drive is disabled or not mounted.
912 return false;
913 }
914
915 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
916 render_view_host(), GetProfile(), GURL(params->url));
917 DCHECK(drive::util::IsUnderDriveMountPoint(path));
918 base::FilePath file_path = drive::util::ExtractDrivePath(path);
919
920 file_system->GetResourceEntry(
921 file_path,
922 base::Bind(&FileBrowserPrivateGetDownloadUrlFunction::OnGetResourceEntry,
923 this));
924 return true;
925 }
926
927 void FileBrowserPrivateGetDownloadUrlFunction::OnGetResourceEntry(
928 drive::FileError error,
929 scoped_ptr<drive::ResourceEntry> entry) {
930 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
931
932 if (error != drive::FILE_ERROR_OK) {
933 SetError("Download Url for this item is not available.");
934 SendResponse(false);
935 return;
936 }
937
938 download_url_ =
939 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.
940
941 ProfileOAuth2TokenService* oauth2_token_service =
942 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile());
943 SigninManagerBase* signin_manager =
944 SigninManagerFactory::GetForProfile(GetProfile());
945 const std::string& account_id = signin_manager->GetAuthenticatedAccountId();
946 std::vector<std::string> scopes;
947 scopes.push_back("https://www.googleapis.com/auth/drive.readonly");
948
949 auth_service_.reset(
950 new google_apis::AuthService(oauth2_token_service,
951 account_id,
952 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.
953 scopes));
954 auth_service_->StartAuthentication(base::Bind(
955 &FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched, this));
956 }
957
958 void FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched(
959 google_apis::GDataErrorCode code,
960 const std::string& access_token) {
961 if (code != google_apis::HTTP_SUCCESS) {
962 SetError("Not able to fetch the token.");
963 SendResponse(false);
964 return;
965 }
966
967 const std::string url = download_url_ + "?access_token=" + access_token;
968 SetResult(new base::StringValue(url));
969
970 SendResponse(true);
971 }
972
890 } // namespace extensions 973 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698