| 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 <set> | 9 #include <set> |
| 9 #include <utility> | 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 15 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 15 #include "chrome/browser/chromeos/drive/file_system_util.h" | 16 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 16 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 17 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
| 17 #include "chrome/browser/chromeos/file_manager/file_tasks.h" | 18 #include "chrome/browser/chromeos/file_manager/file_tasks.h" |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 it != entry_definition_list->end(); | 763 it != entry_definition_list->end(); |
| 763 ++it) { | 764 ++it) { |
| 764 base::DictionaryValue* entry = new base::DictionaryValue(); | 765 base::DictionaryValue* entry = new base::DictionaryValue(); |
| 765 entry->SetString("fileSystemName", it->file_system_name); | 766 entry->SetString("fileSystemName", it->file_system_name); |
| 766 entry->SetString("fileSystemRoot", it->file_system_root_url); | 767 entry->SetString("fileSystemRoot", it->file_system_root_url); |
| 767 entry->SetString("fileFullPath", "/" + it->full_path.AsUTF8Unsafe()); | 768 entry->SetString("fileFullPath", "/" + it->full_path.AsUTF8Unsafe()); |
| 768 entry->SetBoolean("fileIsDirectory", it->is_directory); | 769 entry->SetBoolean("fileIsDirectory", it->is_directory); |
| 769 entries->Append(entry); | 770 entries->Append(entry); |
| 770 } | 771 } |
| 771 | 772 |
| 772 base::DictionaryValue* result = new base::DictionaryValue(); | 773 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 773 result->Set("entries", entries); | 774 result->Set("entries", entries); |
| 774 result->SetString("nextFeed", next_link.spec()); | 775 result->SetString("nextFeed", next_link.spec()); |
| 775 | 776 |
| 776 SetResult(result); | 777 SetResult(std::move(result)); |
| 777 SendResponse(true); | 778 SendResponse(true); |
| 778 } | 779 } |
| 779 | 780 |
| 780 bool FileManagerPrivateSearchDriveMetadataFunction::RunAsync() { | 781 bool FileManagerPrivateSearchDriveMetadataFunction::RunAsync() { |
| 781 using api::file_manager_private::SearchDriveMetadata::Params; | 782 using api::file_manager_private::SearchDriveMetadata::Params; |
| 782 const std::unique_ptr<Params> params(Params::Create(*args_)); | 783 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 783 EXTENSION_FUNCTION_VALIDATE(params); | 784 EXTENSION_FUNCTION_VALIDATE(params); |
| 784 | 785 |
| 785 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); | 786 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); |
| 786 if (logger) { | 787 if (logger) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 base::Bind( | 848 base::Bind( |
| 848 &FileManagerPrivateSearchDriveMetadataFunction::OnEntryDefinitionList, | 849 &FileManagerPrivateSearchDriveMetadataFunction::OnEntryDefinitionList, |
| 849 this, | 850 this, |
| 850 base::Passed(&results))); | 851 base::Passed(&results))); |
| 851 } | 852 } |
| 852 | 853 |
| 853 void FileManagerPrivateSearchDriveMetadataFunction::OnEntryDefinitionList( | 854 void FileManagerPrivateSearchDriveMetadataFunction::OnEntryDefinitionList( |
| 854 std::unique_ptr<drive::MetadataSearchResultVector> search_result_info_list, | 855 std::unique_ptr<drive::MetadataSearchResultVector> search_result_info_list, |
| 855 std::unique_ptr<EntryDefinitionList> entry_definition_list) { | 856 std::unique_ptr<EntryDefinitionList> entry_definition_list) { |
| 856 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size()); | 857 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size()); |
| 857 base::ListValue* results_list = new base::ListValue(); | 858 std::unique_ptr<base::ListValue> results_list(new base::ListValue()); |
| 858 | 859 |
| 859 // Convert Drive files to something File API stack can understand. See | 860 // Convert Drive files to something File API stack can understand. See |
| 860 // file_browser_handler_custom_bindings.cc and | 861 // file_browser_handler_custom_bindings.cc and |
| 861 // file_manager_private_custom_bindings.js for how this is magically | 862 // file_manager_private_custom_bindings.js for how this is magically |
| 862 // converted to a FileEntry. | 863 // converted to a FileEntry. |
| 863 for (size_t i = 0; i < entry_definition_list->size(); ++i) { | 864 for (size_t i = 0; i < entry_definition_list->size(); ++i) { |
| 864 base::DictionaryValue* result_dict = new base::DictionaryValue(); | 865 base::DictionaryValue* result_dict = new base::DictionaryValue(); |
| 865 | 866 |
| 866 // FileEntry fields. | 867 // FileEntry fields. |
| 867 base::DictionaryValue* entry = new base::DictionaryValue(); | 868 base::DictionaryValue* entry = new base::DictionaryValue(); |
| 868 entry->SetString( | 869 entry->SetString( |
| 869 "fileSystemName", entry_definition_list->at(i).file_system_name); | 870 "fileSystemName", entry_definition_list->at(i).file_system_name); |
| 870 entry->SetString( | 871 entry->SetString( |
| 871 "fileSystemRoot", entry_definition_list->at(i).file_system_root_url); | 872 "fileSystemRoot", entry_definition_list->at(i).file_system_root_url); |
| 872 entry->SetString( | 873 entry->SetString( |
| 873 "fileFullPath", | 874 "fileFullPath", |
| 874 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe()); | 875 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe()); |
| 875 entry->SetBoolean("fileIsDirectory", | 876 entry->SetBoolean("fileIsDirectory", |
| 876 entry_definition_list->at(i).is_directory); | 877 entry_definition_list->at(i).is_directory); |
| 877 | 878 |
| 878 result_dict->Set("entry", entry); | 879 result_dict->Set("entry", entry); |
| 879 result_dict->SetString( | 880 result_dict->SetString( |
| 880 "highlightedBaseName", | 881 "highlightedBaseName", |
| 881 search_result_info_list->at(i).highlighted_base_name); | 882 search_result_info_list->at(i).highlighted_base_name); |
| 882 results_list->Append(result_dict); | 883 results_list->Append(result_dict); |
| 883 } | 884 } |
| 884 | 885 |
| 885 SetResult(results_list); | 886 SetResult(std::move(results_list)); |
| 886 SendResponse(true); | 887 SendResponse(true); |
| 887 } | 888 } |
| 888 | 889 |
| 889 bool FileManagerPrivateGetDriveConnectionStateFunction::RunSync() { | 890 bool FileManagerPrivateGetDriveConnectionStateFunction::RunSync() { |
| 890 api::file_manager_private::DriveConnectionState result; | 891 api::file_manager_private::DriveConnectionState result; |
| 891 | 892 |
| 892 switch (drive::util::GetDriveConnectionStatus(GetProfile())) { | 893 switch (drive::util::GetDriveConnectionStatus(GetProfile())) { |
| 893 case drive::util::DRIVE_DISCONNECTED_NOSERVICE: | 894 case drive::util::DRIVE_DISCONNECTED_NOSERVICE: |
| 894 result.type = kDriveConnectionTypeOffline; | 895 result.type = kDriveConnectionTypeOffline; |
| 895 result.reason.reset(new std::string(kDriveConnectionReasonNoService)); | 896 result.reason.reset(new std::string(kDriveConnectionReasonNoService)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 926 bool FileManagerPrivateRequestAccessTokenFunction::RunAsync() { | 927 bool FileManagerPrivateRequestAccessTokenFunction::RunAsync() { |
| 927 using extensions::api::file_manager_private::RequestAccessToken::Params; | 928 using extensions::api::file_manager_private::RequestAccessToken::Params; |
| 928 const std::unique_ptr<Params> params(Params::Create(*args_)); | 929 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 929 EXTENSION_FUNCTION_VALIDATE(params); | 930 EXTENSION_FUNCTION_VALIDATE(params); |
| 930 | 931 |
| 931 drive::DriveServiceInterface* const drive_service = | 932 drive::DriveServiceInterface* const drive_service = |
| 932 drive::util::GetDriveServiceByProfile(GetProfile()); | 933 drive::util::GetDriveServiceByProfile(GetProfile()); |
| 933 | 934 |
| 934 if (!drive_service) { | 935 if (!drive_service) { |
| 935 // DriveService is not available. | 936 // DriveService is not available. |
| 936 SetResult(new base::StringValue("")); | 937 SetResult(base::MakeUnique<base::StringValue>(std::string())); |
| 937 SendResponse(true); | 938 SendResponse(true); |
| 938 return true; | 939 return true; |
| 939 } | 940 } |
| 940 | 941 |
| 941 // If refreshing is requested, then clear the token to refetch it. | 942 // If refreshing is requested, then clear the token to refetch it. |
| 942 if (params->refresh) | 943 if (params->refresh) |
| 943 drive_service->ClearAccessToken(); | 944 drive_service->ClearAccessToken(); |
| 944 | 945 |
| 945 // Retrieve the cached auth token (if available), otherwise the AuthService | 946 // Retrieve the cached auth token (if available), otherwise the AuthService |
| 946 // instance will try to refetch it. | 947 // instance will try to refetch it. |
| 947 drive_service->RequestAccessToken( | 948 drive_service->RequestAccessToken( |
| 948 base::Bind(&FileManagerPrivateRequestAccessTokenFunction:: | 949 base::Bind(&FileManagerPrivateRequestAccessTokenFunction:: |
| 949 OnAccessTokenFetched, this)); | 950 OnAccessTokenFetched, this)); |
| 950 return true; | 951 return true; |
| 951 } | 952 } |
| 952 | 953 |
| 953 void FileManagerPrivateRequestAccessTokenFunction::OnAccessTokenFetched( | 954 void FileManagerPrivateRequestAccessTokenFunction::OnAccessTokenFetched( |
| 954 google_apis::DriveApiErrorCode code, | 955 google_apis::DriveApiErrorCode code, |
| 955 const std::string& access_token) { | 956 const std::string& access_token) { |
| 956 SetResult(new base::StringValue(access_token)); | 957 SetResult(base::MakeUnique<base::StringValue>(access_token)); |
| 957 SendResponse(true); | 958 SendResponse(true); |
| 958 } | 959 } |
| 959 | 960 |
| 960 bool FileManagerPrivateInternalGetShareUrlFunction::RunAsync() { | 961 bool FileManagerPrivateInternalGetShareUrlFunction::RunAsync() { |
| 961 using extensions::api::file_manager_private_internal::GetShareUrl::Params; | 962 using extensions::api::file_manager_private_internal::GetShareUrl::Params; |
| 962 const std::unique_ptr<Params> params(Params::Create(*args_)); | 963 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 963 EXTENSION_FUNCTION_VALIDATE(params); | 964 EXTENSION_FUNCTION_VALIDATE(params); |
| 964 | 965 |
| 965 const base::FilePath path = file_manager::util::GetLocalPathFromURL( | 966 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
| 966 render_frame_host(), GetProfile(), GURL(params->url)); | 967 render_frame_host(), GetProfile(), GURL(params->url)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 985 | 986 |
| 986 void FileManagerPrivateInternalGetShareUrlFunction::OnGetShareUrl( | 987 void FileManagerPrivateInternalGetShareUrlFunction::OnGetShareUrl( |
| 987 drive::FileError error, | 988 drive::FileError error, |
| 988 const GURL& share_url) { | 989 const GURL& share_url) { |
| 989 if (error != drive::FILE_ERROR_OK) { | 990 if (error != drive::FILE_ERROR_OK) { |
| 990 SetError("Share Url for this item is not available."); | 991 SetError("Share Url for this item is not available."); |
| 991 SendResponse(false); | 992 SendResponse(false); |
| 992 return; | 993 return; |
| 993 } | 994 } |
| 994 | 995 |
| 995 SetResult(new base::StringValue(share_url.spec())); | 996 SetResult(base::MakeUnique<base::StringValue>(share_url.spec())); |
| 996 SendResponse(true); | 997 SendResponse(true); |
| 997 } | 998 } |
| 998 | 999 |
| 999 bool FileManagerPrivateInternalRequestDriveShareFunction::RunAsync() { | 1000 bool FileManagerPrivateInternalRequestDriveShareFunction::RunAsync() { |
| 1000 using extensions::api::file_manager_private_internal::RequestDriveShare:: | 1001 using extensions::api::file_manager_private_internal::RequestDriveShare:: |
| 1001 Params; | 1002 Params; |
| 1002 const std::unique_ptr<Params> params(Params::Create(*args_)); | 1003 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 1003 EXTENSION_FUNCTION_VALIDATE(params); | 1004 EXTENSION_FUNCTION_VALIDATE(params); |
| 1004 | 1005 |
| 1005 const base::FilePath path = file_manager::util::GetLocalPathFromURL( | 1006 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 using extensions::api::file_manager_private_internal::GetShareUrl::Params; | 1062 using extensions::api::file_manager_private_internal::GetShareUrl::Params; |
| 1062 const std::unique_ptr<Params> params(Params::Create(*args_)); | 1063 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 1063 EXTENSION_FUNCTION_VALIDATE(params); | 1064 EXTENSION_FUNCTION_VALIDATE(params); |
| 1064 | 1065 |
| 1065 // Start getting the file info. | 1066 // Start getting the file info. |
| 1066 drive::FileSystemInterface* const file_system = | 1067 drive::FileSystemInterface* const file_system = |
| 1067 drive::util::GetFileSystemByProfile(GetProfile()); | 1068 drive::util::GetFileSystemByProfile(GetProfile()); |
| 1068 if (!file_system) { | 1069 if (!file_system) { |
| 1069 // |file_system| is NULL if Drive is disabled or not mounted. | 1070 // |file_system| is NULL if Drive is disabled or not mounted. |
| 1070 SetError("Drive is disabled or not mounted."); | 1071 SetError("Drive is disabled or not mounted."); |
| 1071 SetResult(new base::StringValue("")); // Intentionally returns a blank. | 1072 // Intentionally returns a blank. |
| 1073 SetResult(base::MakeUnique<base::StringValue>(std::string())); |
| 1072 return false; | 1074 return false; |
| 1073 } | 1075 } |
| 1074 | 1076 |
| 1075 const base::FilePath path = file_manager::util::GetLocalPathFromURL( | 1077 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
| 1076 render_frame_host(), GetProfile(), GURL(params->url)); | 1078 render_frame_host(), GetProfile(), GURL(params->url)); |
| 1077 if (!drive::util::IsUnderDriveMountPoint(path)) { | 1079 if (!drive::util::IsUnderDriveMountPoint(path)) { |
| 1078 SetError("The given file is not in Drive."); | 1080 SetError("The given file is not in Drive."); |
| 1079 SetResult(new base::StringValue("")); // Intentionally returns a blank. | 1081 // Intentionally returns a blank. |
| 1082 SetResult(base::MakeUnique<base::StringValue>(std::string())); |
| 1080 return false; | 1083 return false; |
| 1081 } | 1084 } |
| 1082 base::FilePath file_path = drive::util::ExtractDrivePath(path); | 1085 base::FilePath file_path = drive::util::ExtractDrivePath(path); |
| 1083 | 1086 |
| 1084 file_system->GetResourceEntry( | 1087 file_system->GetResourceEntry( |
| 1085 file_path, | 1088 file_path, |
| 1086 base::Bind( | 1089 base::Bind( |
| 1087 &FileManagerPrivateInternalGetDownloadUrlFunction::OnGetResourceEntry, | 1090 &FileManagerPrivateInternalGetDownloadUrlFunction::OnGetResourceEntry, |
| 1088 this)); | 1091 this)); |
| 1089 return true; | 1092 return true; |
| 1090 } | 1093 } |
| 1091 | 1094 |
| 1092 void FileManagerPrivateInternalGetDownloadUrlFunction::OnGetResourceEntry( | 1095 void FileManagerPrivateInternalGetDownloadUrlFunction::OnGetResourceEntry( |
| 1093 drive::FileError error, | 1096 drive::FileError error, |
| 1094 std::unique_ptr<drive::ResourceEntry> entry) { | 1097 std::unique_ptr<drive::ResourceEntry> entry) { |
| 1095 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1098 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1096 | 1099 |
| 1097 if (error != drive::FILE_ERROR_OK) { | 1100 if (error != drive::FILE_ERROR_OK) { |
| 1098 SetError("Download Url for this item is not available."); | 1101 SetError("Download Url for this item is not available."); |
| 1099 SetResult(new base::StringValue("")); // Intentionally returns a blank. | 1102 // Intentionally returns a blank. |
| 1103 SetResult(base::MakeUnique<base::StringValue>(std::string())); |
| 1100 SendResponse(false); | 1104 SendResponse(false); |
| 1101 return; | 1105 return; |
| 1102 } | 1106 } |
| 1103 | 1107 |
| 1104 DriveApiUrlGenerator url_generator( | 1108 DriveApiUrlGenerator url_generator( |
| 1105 (GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction)), | 1109 (GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction)), |
| 1106 (GURL( | 1110 (GURL( |
| 1107 google_apis::DriveApiUrlGenerator::kBaseThumbnailUrlForProduction))); | 1111 google_apis::DriveApiUrlGenerator::kBaseThumbnailUrlForProduction))); |
| 1108 download_url_ = url_generator.GenerateDownloadFileUrl(entry->resource_id()); | 1112 download_url_ = url_generator.GenerateDownloadFileUrl(entry->resource_id()); |
| 1109 | 1113 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1122 scopes)); | 1126 scopes)); |
| 1123 auth_service_->StartAuthentication(base::Bind( | 1127 auth_service_->StartAuthentication(base::Bind( |
| 1124 &FileManagerPrivateInternalGetDownloadUrlFunction::OnTokenFetched, this)); | 1128 &FileManagerPrivateInternalGetDownloadUrlFunction::OnTokenFetched, this)); |
| 1125 } | 1129 } |
| 1126 | 1130 |
| 1127 void FileManagerPrivateInternalGetDownloadUrlFunction::OnTokenFetched( | 1131 void FileManagerPrivateInternalGetDownloadUrlFunction::OnTokenFetched( |
| 1128 google_apis::DriveApiErrorCode code, | 1132 google_apis::DriveApiErrorCode code, |
| 1129 const std::string& access_token) { | 1133 const std::string& access_token) { |
| 1130 if (code != google_apis::HTTP_SUCCESS) { | 1134 if (code != google_apis::HTTP_SUCCESS) { |
| 1131 SetError("Not able to fetch the token."); | 1135 SetError("Not able to fetch the token."); |
| 1132 SetResult(new base::StringValue("")); // Intentionally returns a blank. | 1136 // Intentionally returns a blank. |
| 1137 SetResult(base::MakeUnique<base::StringValue>(std::string())); |
| 1133 SendResponse(false); | 1138 SendResponse(false); |
| 1134 return; | 1139 return; |
| 1135 } | 1140 } |
| 1136 | 1141 |
| 1137 const std::string url = | 1142 const std::string url = |
| 1138 download_url_.Resolve("?alt=media&access_token=" + access_token).spec(); | 1143 download_url_.Resolve("?alt=media&access_token=" + access_token).spec(); |
| 1139 SetResult(new base::StringValue(url)); | 1144 SetResult(base::MakeUnique<base::StringValue>(url)); |
| 1140 | 1145 |
| 1141 SendResponse(true); | 1146 SendResponse(true); |
| 1142 } | 1147 } |
| 1143 | 1148 |
| 1144 } // namespace extensions | 1149 } // namespace extensions |
| OLD | NEW |