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

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: rebase 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 "base/command_line.h"
7 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/chromeos/drive/drive_integration_service.h" 9 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
9 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" 10 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
10 #include "chrome/browser/chromeos/file_manager/file_tasks.h" 11 #include "chrome/browser/chromeos/file_manager/file_tasks.h"
11 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" 12 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
12 #include "chrome/browser/chromeos/file_manager/url_util.h" 13 #include "chrome/browser/chromeos/file_manager/url_util.h"
13 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" 14 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
14 #include "chrome/browser/chromeos/profiles/profile_helper.h" 15 #include "chrome/browser/chromeos/profiles/profile_helper.h"
15 #include "chrome/browser/drive/drive_app_registry.h" 16 #include "chrome/browser/drive/drive_app_registry.h"
16 #include "chrome/browser/drive/event_logger.h" 17 #include "chrome/browser/drive/event_logger.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/common/extensions/api/file_browser_private.h" 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
21 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "chromeos/chromeos_switches.h"
23 #include "components/signin/core/browser/profile_oauth2_token_service.h"
24 #include "components/signin/core/browser/signin_manager.h"
20 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
26 #include "google_apis/drive/auth_service.h"
21 #include "webkit/common/fileapi/file_system_info.h" 27 #include "webkit/common/fileapi/file_system_info.h"
22 #include "webkit/common/fileapi/file_system_util.h" 28 #include "webkit/common/fileapi/file_system_util.h"
23 29
24 using content::BrowserThread; 30 using content::BrowserThread;
25 31
26 using file_manager::util::EntryDefinition; 32 using file_manager::util::EntryDefinition;
27 using file_manager::util::EntryDefinitionCallback; 33 using file_manager::util::EntryDefinitionCallback;
28 using file_manager::util::EntryDefinitionList; 34 using file_manager::util::EntryDefinitionList;
29 using file_manager::util::EntryDefinitionListCallback; 35 using file_manager::util::EntryDefinitionListCallback;
30 using file_manager::util::FileDefinition; 36 using file_manager::util::FileDefinition;
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 base::Bind(&FileBrowserPrivateRequestDriveShareFunction::OnAddPermission, 886 base::Bind(&FileBrowserPrivateRequestDriveShareFunction::OnAddPermission,
881 this)); 887 this));
882 return true; 888 return true;
883 } 889 }
884 890
885 void FileBrowserPrivateRequestDriveShareFunction::OnAddPermission( 891 void FileBrowserPrivateRequestDriveShareFunction::OnAddPermission(
886 drive::FileError error) { 892 drive::FileError error) {
887 SendResponse(error == drive::FILE_ERROR_OK); 893 SendResponse(error == drive::FILE_ERROR_OK);
888 } 894 }
889 895
896 FileBrowserPrivateGetDownloadUrlFunction::
897 FileBrowserPrivateGetDownloadUrlFunction() {
898 }
899
900 FileBrowserPrivateGetDownloadUrlFunction::
901 ~FileBrowserPrivateGetDownloadUrlFunction() {
902 }
903
904 bool FileBrowserPrivateGetDownloadUrlFunction::RunAsync() {
905 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
906 if (!command_line->HasSwitch(
907 chromeos::switches::kEnableVideoPlayerChromecastSupport)) {
908 SetError("Cast support is disabled.");
909 SetResult(new base::StringValue("")); // Intentionally returns a blank.
910 return false;
911 }
912
913 using extensions::api::file_browser_private::GetShareUrl::Params;
914 const scoped_ptr<Params> params(Params::Create(*args_));
915 EXTENSION_FUNCTION_VALIDATE(params);
916
917 // Start getting the file info.
918 drive::FileSystemInterface* const file_system =
919 drive::util::GetFileSystemByProfile(GetProfile());
920 if (!file_system) {
921 // |file_system| is NULL if Drive is disabled or not mounted.
922 SetError("Drive is disabled or not mounted.");
923 SetResult(new base::StringValue("")); // Intentionally returns a blank.
924 return false;
925 }
926
927 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
928 render_view_host(), GetProfile(), GURL(params->url));
929 DCHECK(drive::util::IsUnderDriveMountPoint(path));
930 base::FilePath file_path = drive::util::ExtractDrivePath(path);
931
932 file_system->GetResourceEntry(
933 file_path,
934 base::Bind(&FileBrowserPrivateGetDownloadUrlFunction::OnGetResourceEntry,
935 this));
936 return true;
937 }
938
939 void FileBrowserPrivateGetDownloadUrlFunction::OnGetResourceEntry(
940 drive::FileError error,
941 scoped_ptr<drive::ResourceEntry> entry) {
942 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
943
944 if (error != drive::FILE_ERROR_OK) {
945 SetError("Download Url for this item is not available.");
946 SetResult(new base::StringValue("")); // Intentionally returns a blank.
947 SendResponse(false);
948 return;
949 }
950
951 download_url_ =
952 google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction +
953 entry->resource_id();
954
955 ProfileOAuth2TokenService* oauth2_token_service =
956 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile());
957 SigninManagerBase* signin_manager =
958 SigninManagerFactory::GetForProfile(GetProfile());
959 const std::string& account_id = signin_manager->GetAuthenticatedAccountId();
960 std::vector<std::string> scopes;
961 scopes.push_back("https://www.googleapis.com/auth/drive.readonly");
962
963 auth_service_.reset(
964 new google_apis::AuthService(oauth2_token_service,
965 account_id,
966 GetProfile()->GetRequestContext(),
967 scopes));
968 auth_service_->StartAuthentication(base::Bind(
969 &FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched, this));
970 }
971
972 void FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched(
973 google_apis::GDataErrorCode code,
974 const std::string& access_token) {
975 if (code != google_apis::HTTP_SUCCESS) {
976 SetError("Not able to fetch the token.");
977 SetResult(new base::StringValue("")); // Intentionally returns a blank.
978 SendResponse(false);
979 return;
980 }
981
982 const std::string url = download_url_ + "?access_token=" + access_token;
983 SetResult(new base::StringValue(url));
984
985 SendResponse(true);
986 }
987
890 } // namespace extensions 988 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698