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

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

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 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>
11 11
12 #include "apps/saved_files_service.h" 12 #include "apps/saved_files_service.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/linked_ptr.h" 18 #include "base/memory/linked_ptr.h"
19 #include "base/memory/ptr_util.h"
19 #include "base/path_service.h" 20 #include "base/path_service.h"
20 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
22 #include "base/strings/sys_string_conversions.h" 23 #include "base/strings/sys_string_conversions.h"
23 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
24 #include "base/value_conversions.h" 25 #include "base/value_conversions.h"
25 #include "base/values.h" 26 #include "base/values.h"
26 #include "build/build_config.h" 27 #include "build/build_config.h"
27 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" 28 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
28 #include "chrome/browser/extensions/extension_service.h" 29 #include "chrome/browser/extensions/extension_service.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 207
207 const int kGraylistedPaths[] = { 208 const int kGraylistedPaths[] = {
208 base::DIR_HOME, 209 base::DIR_HOME,
209 #if defined(OS_WIN) 210 #if defined(OS_WIN)
210 base::DIR_PROGRAM_FILES, 211 base::DIR_PROGRAM_FILES,
211 base::DIR_PROGRAM_FILESX86, 212 base::DIR_PROGRAM_FILESX86,
212 base::DIR_WINDOWS, 213 base::DIR_WINDOWS,
213 #endif 214 #endif
214 }; 215 };
215 216
216 typedef base::Callback<void(scoped_ptr<base::File::Info>)> FileInfoOptCallback; 217 typedef base::Callback<void(std::unique_ptr<base::File::Info>)>
218 FileInfoOptCallback;
217 219
218 // Passes optional file info to the UI thread depending on |result| and |info|. 220 // Passes optional file info to the UI thread depending on |result| and |info|.
219 void PassFileInfoToUIThread(const FileInfoOptCallback& callback, 221 void PassFileInfoToUIThread(const FileInfoOptCallback& callback,
220 base::File::Error result, 222 base::File::Error result,
221 const base::File::Info& info) { 223 const base::File::Info& info) {
222 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 224 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
223 scoped_ptr<base::File::Info> file_info( 225 std::unique_ptr<base::File::Info> file_info(
224 result == base::File::FILE_OK ? new base::File::Info(info) : NULL); 226 result == base::File::FILE_OK ? new base::File::Info(info) : NULL);
225 content::BrowserThread::PostTask( 227 content::BrowserThread::PostTask(
226 content::BrowserThread::UI, 228 content::BrowserThread::UI,
227 FROM_HERE, 229 FROM_HERE,
228 base::Bind(callback, base::Passed(&file_info))); 230 base::Bind(callback, base::Passed(&file_info)));
229 } 231 }
230 232
231 // Gets a WebContents instance handle for a platform app hosted in 233 // Gets a WebContents instance handle for a platform app hosted in
232 // |render_frame_host|. If not found, then returns NULL. 234 // |render_frame_host|. If not found, then returns NULL.
233 content::WebContents* GetWebContentsForRenderFrameHost( 235 content::WebContents* GetWebContentsForRenderFrameHost(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 311
310 ConsentProviderDelegate consent_provider_delegate(profile, nullptr); 312 ConsentProviderDelegate consent_provider_delegate(profile, nullptr);
311 ConsentProvider consent_provider(&consent_provider_delegate); 313 ConsentProvider consent_provider(&consent_provider_delegate);
312 api::file_system::VolumeListChangedEvent event_args; 314 api::file_system::VolumeListChangedEvent event_args;
313 FillVolumeList(profile, &event_args.volumes); 315 FillVolumeList(profile, &event_args.volumes);
314 for (const auto& extension : registry->enabled_extensions()) { 316 for (const auto& extension : registry->enabled_extensions()) {
315 if (!consent_provider.IsGrantable(*extension.get())) 317 if (!consent_provider.IsGrantable(*extension.get()))
316 continue; 318 continue;
317 event_router->DispatchEventToExtension( 319 event_router->DispatchEventToExtension(
318 extension->id(), 320 extension->id(),
319 make_scoped_ptr(new Event( 321 base::WrapUnique(new Event(
320 events::FILE_SYSTEM_ON_VOLUME_LIST_CHANGED, 322 events::FILE_SYSTEM_ON_VOLUME_LIST_CHANGED,
321 api::file_system::OnVolumeListChanged::kEventName, 323 api::file_system::OnVolumeListChanged::kEventName,
322 api::file_system::OnVolumeListChanged::Create(event_args)))); 324 api::file_system::OnVolumeListChanged::Create(event_args))));
323 } 325 }
324 } 326 }
325 327
326 ConsentProvider::ConsentProvider(DelegateInterface* delegate) 328 ConsentProvider::ConsentProvider(DelegateInterface* delegate)
327 : delegate_(delegate) { 329 : delegate_(delegate) {
328 DCHECK(delegate_); 330 DCHECK(delegate_);
329 } 331 }
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 if (PathService::Get(chrome::DIR_USER_DOCUMENTS, &documents_dir)) { 1039 if (PathService::Get(chrome::DIR_USER_DOCUMENTS, &documents_dir)) {
1038 initial_path_ = documents_dir.Append(suggested_name); 1040 initial_path_ = documents_dir.Append(suggested_name);
1039 } else { 1041 } else {
1040 initial_path_ = suggested_name; 1042 initial_path_ = suggested_name;
1041 } 1043 }
1042 } 1044 }
1043 ShowPicker(file_type_info, picker_type); 1045 ShowPicker(file_type_info, picker_type);
1044 } 1046 }
1045 1047
1046 bool FileSystemChooseEntryFunction::RunAsync() { 1048 bool FileSystemChooseEntryFunction::RunAsync() {
1047 scoped_ptr<ChooseEntry::Params> params(ChooseEntry::Params::Create(*args_)); 1049 std::unique_ptr<ChooseEntry::Params> params(
1050 ChooseEntry::Params::Create(*args_));
1048 EXTENSION_FUNCTION_VALIDATE(params.get()); 1051 EXTENSION_FUNCTION_VALIDATE(params.get());
1049 1052
1050 base::FilePath suggested_name; 1053 base::FilePath suggested_name;
1051 ui::SelectFileDialog::FileTypeInfo file_type_info; 1054 ui::SelectFileDialog::FileTypeInfo file_type_info;
1052 ui::SelectFileDialog::Type picker_type = 1055 ui::SelectFileDialog::Type picker_type =
1053 ui::SelectFileDialog::SELECT_OPEN_FILE; 1056 ui::SelectFileDialog::SELECT_OPEN_FILE;
1054 1057
1055 file_system::ChooseEntryOptions* options = params->options.get(); 1058 file_system::ChooseEntryOptions* options = params->options.get();
1056 if (options) { 1059 if (options) {
1057 multiple_ = options->accepts_multiple && *options->accepts_multiple; 1060 multiple_ = options->accepts_multiple && *options->accepts_multiple;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 } 1178 }
1176 1179
1177 saved_files_service->EnqueueFileEntry(extension_->id(), entry_id); 1180 saved_files_service->EnqueueFileEntry(extension_->id(), entry_id);
1178 SendResponse(true); 1181 SendResponse(true);
1179 return true; 1182 return true;
1180 } 1183 }
1181 1184
1182 void FileSystemRetainEntryFunction::RetainFileEntry( 1185 void FileSystemRetainEntryFunction::RetainFileEntry(
1183 const std::string& entry_id, 1186 const std::string& entry_id,
1184 const base::FilePath& path, 1187 const base::FilePath& path,
1185 scoped_ptr<base::File::Info> file_info) { 1188 std::unique_ptr<base::File::Info> file_info) {
1186 if (!file_info) { 1189 if (!file_info) {
1187 SendResponse(false); 1190 SendResponse(false);
1188 return; 1191 return;
1189 } 1192 }
1190 1193
1191 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile()); 1194 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile());
1192 saved_files_service->RegisterFileEntry( 1195 saved_files_service->RegisterFileEntry(
1193 extension_->id(), entry_id, path, file_info->is_directory); 1196 extension_->id(), entry_id, path, file_info->is_directory);
1194 saved_files_service->EnqueueFileEntry(extension_->id(), entry_id); 1197 saved_files_service->EnqueueFileEntry(extension_->id(), entry_id);
1195 SendResponse(true); 1198 SendResponse(true);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 1247
1245 bool FileSystemGetObservedEntriesFunction::RunSync() { 1248 bool FileSystemGetObservedEntriesFunction::RunSync() {
1246 NOTIMPLEMENTED(); 1249 NOTIMPLEMENTED();
1247 error_ = kUnknownIdError; 1250 error_ = kUnknownIdError;
1248 return false; 1251 return false;
1249 } 1252 }
1250 1253
1251 #if !defined(OS_CHROMEOS) 1254 #if !defined(OS_CHROMEOS)
1252 ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() { 1255 ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() {
1253 using api::file_system::RequestFileSystem::Params; 1256 using api::file_system::RequestFileSystem::Params;
1254 const scoped_ptr<Params> params(Params::Create(*args_)); 1257 const std::unique_ptr<Params> params(Params::Create(*args_));
1255 EXTENSION_FUNCTION_VALIDATE(params); 1258 EXTENSION_FUNCTION_VALIDATE(params);
1256 1259
1257 NOTIMPLEMENTED(); 1260 NOTIMPLEMENTED();
1258 return RespondNow(Error(kNotSupportedOnCurrentPlatformError)); 1261 return RespondNow(Error(kNotSupportedOnCurrentPlatformError));
1259 } 1262 }
1260 1263
1261 ExtensionFunction::ResponseAction FileSystemGetVolumeListFunction::Run() { 1264 ExtensionFunction::ResponseAction FileSystemGetVolumeListFunction::Run() {
1262 NOTIMPLEMENTED(); 1265 NOTIMPLEMENTED();
1263 return RespondNow(Error(kNotSupportedOnCurrentPlatformError)); 1266 return RespondNow(Error(kNotSupportedOnCurrentPlatformError));
1264 } 1267 }
1265 #else 1268 #else
1266 1269
1267 FileSystemRequestFileSystemFunction::FileSystemRequestFileSystemFunction() 1270 FileSystemRequestFileSystemFunction::FileSystemRequestFileSystemFunction()
1268 : chrome_details_(this) { 1271 : chrome_details_(this) {
1269 } 1272 }
1270 1273
1271 FileSystemRequestFileSystemFunction::~FileSystemRequestFileSystemFunction() { 1274 FileSystemRequestFileSystemFunction::~FileSystemRequestFileSystemFunction() {
1272 } 1275 }
1273 1276
1274 ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() { 1277 ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() {
1275 using api::file_system::RequestFileSystem::Params; 1278 using api::file_system::RequestFileSystem::Params;
1276 const scoped_ptr<Params> params(Params::Create(*args_)); 1279 const std::unique_ptr<Params> params(Params::Create(*args_));
1277 EXTENSION_FUNCTION_VALIDATE(params); 1280 EXTENSION_FUNCTION_VALIDATE(params);
1278 1281
1279 // Only kiosk apps in kiosk sessions can use this API. 1282 // Only kiosk apps in kiosk sessions can use this API.
1280 // Additionally it is enabled for whitelisted component extensions and apps. 1283 // Additionally it is enabled for whitelisted component extensions and apps.
1281 file_system_api::ConsentProviderDelegate consent_provider_delegate( 1284 file_system_api::ConsentProviderDelegate consent_provider_delegate(
1282 chrome_details_.GetProfile(), render_frame_host()); 1285 chrome_details_.GetProfile(), render_frame_host());
1283 file_system_api::ConsentProvider consent_provider(&consent_provider_delegate); 1286 file_system_api::ConsentProvider consent_provider(&consent_provider_delegate);
1284 1287
1285 if (!consent_provider.IsGrantable(*extension())) 1288 if (!consent_provider.IsGrantable(*extension()))
1286 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); 1289 return RespondNow(Error(kNotSupportedOnNonKioskSessionError));
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); 1450 return RespondNow(Error(kNotSupportedOnNonKioskSessionError));
1448 std::vector<api::file_system::Volume> result_volume_list; 1451 std::vector<api::file_system::Volume> result_volume_list;
1449 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list); 1452 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list);
1450 1453
1451 return RespondNow(ArgumentList( 1454 return RespondNow(ArgumentList(
1452 api::file_system::GetVolumeList::Results::Create(result_volume_list))); 1455 api::file_system::GetVolumeList::Results::Create(result_volume_list)));
1453 } 1456 }
1454 #endif 1457 #endif
1455 1458
1456 } // namespace extensions 1459 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698