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

Side by Side Diff: chrome/browser/extensions/extension_file_browser_private_api.cc

Issue 9372044: Refactor FileSystemOperation to take callback for each method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
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/extension_file_browser_private_api.h" 5 #include "chrome/browser/extensions/extension_file_browser_private_api.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 mount_info->SetString("mountCondition", 303 mount_info->SetString("mountCondition",
304 DiskMountManager::MountConditionToString( 304 DiskMountManager::MountConditionToString(
305 mount_point_info.mount_condition)); 305 mount_point_info.mount_condition));
306 306
307 return mount_info; 307 return mount_info;
308 } 308 }
309 #endif 309 #endif
310 310
311 } // namespace 311 } // namespace
312 312
313 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher 313 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher {
314 : public fileapi::FileSystemCallbackDispatcher {
315 public: 314 public:
316 static scoped_ptr<FileSystemCallbackDispatcher> Create( 315 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback(
317 RequestLocalFileSystemFunction* function, 316 RequestLocalFileSystemFunction* function,
318 Profile* profile, 317 Profile* profile,
319 int child_id, 318 int child_id,
320 scoped_refptr<const Extension> extension) { 319 scoped_refptr<const Extension> extension) {
321 return scoped_ptr<fileapi::FileSystemCallbackDispatcher>( 320 return base::Bind(
322 new LocalFileSystemCallbackDispatcher( 321 &LocalFileSystemCallbackDispatcher::DidOpenFileSystem,
323 function, profile, child_id, extension)); 322 base::Owned(new LocalFileSystemCallbackDispatcher(
323 function, profile, child_id, extension)));
324 } 324 }
325 325
326 // fileapi::FileSystemCallbackDispatcher overrides. 326 void DidOpenFileSystem(base::PlatformFileError result,
327 virtual void DidSucceed() OVERRIDE { 327 const std::string& name,
328 NOTREACHED(); 328 const GURL& root_path) OVERRIDE {
329 } 329 if (result != base::PLATFORM_FILE_OK) {
330 330 DidFail(result);
331 virtual void DidReadMetadata(const base::PlatformFileInfo& info, 331 return;
332 const FilePath& unused) OVERRIDE { 332 }
333 NOTREACHED();
334 }
335
336 virtual void DidReadDirectory(
337 const std::vector<base::FileUtilProxy::Entry>& entries,
338 bool has_more) OVERRIDE {
339 NOTREACHED();
340 }
341
342 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE {
343 NOTREACHED();
344 }
345
346 virtual void DidOpenFileSystem(const std::string& name,
347 const GURL& root_path) OVERRIDE {
348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
349 // Set up file permission access. 334 // Set up file permission access.
350 if (!SetupFileSystemAccessPermissions()) { 335 if (!SetupFileSystemAccessPermissions()) {
351 DidFail(base::PLATFORM_FILE_ERROR_SECURITY); 336 DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
352 return; 337 return;
353 } 338 }
354 339
355 BrowserThread::PostTask( 340 BrowserThread::PostTask(
356 BrowserThread::UI, FROM_HERE, 341 BrowserThread::UI, FROM_HERE,
357 base::Bind( 342 base::Bind(
358 &RequestLocalFileSystemFunction::RespondSuccessOnUIThread, 343 &RequestLocalFileSystemFunction::RespondSuccessOnUIThread,
359 function_, 344 function_,
360 name, 345 name,
361 root_path)); 346 root_path));
362 } 347 }
363 348
364 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { 349 void DidFail(base::PlatformFileError error_code) OVERRIDE {
365 BrowserThread::PostTask( 350 BrowserThread::PostTask(
366 BrowserThread::UI, FROM_HERE, 351 BrowserThread::UI, FROM_HERE,
367 base::Bind( 352 base::Bind(
368 &RequestLocalFileSystemFunction::RespondFailedOnUIThread, 353 &RequestLocalFileSystemFunction::RespondFailedOnUIThread,
369 function_, 354 function_,
370 error_code)); 355 error_code));
371 } 356 }
372 357
373 private: 358 private:
374 LocalFileSystemCallbackDispatcher( 359 LocalFileSystemCallbackDispatcher(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // Extension source URL. 408 // Extension source URL.
424 scoped_refptr<const Extension> extension_; 409 scoped_refptr<const Extension> extension_;
425 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher); 410 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher);
426 }; 411 };
427 412
428 void RequestLocalFileSystemFunction::RequestOnFileThread( 413 void RequestLocalFileSystemFunction::RequestOnFileThread(
429 const GURL& source_url, int child_id) { 414 const GURL& source_url, int child_id) {
430 GURL origin_url = source_url.GetOrigin(); 415 GURL origin_url = source_url.GetOrigin();
431 profile()->GetFileSystemContext()->OpenFileSystem( 416 profile()->GetFileSystemContext()->OpenFileSystem(
432 origin_url, fileapi::kFileSystemTypeExternal, false, // create 417 origin_url, fileapi::kFileSystemTypeExternal, false, // create
433 LocalFileSystemCallbackDispatcher::Create( 418 LocalFileSystemCallbackDispatcher::CreateCallback(
434 this, 419 this,
435 profile(), 420 profile(),
436 child_id, 421 child_id,
437 GetExtension())); 422 GetExtension()));
438 } 423 }
439 424
440 bool RequestLocalFileSystemFunction::RunImpl() { 425 bool RequestLocalFileSystemFunction::RunImpl() {
441 if (!dispatcher() || !render_view_host() || !render_view_host()->process()) 426 if (!dispatcher() || !render_view_host() || !render_view_host()->process())
442 return false; 427 return false;
443 428
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 task->SetString("iconUrl", icon.spec()); 602 task->SetString("iconUrl", icon.spec());
618 result_list->Append(task); 603 result_list->Append(task);
619 } 604 }
620 605
621 // TODO(zelidrag, serya): Add intent content tasks to result_list once we 606 // TODO(zelidrag, serya): Add intent content tasks to result_list once we
622 // implement that API. 607 // implement that API.
623 SendResponse(true); 608 SendResponse(true);
624 return true; 609 return true;
625 } 610 }
626 611
627 class ExecuteTasksFileBrowserFunction::ExecuteTasksFileSystemCallbackDispatcher 612 class
628 : public fileapi::FileSystemCallbackDispatcher { 613 ExecuteTasksFileBrowserFunction::ExecuteTasksFileSystemCallbackDispatcher {
629 public: 614 public:
630 static scoped_ptr<fileapi::FileSystemCallbackDispatcher> Create( 615 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback(
kinuko 2012/02/10 05:34:09 Nice practical solution.
kinaba 2012/02/10 08:22:58 :)
631 ExecuteTasksFileBrowserFunction* function, 616 ExecuteTasksFileBrowserFunction* function,
632 Profile* profile, 617 Profile* profile,
633 int child_id, 618 int child_id,
634 const GURL& source_url, 619 const GURL& source_url,
635 scoped_refptr<const Extension> extension, 620 scoped_refptr<const Extension> extension,
636 const std::string task_id, 621 const std::string task_id,
637 const std::vector<GURL>& file_urls) { 622 const std::vector<GURL>& file_urls) {
638 return scoped_ptr<fileapi::FileSystemCallbackDispatcher>( 623 return base::Bind(
639 new ExecuteTasksFileSystemCallbackDispatcher( 624 &ExecuteTasksFileSystemCallbackDispatcher::DidOpenFileSystem,
625 base::Owned(new ExecuteTasksFileSystemCallbackDispatcher(
640 function, profile, child_id, source_url, extension, 626 function, profile, child_id, source_url, extension,
641 task_id, file_urls)); 627 task_id, file_urls)));
642 } 628 }
643 629
644 // fileapi::FileSystemCallbackDispatcher overrides. 630 void DidOpenFileSystem(base::PlatformFileError result,
645 virtual void DidSucceed() OVERRIDE { 631 const std::string& file_system_name,
646 NOTREACHED(); 632 const GURL& file_system_root) OVERRIDE {
647 } 633 if (result != base::PLATFORM_FILE_OK) {
648 634 DidFail(result);
649 virtual void DidReadMetadata(const base::PlatformFileInfo& info, 635 return;
650 const FilePath& unused) OVERRIDE { 636 }
651 NOTREACHED();
652 }
653
654 virtual void DidReadDirectory(
655 const std::vector<base::FileUtilProxy::Entry>& entries,
656 bool has_more) OVERRIDE {
657 NOTREACHED();
658 }
659
660 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE {
661 NOTREACHED();
662 }
663
664 virtual void DidOpenFileSystem(const std::string& file_system_name,
665 const GURL& file_system_root) OVERRIDE {
666 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
667 ExecuteTasksFileBrowserFunction::FileDefinitionList file_list; 638 ExecuteTasksFileBrowserFunction::FileDefinitionList file_list;
668 for (std::vector<GURL>::iterator iter = origin_file_urls_.begin(); 639 for (std::vector<GURL>::iterator iter = origin_file_urls_.begin();
669 iter != origin_file_urls_.end(); 640 iter != origin_file_urls_.end();
670 ++iter) { 641 ++iter) {
671 // Set up file permission access. 642 // Set up file permission access.
672 ExecuteTasksFileBrowserFunction::FileDefinition file; 643 ExecuteTasksFileBrowserFunction::FileDefinition file;
673 if (!SetupFileAccessPermissions(*iter, &file.target_file_url, 644 if (!SetupFileAccessPermissions(*iter, &file.target_file_url,
674 &file.virtual_path, &file.is_directory)) { 645 &file.virtual_path, &file.is_directory)) {
675 continue; 646 continue;
(...skipping 13 matching lines...) Expand all
689 BrowserThread::UI, FROM_HERE, 660 BrowserThread::UI, FROM_HERE,
690 base::Bind( 661 base::Bind(
691 &ExecuteTasksFileBrowserFunction::ExecuteFileActionsOnUIThread, 662 &ExecuteTasksFileBrowserFunction::ExecuteFileActionsOnUIThread,
692 function_, 663 function_,
693 task_id_, 664 task_id_,
694 file_system_name, 665 file_system_name,
695 file_system_root, 666 file_system_root,
696 file_list)); 667 file_list));
697 } 668 }
698 669
699 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { 670 void DidFail(base::PlatformFileError error_code) {
700 BrowserThread::PostTask( 671 BrowserThread::PostTask(
701 BrowserThread::UI, FROM_HERE, 672 BrowserThread::UI, FROM_HERE,
702 base::Bind( 673 base::Bind(
703 &ExecuteTasksFileBrowserFunction::ExecuteFailedOnUIThread, 674 &ExecuteTasksFileBrowserFunction::ExecuteFailedOnUIThread,
704 function_)); 675 function_));
705 } 676 }
706 677
707 private: 678 private:
708 ExecuteTasksFileSystemCallbackDispatcher( 679 ExecuteTasksFileSystemCallbackDispatcher(
709 ExecuteTasksFileBrowserFunction* function, 680 ExecuteTasksFileBrowserFunction* function,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 return true; 859 return true;
889 } 860 }
890 861
891 void ExecuteTasksFileBrowserFunction::RequestFileEntryOnFileThread( 862 void ExecuteTasksFileBrowserFunction::RequestFileEntryOnFileThread(
892 const GURL& source_url, const std::string& task_id, 863 const GURL& source_url, const std::string& task_id,
893 const std::vector<GURL>& file_urls) { 864 const std::vector<GURL>& file_urls) {
894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 865 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
895 GURL origin_url = source_url.GetOrigin(); 866 GURL origin_url = source_url.GetOrigin();
896 profile()->GetFileSystemContext()->OpenFileSystem( 867 profile()->GetFileSystemContext()->OpenFileSystem(
897 origin_url, fileapi::kFileSystemTypeExternal, false, // create 868 origin_url, fileapi::kFileSystemTypeExternal, false, // create
898 ExecuteTasksFileSystemCallbackDispatcher::Create( 869 ExecuteTasksFileSystemCallbackDispatcher::CreateCallback(
899 this, 870 this,
900 profile(), 871 profile(),
901 render_view_host()->process()->GetID(), 872 render_view_host()->process()->GetID(),
902 source_url, 873 source_url,
903 GetExtension(), 874 GetExtension(),
904 task_id, 875 task_id,
905 file_urls)); 876 file_urls));
906 } 877 }
907 878
908 void ExecuteTasksFileBrowserFunction::ExecuteFailedOnUIThread() { 879 void ExecuteTasksFileBrowserFunction::ExecuteFailedOnUIThread() {
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 SET_STRING(IDS_FILE_BROWSER, ENQUEUE); 1654 SET_STRING(IDS_FILE_BROWSER, ENQUEUE);
1684 #undef SET_STRING 1655 #undef SET_STRING
1685 1656
1686 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); 1657 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict);
1687 1658
1688 dict->SetString("PLAY_MEDIA", 1659 dict->SetString("PLAY_MEDIA",
1689 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); 1660 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY));
1690 1661
1691 return true; 1662 return true;
1692 } 1663 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698