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

Side by Side Diff: chrome/browser/chromeos/file_manager/file_browser_handlers.cc

Issue 1870793002: Convert //chrome/browser/chromeos from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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/chromeos/file_manager/file_browser_handlers.h" 5 #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // Executes the task for each file. |done| will be run with the result. 172 // Executes the task for each file. |done| will be run with the result.
173 void Execute(const std::vector<FileSystemURL>& file_urls, 173 void Execute(const std::vector<FileSystemURL>& file_urls,
174 const file_tasks::FileTaskFinishedCallback& done); 174 const file_tasks::FileTaskFinishedCallback& done);
175 175
176 private: 176 private:
177 // This object is responsible to delete itself. 177 // This object is responsible to delete itself.
178 virtual ~FileBrowserHandlerExecutor(); 178 virtual ~FileBrowserHandlerExecutor();
179 179
180 // Checks legitimacy of file url and grants file RO access permissions from 180 // Checks legitimacy of file url and grants file RO access permissions from
181 // handler (target) extension and its renderer process. 181 // handler (target) extension and its renderer process.
182 static scoped_ptr<FileDefinitionList> SetupFileAccessPermissions( 182 static std::unique_ptr<FileDefinitionList> SetupFileAccessPermissions(
183 scoped_refptr<storage::FileSystemContext> file_system_context_handler, 183 scoped_refptr<storage::FileSystemContext> file_system_context_handler,
184 const scoped_refptr<const Extension>& handler_extension, 184 const scoped_refptr<const Extension>& handler_extension,
185 const std::vector<FileSystemURL>& file_urls); 185 const std::vector<FileSystemURL>& file_urls);
186 186
187 void ExecuteDoneOnUIThread(bool success); 187 void ExecuteDoneOnUIThread(bool success);
188 void ExecuteAfterSetupFileAccess(scoped_ptr<FileDefinitionList> file_list); 188 void ExecuteAfterSetupFileAccess(
189 std::unique_ptr<FileDefinitionList> file_list);
189 void ExecuteFileActionsOnUIThread( 190 void ExecuteFileActionsOnUIThread(
190 scoped_ptr<FileDefinitionList> file_definition_list, 191 std::unique_ptr<FileDefinitionList> file_definition_list,
191 scoped_ptr<EntryDefinitionList> entry_definition_list); 192 std::unique_ptr<EntryDefinitionList> entry_definition_list);
192 void SetupPermissionsAndDispatchEvent( 193 void SetupPermissionsAndDispatchEvent(
193 scoped_ptr<FileDefinitionList> file_definition_list, 194 std::unique_ptr<FileDefinitionList> file_definition_list,
194 scoped_ptr<EntryDefinitionList> entry_definition_list, 195 std::unique_ptr<EntryDefinitionList> entry_definition_list,
195 int handler_pid_in, 196 int handler_pid_in,
196 extensions::ExtensionHost* host); 197 extensions::ExtensionHost* host);
197 198
198 // Registers file permissions from |handler_host_permissions_| with 199 // Registers file permissions from |handler_host_permissions_| with
199 // ChildProcessSecurityPolicy for process with id |handler_pid|. 200 // ChildProcessSecurityPolicy for process with id |handler_pid|.
200 void SetupHandlerHostFileAccessPermissions( 201 void SetupHandlerHostFileAccessPermissions(
201 FileDefinitionList* file_definition_list, 202 FileDefinitionList* file_definition_list,
202 const Extension* extension, 203 const Extension* extension,
203 int handler_pid); 204 int handler_pid);
204 205
205 Profile* profile_; 206 Profile* profile_;
206 scoped_refptr<const Extension> extension_; 207 scoped_refptr<const Extension> extension_;
207 const std::string action_id_; 208 const std::string action_id_;
208 file_tasks::FileTaskFinishedCallback done_; 209 file_tasks::FileTaskFinishedCallback done_;
209 base::WeakPtrFactory<FileBrowserHandlerExecutor> weak_ptr_factory_; 210 base::WeakPtrFactory<FileBrowserHandlerExecutor> weak_ptr_factory_;
210 211
211 DISALLOW_COPY_AND_ASSIGN(FileBrowserHandlerExecutor); 212 DISALLOW_COPY_AND_ASSIGN(FileBrowserHandlerExecutor);
212 }; 213 };
213 214
214 // static 215 // static
215 scoped_ptr<FileDefinitionList> 216 std::unique_ptr<FileDefinitionList>
216 FileBrowserHandlerExecutor::SetupFileAccessPermissions( 217 FileBrowserHandlerExecutor::SetupFileAccessPermissions(
217 scoped_refptr<storage::FileSystemContext> file_system_context_handler, 218 scoped_refptr<storage::FileSystemContext> file_system_context_handler,
218 const scoped_refptr<const Extension>& handler_extension, 219 const scoped_refptr<const Extension>& handler_extension,
219 const std::vector<FileSystemURL>& file_urls) { 220 const std::vector<FileSystemURL>& file_urls) {
220 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 221 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
221 DCHECK(handler_extension.get()); 222 DCHECK(handler_extension.get());
222 223
223 storage::ExternalFileSystemBackend* backend = 224 storage::ExternalFileSystemBackend* backend =
224 file_system_context_handler->external_backend(); 225 file_system_context_handler->external_backend();
225 226
226 scoped_ptr<FileDefinitionList> file_definition_list(new FileDefinitionList); 227 std::unique_ptr<FileDefinitionList> file_definition_list(
228 new FileDefinitionList);
227 for (size_t i = 0; i < file_urls.size(); ++i) { 229 for (size_t i = 0; i < file_urls.size(); ++i) {
228 const FileSystemURL& url = file_urls[i]; 230 const FileSystemURL& url = file_urls[i];
229 231
230 // Check if this file system entry exists first. 232 // Check if this file system entry exists first.
231 base::File::Info file_info; 233 base::File::Info file_info;
232 234
233 base::FilePath local_path = url.path(); 235 base::FilePath local_path = url.path();
234 base::FilePath virtual_path = url.virtual_path(); 236 base::FilePath virtual_path = url.virtual_path();
235 237
236 const bool is_drive_file = url.type() == storage::kFileSystemTypeDrive; 238 const bool is_drive_file = url.type() == storage::kFileSystemTypeDrive;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 FROM_HERE, 295 FROM_HERE,
294 base::Bind(&SetupFileAccessPermissions, 296 base::Bind(&SetupFileAccessPermissions,
295 file_system_context, 297 file_system_context,
296 extension_, 298 extension_,
297 file_urls), 299 file_urls),
298 base::Bind(&FileBrowserHandlerExecutor::ExecuteAfterSetupFileAccess, 300 base::Bind(&FileBrowserHandlerExecutor::ExecuteAfterSetupFileAccess,
299 weak_ptr_factory_.GetWeakPtr())); 301 weak_ptr_factory_.GetWeakPtr()));
300 } 302 }
301 303
302 void FileBrowserHandlerExecutor::ExecuteAfterSetupFileAccess( 304 void FileBrowserHandlerExecutor::ExecuteAfterSetupFileAccess(
303 scoped_ptr<FileDefinitionList> file_definition_list) { 305 std::unique_ptr<FileDefinitionList> file_definition_list) {
304 // Outlives the conversion process, since bound to the callback. 306 // Outlives the conversion process, since bound to the callback.
305 const FileDefinitionList& file_definition_list_ref = 307 const FileDefinitionList& file_definition_list_ref =
306 *file_definition_list.get(); 308 *file_definition_list.get();
307 file_manager::util::ConvertFileDefinitionListToEntryDefinitionList( 309 file_manager::util::ConvertFileDefinitionListToEntryDefinitionList(
308 profile_, 310 profile_,
309 extension_->id(), 311 extension_->id(),
310 file_definition_list_ref, 312 file_definition_list_ref,
311 base::Bind(&FileBrowserHandlerExecutor::ExecuteFileActionsOnUIThread, 313 base::Bind(&FileBrowserHandlerExecutor::ExecuteFileActionsOnUIThread,
312 weak_ptr_factory_.GetWeakPtr(), 314 weak_ptr_factory_.GetWeakPtr(),
313 base::Passed(&file_definition_list))); 315 base::Passed(&file_definition_list)));
314 } 316 }
315 317
316 void FileBrowserHandlerExecutor::ExecuteDoneOnUIThread(bool success) { 318 void FileBrowserHandlerExecutor::ExecuteDoneOnUIThread(bool success) {
317 DCHECK_CURRENTLY_ON(BrowserThread::UI); 319 DCHECK_CURRENTLY_ON(BrowserThread::UI);
318 if (!done_.is_null()) 320 if (!done_.is_null())
319 done_.Run( 321 done_.Run(
320 success 322 success
321 ? extensions::api::file_manager_private::TASK_RESULT_MESSAGE_SENT 323 ? extensions::api::file_manager_private::TASK_RESULT_MESSAGE_SENT
322 : extensions::api::file_manager_private::TASK_RESULT_FAILED); 324 : extensions::api::file_manager_private::TASK_RESULT_FAILED);
323 delete this; 325 delete this;
324 } 326 }
325 327
326 void FileBrowserHandlerExecutor::ExecuteFileActionsOnUIThread( 328 void FileBrowserHandlerExecutor::ExecuteFileActionsOnUIThread(
327 scoped_ptr<FileDefinitionList> file_definition_list, 329 std::unique_ptr<FileDefinitionList> file_definition_list,
328 scoped_ptr<EntryDefinitionList> entry_definition_list) { 330 std::unique_ptr<EntryDefinitionList> entry_definition_list) {
329 DCHECK_CURRENTLY_ON(BrowserThread::UI); 331 DCHECK_CURRENTLY_ON(BrowserThread::UI);
330 332
331 if (file_definition_list->empty() || entry_definition_list->empty()) { 333 if (file_definition_list->empty() || entry_definition_list->empty()) {
332 ExecuteDoneOnUIThread(false); 334 ExecuteDoneOnUIThread(false);
333 return; 335 return;
334 } 336 }
335 337
336 int handler_pid = ExtractProcessFromExtensionId(profile_, extension_->id()); 338 int handler_pid = ExtractProcessFromExtensionId(profile_, extension_->id());
337 if (handler_pid <= 0 && 339 if (handler_pid <= 0 &&
338 !extensions::BackgroundInfo::HasLazyBackgroundPage(extension_.get())) { 340 !extensions::BackgroundInfo::HasLazyBackgroundPage(extension_.get())) {
(...skipping 17 matching lines...) Expand all
356 profile_, extension_->id(), 358 profile_, extension_->id(),
357 base::Bind( 359 base::Bind(
358 &FileBrowserHandlerExecutor::SetupPermissionsAndDispatchEvent, 360 &FileBrowserHandlerExecutor::SetupPermissionsAndDispatchEvent,
359 weak_ptr_factory_.GetWeakPtr(), 361 weak_ptr_factory_.GetWeakPtr(),
360 base::Passed(std::move(file_definition_list)), 362 base::Passed(std::move(file_definition_list)),
361 base::Passed(std::move(entry_definition_list)), handler_pid)); 363 base::Passed(std::move(entry_definition_list)), handler_pid));
362 } 364 }
363 } 365 }
364 366
365 void FileBrowserHandlerExecutor::SetupPermissionsAndDispatchEvent( 367 void FileBrowserHandlerExecutor::SetupPermissionsAndDispatchEvent(
366 scoped_ptr<FileDefinitionList> file_definition_list, 368 std::unique_ptr<FileDefinitionList> file_definition_list,
367 scoped_ptr<EntryDefinitionList> entry_definition_list, 369 std::unique_ptr<EntryDefinitionList> entry_definition_list,
368 int handler_pid_in, 370 int handler_pid_in,
369 extensions::ExtensionHost* host) { 371 extensions::ExtensionHost* host) {
370 int handler_pid = host ? host->render_process_host()->GetID() : 372 int handler_pid = host ? host->render_process_host()->GetID() :
371 handler_pid_in; 373 handler_pid_in;
372 374
373 if (handler_pid <= 0) { 375 if (handler_pid <= 0) {
374 ExecuteDoneOnUIThread(false); 376 ExecuteDoneOnUIThread(false);
375 return; 377 return;
376 } 378 }
377 379
378 extensions::EventRouter* router = extensions::EventRouter::Get(profile_); 380 extensions::EventRouter* router = extensions::EventRouter::Get(profile_);
379 if (!router) { 381 if (!router) {
380 ExecuteDoneOnUIThread(false); 382 ExecuteDoneOnUIThread(false);
381 return; 383 return;
382 } 384 }
383 385
384 SetupHandlerHostFileAccessPermissions( 386 SetupHandlerHostFileAccessPermissions(
385 file_definition_list.get(), extension_.get(), handler_pid); 387 file_definition_list.get(), extension_.get(), handler_pid);
386 388
387 scoped_ptr<base::ListValue> event_args(new base::ListValue()); 389 std::unique_ptr<base::ListValue> event_args(new base::ListValue());
388 event_args->Append(new base::StringValue(action_id_)); 390 event_args->Append(new base::StringValue(action_id_));
389 base::DictionaryValue* details = new base::DictionaryValue(); 391 base::DictionaryValue* details = new base::DictionaryValue();
390 event_args->Append(details); 392 event_args->Append(details);
391 // Get file definitions. These will be replaced with Entry instances by 393 // Get file definitions. These will be replaced with Entry instances by
392 // dispatchEvent() method from event_binding.js. 394 // dispatchEvent() method from event_binding.js.
393 base::ListValue* file_entries = new base::ListValue(); 395 base::ListValue* file_entries = new base::ListValue();
394 details->Set("entries", file_entries); 396 details->Set("entries", file_entries);
395 397
396 for (EntryDefinitionList::const_iterator iter = 398 for (EntryDefinitionList::const_iterator iter =
397 entry_definition_list->begin(); 399 entry_definition_list->begin();
398 iter != entry_definition_list->end(); 400 iter != entry_definition_list->end();
399 ++iter) { 401 ++iter) {
400 base::DictionaryValue* file_def = new base::DictionaryValue(); 402 base::DictionaryValue* file_def = new base::DictionaryValue();
401 file_entries->Append(file_def); 403 file_entries->Append(file_def);
402 file_def->SetString("fileSystemName", iter->file_system_name); 404 file_def->SetString("fileSystemName", iter->file_system_name);
403 file_def->SetString("fileSystemRoot", iter->file_system_root_url); 405 file_def->SetString("fileSystemRoot", iter->file_system_root_url);
404 file_def->SetString("fileFullPath", 406 file_def->SetString("fileFullPath",
405 "/" + iter->full_path.AsUTF8Unsafe()); 407 "/" + iter->full_path.AsUTF8Unsafe());
406 file_def->SetBoolean("fileIsDirectory", iter->is_directory); 408 file_def->SetBoolean("fileIsDirectory", iter->is_directory);
407 } 409 }
408 410
409 scoped_ptr<extensions::Event> event(new extensions::Event( 411 std::unique_ptr<extensions::Event> event(new extensions::Event(
410 extensions::events::FILE_BROWSER_HANDLER_ON_EXECUTE, 412 extensions::events::FILE_BROWSER_HANDLER_ON_EXECUTE,
411 "fileBrowserHandler.onExecute", std::move(event_args))); 413 "fileBrowserHandler.onExecute", std::move(event_args)));
412 event->restrict_to_browser_context = profile_; 414 event->restrict_to_browser_context = profile_;
413 router->DispatchEventToExtension(extension_->id(), std::move(event)); 415 router->DispatchEventToExtension(extension_->id(), std::move(event));
414 416
415 ExecuteDoneOnUIThread(true); 417 ExecuteDoneOnUIThread(true);
416 } 418 }
417 419
418 void FileBrowserHandlerExecutor::SetupHandlerHostFileAccessPermissions( 420 void FileBrowserHandlerExecutor::SetupHandlerHostFileAccessPermissions(
419 FileDefinitionList* file_definition_list, 421 FileDefinitionList* file_definition_list,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 if (common_handlers.empty()) 528 if (common_handlers.empty())
527 return FileBrowserHandlerList(); 529 return FileBrowserHandlerList();
528 } 530 }
529 } 531 }
530 532
531 return common_handlers; 533 return common_handlers;
532 } 534 }
533 535
534 } // namespace file_browser_handlers 536 } // namespace file_browser_handlers
535 } // namespace file_manager 537 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698