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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api.cc

Issue 1829783002: [Extensions] Convert APIs to use movable types [5] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/api/file_system/file_system_api.h" 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 content::WebContents* GetWebContentsForAppId(Profile* profile, 249 content::WebContents* GetWebContentsForAppId(Profile* profile,
250 const std::string& app_id) { 250 const std::string& app_id) {
251 AppWindowRegistry* const registry = AppWindowRegistry::Get(profile); 251 AppWindowRegistry* const registry = AppWindowRegistry::Get(profile);
252 DCHECK(registry); 252 DCHECK(registry);
253 AppWindow* const app_window = registry->GetCurrentAppWindowForApp(app_id); 253 AppWindow* const app_window = registry->GetCurrentAppWindowForApp(app_id);
254 return app_window ? app_window->web_contents() : nullptr; 254 return app_window ? app_window->web_contents() : nullptr;
255 } 255 }
256 256
257 // Fills a list of volumes mounted in the system. 257 // Fills a list of volumes mounted in the system.
258 void FillVolumeList(Profile* profile, 258 void FillVolumeList(Profile* profile,
259 std::vector<linked_ptr<api::file_system::Volume>>* result) { 259 std::vector<api::file_system::Volume>* result) {
260 using file_manager::VolumeManager; 260 file_manager::VolumeManager* const volume_manager =
261 VolumeManager* const volume_manager = VolumeManager::Get(profile); 261 file_manager::VolumeManager::Get(profile);
262 DCHECK(volume_manager); 262 DCHECK(volume_manager);
263 263
264 using api::file_system::Volume;
265 const auto& volume_list = volume_manager->GetVolumeList(); 264 const auto& volume_list = volume_manager->GetVolumeList();
266 // Convert volume_list to result_volume_list. 265 // Convert volume_list to result_volume_list.
267 for (const auto& volume : volume_list) { 266 for (const auto& volume : volume_list) {
268 const linked_ptr<Volume> result_volume(new Volume); 267 api::file_system::Volume result_volume;
269 result_volume->volume_id = volume->volume_id(); 268 result_volume.volume_id = volume->volume_id();
270 result_volume->writable = !volume->is_read_only(); 269 result_volume.writable = !volume->is_read_only();
271 result->push_back(result_volume); 270 result->push_back(std::move(result_volume));
272 } 271 }
273 } 272 }
274 #endif 273 #endif
275 274
276 } // namespace 275 } // namespace
277 276
278 namespace file_system_api { 277 namespace file_system_api {
279 278
280 base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs, 279 base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs,
281 const std::string& extension_id) { 280 const std::string& extension_id) {
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 const AcceptOptions* accepts, 971 const AcceptOptions* accepts,
973 const bool* acceptsAllTypes) { 972 const bool* acceptsAllTypes) {
974 file_type_info->include_all_files = true; 973 file_type_info->include_all_files = true;
975 if (acceptsAllTypes) 974 if (acceptsAllTypes)
976 file_type_info->include_all_files = *acceptsAllTypes; 975 file_type_info->include_all_files = *acceptsAllTypes;
977 976
978 bool need_suggestion = !file_type_info->include_all_files && 977 bool need_suggestion = !file_type_info->include_all_files &&
979 !suggested_extension.empty(); 978 !suggested_extension.empty();
980 979
981 if (accepts) { 980 if (accepts) {
982 typedef file_system::AcceptOption AcceptOption; 981 for (const file_system::AcceptOption& option : *accepts) {
983 for (std::vector<linked_ptr<AcceptOption> >::const_iterator iter =
984 accepts->begin(); iter != accepts->end(); ++iter) {
985 base::string16 description; 982 base::string16 description;
986 std::vector<base::FilePath::StringType> extensions; 983 std::vector<base::FilePath::StringType> extensions;
987 984
988 if (!GetFileTypesFromAcceptOption(**iter, &extensions, &description)) 985 if (!GetFileTypesFromAcceptOption(option, &extensions, &description))
989 continue; // No extensions were found. 986 continue; // No extensions were found.
990 987
991 file_type_info->extensions.push_back(extensions); 988 file_type_info->extensions.push_back(extensions);
992 file_type_info->extension_description_overrides.push_back(description); 989 file_type_info->extension_description_overrides.push_back(description);
993 990
994 // If we still need to find suggested_extension, hunt for it inside the 991 // If we still need to find suggested_extension, hunt for it inside the
995 // extensions returned from GetFileTypesFromAcceptOption. 992 // extensions returned from GetFileTypesFromAcceptOption.
996 if (need_suggestion && std::find(extensions.begin(), 993 if (need_suggestion && std::find(extensions.begin(),
997 extensions.end(), suggested_extension) != extensions.end()) { 994 extensions.end(), suggested_extension) != extensions.end()) {
998 need_suggestion = false; 995 need_suggestion = false;
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 1438
1442 ExtensionFunction::ResponseAction FileSystemGetVolumeListFunction::Run() { 1439 ExtensionFunction::ResponseAction FileSystemGetVolumeListFunction::Run() {
1443 // Only kiosk apps in kiosk sessions can use this API. 1440 // Only kiosk apps in kiosk sessions can use this API.
1444 // Additionally it is enabled for whitelisted component extensions and apps. 1441 // Additionally it is enabled for whitelisted component extensions and apps.
1445 file_system_api::ConsentProviderDelegate consent_provider_delegate( 1442 file_system_api::ConsentProviderDelegate consent_provider_delegate(
1446 chrome_details_.GetProfile(), render_frame_host()); 1443 chrome_details_.GetProfile(), render_frame_host());
1447 file_system_api::ConsentProvider consent_provider(&consent_provider_delegate); 1444 file_system_api::ConsentProvider consent_provider(&consent_provider_delegate);
1448 1445
1449 if (!consent_provider.IsGrantable(*extension())) 1446 if (!consent_provider.IsGrantable(*extension()))
1450 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); 1447 return RespondNow(Error(kNotSupportedOnNonKioskSessionError));
1451 using api::file_system::Volume; 1448 std::vector<api::file_system::Volume> result_volume_list;
1452 std::vector<linked_ptr<Volume>> result_volume_list;
1453 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list); 1449 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list);
1454 1450
1455 return RespondNow(ArgumentList( 1451 return RespondNow(ArgumentList(
1456 api::file_system::GetVolumeList::Results::Create(result_volume_list))); 1452 api::file_system::GetVolumeList::Results::Create(result_volume_list)));
1457 } 1453 }
1458 #endif 1454 #endif
1459 1455
1460 } // namespace extensions 1456 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698