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

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: 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/drive/drive_readonly_token_fetcher.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 "components/signin/core/browser/profile_oauth2_token_service.h"
23 #include "components/signin/core/browser/signin_manager.h"
20 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.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;
(...skipping 850 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 bool FileBrowserPrivateGetDownloadUrlFunction::RunAsync() {
895 using extensions::api::file_browser_private::GetShareUrl::Params;
896 const scoped_ptr<Params> params(Params::Create(*args_));
897 EXTENSION_FUNCTION_VALIDATE(params);
898
899 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
900 render_view_host(), GetProfile(), GURL(params->url));
901 DCHECK(drive::util::IsUnderDriveMountPoint(path));
902
903 file_path_ = drive::util::ExtractDrivePath(path);
904
905 drive::FileSystemInterface* const file_system =
906 drive::util::GetFileSystemByProfile(GetProfile());
907 if (!file_system) {
908 // |file_system| is NULL if Drive is disabled.
909 return false;
910 }
911
912 file_system->GetDownloadUrl(
913 file_path_,
914 base::Bind(&FileBrowserPrivateGetDownloadUrlFunction::OnGetDownloadUrl,
915 this));
916 return true;
917 }
918
919 void FileBrowserPrivateGetDownloadUrlFunction::OnGetDownloadUrl(
920 drive::FileError error,
921 const GURL& download_url) {
922 if (error != drive::FILE_ERROR_OK) {
923 SetError("Download Url for this item is not available.");
924 SendResponse(false);
925 return;
926 }
927
928 drive::DriveServiceInterface* const drive_service =
kinaba 2014/07/09 06:02:47 Looks unused.
yoshiki 2014/07/11 13:48:50 Done.
929 drive::util::GetDriveServiceByProfile(GetProfile());
930 if (!drive_service) {
931 // DriveService is not available.
932 SetResult(new base::StringValue(""));
933 SendResponse(true);
934 }
935
936 download_url_ = download_url.spec();
937
938 ProfileOAuth2TokenService* oauth2_token_service =
939 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile());
940 SigninManagerBase* signin_manager =
941 SigninManagerFactory::GetForProfile(GetProfile());
942 const std::string& account_id = signin_manager->GetAuthenticatedAccountId();
943
944 new drive::DriveReadonlyTokenFetcher(
945 account_id,
946 oauth2_token_service,
947 base::Bind(&FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched,
948 this));
949 }
950
951 void FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched(
952 google_apis::GDataErrorCode code,
953 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.
954 const std::string url = download_url_ + "&access_token=" + access_token;
955 SetResult(new base::StringValue(url));
956
957 SendResponse(true);
958 }
959
890 } // namespace extensions 960 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698