OLD | NEW |
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 <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 bool FileManagerPrivateRequestAccessTokenFunction::RunAsync() { | 934 bool FileManagerPrivateRequestAccessTokenFunction::RunAsync() { |
935 using extensions::api::file_manager_private::RequestAccessToken::Params; | 935 using extensions::api::file_manager_private::RequestAccessToken::Params; |
936 const std::unique_ptr<Params> params(Params::Create(*args_)); | 936 const std::unique_ptr<Params> params(Params::Create(*args_)); |
937 EXTENSION_FUNCTION_VALIDATE(params); | 937 EXTENSION_FUNCTION_VALIDATE(params); |
938 | 938 |
939 drive::DriveServiceInterface* const drive_service = | 939 drive::DriveServiceInterface* const drive_service = |
940 drive::util::GetDriveServiceByProfile(GetProfile()); | 940 drive::util::GetDriveServiceByProfile(GetProfile()); |
941 | 941 |
942 if (!drive_service) { | 942 if (!drive_service) { |
943 // DriveService is not available. | 943 // DriveService is not available. |
944 SetResult(base::MakeUnique<base::StringValue>(std::string())); | 944 SetResult(base::MakeUnique<base::Value>(std::string())); |
945 SendResponse(true); | 945 SendResponse(true); |
946 return true; | 946 return true; |
947 } | 947 } |
948 | 948 |
949 // If refreshing is requested, then clear the token to refetch it. | 949 // If refreshing is requested, then clear the token to refetch it. |
950 if (params->refresh) | 950 if (params->refresh) |
951 drive_service->ClearAccessToken(); | 951 drive_service->ClearAccessToken(); |
952 | 952 |
953 // Retrieve the cached auth token (if available), otherwise the AuthService | 953 // Retrieve the cached auth token (if available), otherwise the AuthService |
954 // instance will try to refetch it. | 954 // instance will try to refetch it. |
955 drive_service->RequestAccessToken( | 955 drive_service->RequestAccessToken( |
956 base::Bind(&FileManagerPrivateRequestAccessTokenFunction:: | 956 base::Bind(&FileManagerPrivateRequestAccessTokenFunction:: |
957 OnAccessTokenFetched, this)); | 957 OnAccessTokenFetched, this)); |
958 return true; | 958 return true; |
959 } | 959 } |
960 | 960 |
961 void FileManagerPrivateRequestAccessTokenFunction::OnAccessTokenFetched( | 961 void FileManagerPrivateRequestAccessTokenFunction::OnAccessTokenFetched( |
962 google_apis::DriveApiErrorCode code, | 962 google_apis::DriveApiErrorCode code, |
963 const std::string& access_token) { | 963 const std::string& access_token) { |
964 SetResult(base::MakeUnique<base::StringValue>(access_token)); | 964 SetResult(base::MakeUnique<base::Value>(access_token)); |
965 SendResponse(true); | 965 SendResponse(true); |
966 } | 966 } |
967 | 967 |
968 bool FileManagerPrivateInternalGetShareUrlFunction::RunAsync() { | 968 bool FileManagerPrivateInternalGetShareUrlFunction::RunAsync() { |
969 using extensions::api::file_manager_private_internal::GetShareUrl::Params; | 969 using extensions::api::file_manager_private_internal::GetShareUrl::Params; |
970 const std::unique_ptr<Params> params(Params::Create(*args_)); | 970 const std::unique_ptr<Params> params(Params::Create(*args_)); |
971 EXTENSION_FUNCTION_VALIDATE(params); | 971 EXTENSION_FUNCTION_VALIDATE(params); |
972 | 972 |
973 const base::FilePath path = file_manager::util::GetLocalPathFromURL( | 973 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
974 render_frame_host(), GetProfile(), GURL(params->url)); | 974 render_frame_host(), GetProfile(), GURL(params->url)); |
(...skipping 18 matching lines...) Expand all Loading... |
993 | 993 |
994 void FileManagerPrivateInternalGetShareUrlFunction::OnGetShareUrl( | 994 void FileManagerPrivateInternalGetShareUrlFunction::OnGetShareUrl( |
995 drive::FileError error, | 995 drive::FileError error, |
996 const GURL& share_url) { | 996 const GURL& share_url) { |
997 if (error != drive::FILE_ERROR_OK) { | 997 if (error != drive::FILE_ERROR_OK) { |
998 SetError("Share Url for this item is not available."); | 998 SetError("Share Url for this item is not available."); |
999 SendResponse(false); | 999 SendResponse(false); |
1000 return; | 1000 return; |
1001 } | 1001 } |
1002 | 1002 |
1003 SetResult(base::MakeUnique<base::StringValue>(share_url.spec())); | 1003 SetResult(base::MakeUnique<base::Value>(share_url.spec())); |
1004 SendResponse(true); | 1004 SendResponse(true); |
1005 } | 1005 } |
1006 | 1006 |
1007 bool FileManagerPrivateInternalRequestDriveShareFunction::RunAsync() { | 1007 bool FileManagerPrivateInternalRequestDriveShareFunction::RunAsync() { |
1008 using extensions::api::file_manager_private_internal::RequestDriveShare:: | 1008 using extensions::api::file_manager_private_internal::RequestDriveShare:: |
1009 Params; | 1009 Params; |
1010 const std::unique_ptr<Params> params(Params::Create(*args_)); | 1010 const std::unique_ptr<Params> params(Params::Create(*args_)); |
1011 EXTENSION_FUNCTION_VALIDATE(params); | 1011 EXTENSION_FUNCTION_VALIDATE(params); |
1012 | 1012 |
1013 const base::FilePath path = file_manager::util::GetLocalPathFromURL( | 1013 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 const std::unique_ptr<Params> params(Params::Create(*args_)); | 1071 const std::unique_ptr<Params> params(Params::Create(*args_)); |
1072 EXTENSION_FUNCTION_VALIDATE(params); | 1072 EXTENSION_FUNCTION_VALIDATE(params); |
1073 | 1073 |
1074 // Start getting the file info. | 1074 // Start getting the file info. |
1075 drive::FileSystemInterface* const file_system = | 1075 drive::FileSystemInterface* const file_system = |
1076 drive::util::GetFileSystemByProfile(GetProfile()); | 1076 drive::util::GetFileSystemByProfile(GetProfile()); |
1077 if (!file_system) { | 1077 if (!file_system) { |
1078 // |file_system| is NULL if Drive is disabled or not mounted. | 1078 // |file_system| is NULL if Drive is disabled or not mounted. |
1079 SetError("Drive is disabled or not mounted."); | 1079 SetError("Drive is disabled or not mounted."); |
1080 // Intentionally returns a blank. | 1080 // Intentionally returns a blank. |
1081 SetResult(base::MakeUnique<base::StringValue>(std::string())); | 1081 SetResult(base::MakeUnique<base::Value>(std::string())); |
1082 return false; | 1082 return false; |
1083 } | 1083 } |
1084 | 1084 |
1085 const base::FilePath path = file_manager::util::GetLocalPathFromURL( | 1085 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
1086 render_frame_host(), GetProfile(), GURL(params->url)); | 1086 render_frame_host(), GetProfile(), GURL(params->url)); |
1087 if (!drive::util::IsUnderDriveMountPoint(path)) { | 1087 if (!drive::util::IsUnderDriveMountPoint(path)) { |
1088 SetError("The given file is not in Drive."); | 1088 SetError("The given file is not in Drive."); |
1089 // Intentionally returns a blank. | 1089 // Intentionally returns a blank. |
1090 SetResult(base::MakeUnique<base::StringValue>(std::string())); | 1090 SetResult(base::MakeUnique<base::Value>(std::string())); |
1091 return false; | 1091 return false; |
1092 } | 1092 } |
1093 base::FilePath file_path = drive::util::ExtractDrivePath(path); | 1093 base::FilePath file_path = drive::util::ExtractDrivePath(path); |
1094 | 1094 |
1095 file_system->GetResourceEntry( | 1095 file_system->GetResourceEntry( |
1096 file_path, | 1096 file_path, |
1097 base::Bind( | 1097 base::Bind( |
1098 &FileManagerPrivateInternalGetDownloadUrlFunction::OnGetResourceEntry, | 1098 &FileManagerPrivateInternalGetDownloadUrlFunction::OnGetResourceEntry, |
1099 this)); | 1099 this)); |
1100 return true; | 1100 return true; |
1101 } | 1101 } |
1102 | 1102 |
1103 void FileManagerPrivateInternalGetDownloadUrlFunction::OnGetResourceEntry( | 1103 void FileManagerPrivateInternalGetDownloadUrlFunction::OnGetResourceEntry( |
1104 drive::FileError error, | 1104 drive::FileError error, |
1105 std::unique_ptr<drive::ResourceEntry> entry) { | 1105 std::unique_ptr<drive::ResourceEntry> entry) { |
1106 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1106 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1107 | 1107 |
1108 if (error != drive::FILE_ERROR_OK) { | 1108 if (error != drive::FILE_ERROR_OK) { |
1109 SetError("Download Url for this item is not available."); | 1109 SetError("Download Url for this item is not available."); |
1110 // Intentionally returns a blank. | 1110 // Intentionally returns a blank. |
1111 SetResult(base::MakeUnique<base::StringValue>(std::string())); | 1111 SetResult(base::MakeUnique<base::Value>(std::string())); |
1112 SendResponse(false); | 1112 SendResponse(false); |
1113 return; | 1113 return; |
1114 } | 1114 } |
1115 | 1115 |
1116 DriveApiUrlGenerator url_generator( | 1116 DriveApiUrlGenerator url_generator( |
1117 (GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction)), | 1117 (GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction)), |
1118 (GURL( | 1118 (GURL( |
1119 google_apis::DriveApiUrlGenerator::kBaseThumbnailUrlForProduction)), | 1119 google_apis::DriveApiUrlGenerator::kBaseThumbnailUrlForProduction)), |
1120 google_apis::GetTeamDrivesIntegrationSwitch()); | 1120 google_apis::GetTeamDrivesIntegrationSwitch()); |
1121 download_url_ = url_generator.GenerateDownloadFileUrl(entry->resource_id()); | 1121 download_url_ = url_generator.GenerateDownloadFileUrl(entry->resource_id()); |
(...skipping 14 matching lines...) Expand all Loading... |
1136 auth_service_->StartAuthentication(base::Bind( | 1136 auth_service_->StartAuthentication(base::Bind( |
1137 &FileManagerPrivateInternalGetDownloadUrlFunction::OnTokenFetched, this)); | 1137 &FileManagerPrivateInternalGetDownloadUrlFunction::OnTokenFetched, this)); |
1138 } | 1138 } |
1139 | 1139 |
1140 void FileManagerPrivateInternalGetDownloadUrlFunction::OnTokenFetched( | 1140 void FileManagerPrivateInternalGetDownloadUrlFunction::OnTokenFetched( |
1141 google_apis::DriveApiErrorCode code, | 1141 google_apis::DriveApiErrorCode code, |
1142 const std::string& access_token) { | 1142 const std::string& access_token) { |
1143 if (code != google_apis::HTTP_SUCCESS) { | 1143 if (code != google_apis::HTTP_SUCCESS) { |
1144 SetError("Not able to fetch the token."); | 1144 SetError("Not able to fetch the token."); |
1145 // Intentionally returns a blank. | 1145 // Intentionally returns a blank. |
1146 SetResult(base::MakeUnique<base::StringValue>(std::string())); | 1146 SetResult(base::MakeUnique<base::Value>(std::string())); |
1147 SendResponse(false); | 1147 SendResponse(false); |
1148 return; | 1148 return; |
1149 } | 1149 } |
1150 | 1150 |
1151 const std::string url = | 1151 const std::string url = |
1152 download_url_.Resolve("?alt=media&access_token=" + access_token).spec(); | 1152 download_url_.Resolve("?alt=media&access_token=" + access_token).spec(); |
1153 SetResult(base::MakeUnique<base::StringValue>(url)); | 1153 SetResult(base::MakeUnique<base::Value>(url)); |
1154 | 1154 |
1155 SendResponse(true); | 1155 SendResponse(true); |
1156 } | 1156 } |
1157 | 1157 |
1158 } // namespace extensions | 1158 } // namespace extensions |
OLD | NEW |