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

Side by Side Diff: chrome/browser/chromeos/extensions/file_handler_util.cc

Issue 10692146: Fix more incorrect usage of BrowserContext on the FILE thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix yet another misuse Created 8 years, 5 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
« no previous file with comments | « chrome/browser/chromeos/extensions/file_browser_private_api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/extensions/file_handler_util.h" 5 #include "chrome/browser/chromeos/extensions/file_handler_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 373
374 GURL target_file_url; 374 GURL target_file_url;
375 FilePath virtual_path; 375 FilePath virtual_path;
376 FilePath absolute_path; 376 FilePath absolute_path;
377 bool is_directory; 377 bool is_directory;
378 }; 378 };
379 379
380 typedef std::vector<FileDefinition> FileDefinitionList; 380 typedef std::vector<FileDefinition> FileDefinitionList;
381 class ExecuteTasksFileSystemCallbackDispatcher; 381 class ExecuteTasksFileSystemCallbackDispatcher;
382 void RequestFileEntryOnFileThread( 382 void RequestFileEntryOnFileThread(
383 scoped_refptr<fileapi::FileSystemContext> file_system_context,
383 const GURL& handler_base_url, 384 const GURL& handler_base_url,
384 const scoped_refptr<const extensions::Extension>& handler, 385 const scoped_refptr<const extensions::Extension>& handler,
385 int handler_pid, 386 int handler_pid,
386 const std::vector<GURL>& file_urls); 387 const std::vector<GURL>& file_urls);
387 388
388 void ExecuteDoneOnUIThread(bool success); 389 void ExecuteDoneOnUIThread(bool success);
389 void ExecuteFileActionsOnUIThread(const std::string& file_system_name, 390 void ExecuteFileActionsOnUIThread(const std::string& file_system_name,
390 const GURL& file_system_root, 391 const GURL& file_system_root,
391 const FileDefinitionList& file_list, 392 const FileDefinitionList& file_list,
392 int handler_pid); 393 int handler_pid);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 ExtensionTaskExecutor::FileDefinition::FileDefinition() : is_directory(false) { 468 ExtensionTaskExecutor::FileDefinition::FileDefinition() : is_directory(false) {
468 } 469 }
469 470
470 ExtensionTaskExecutor::FileDefinition::~FileDefinition() { 471 ExtensionTaskExecutor::FileDefinition::~FileDefinition() {
471 } 472 }
472 473
473 class ExtensionTaskExecutor::ExecuteTasksFileSystemCallbackDispatcher { 474 class ExtensionTaskExecutor::ExecuteTasksFileSystemCallbackDispatcher {
474 public: 475 public:
475 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( 476 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback(
476 ExtensionTaskExecutor* executor, 477 ExtensionTaskExecutor* executor,
477 Profile* profile, 478 scoped_refptr<fileapi::FileSystemContext> file_system_context,
478 const GURL& source_url, 479 const GURL& source_url,
479 scoped_refptr<const Extension> handler_extension, 480 scoped_refptr<const Extension> handler_extension,
480 int handler_pid, 481 int handler_pid,
481 const std::string& action_id, 482 const std::string& action_id,
482 const std::vector<GURL>& file_urls) { 483 const std::vector<GURL>& file_urls) {
483 return base::Bind( 484 return base::Bind(
484 &ExecuteTasksFileSystemCallbackDispatcher::DidOpenFileSystem, 485 &ExecuteTasksFileSystemCallbackDispatcher::DidOpenFileSystem,
485 base::Owned(new ExecuteTasksFileSystemCallbackDispatcher( 486 base::Owned(new ExecuteTasksFileSystemCallbackDispatcher(
486 executor, profile, source_url, handler_extension, 487 executor, file_system_context, source_url, handler_extension,
487 handler_pid, action_id, file_urls))); 488 handler_pid, action_id, file_urls)));
488 } 489 }
489 490
490 void DidOpenFileSystem(base::PlatformFileError result, 491 void DidOpenFileSystem(base::PlatformFileError result,
491 const std::string& file_system_name, 492 const std::string& file_system_name,
492 const GURL& file_system_root) { 493 const GURL& file_system_root) {
493 if (result != base::PLATFORM_FILE_OK) { 494 if (result != base::PLATFORM_FILE_OK) {
494 DidFail(result); 495 DidFail(result);
495 return; 496 return;
496 } 497 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 BrowserThread::UI, FROM_HERE, 533 BrowserThread::UI, FROM_HERE,
533 base::Bind( 534 base::Bind(
534 &ExtensionTaskExecutor::ExecuteDoneOnUIThread, 535 &ExtensionTaskExecutor::ExecuteDoneOnUIThread,
535 executor_, 536 executor_,
536 false)); 537 false));
537 } 538 }
538 539
539 private: 540 private:
540 ExecuteTasksFileSystemCallbackDispatcher( 541 ExecuteTasksFileSystemCallbackDispatcher(
541 ExtensionTaskExecutor* executor, 542 ExtensionTaskExecutor* executor,
542 Profile* profile, 543 scoped_refptr<fileapi::FileSystemContext> file_system_context,
543 const GURL& source_url, 544 const GURL& source_url,
544 const scoped_refptr<const Extension>& handler_extension, 545 const scoped_refptr<const Extension>& handler_extension,
545 int handler_pid, 546 int handler_pid,
546 const std::string& action_id, 547 const std::string& action_id,
547 const std::vector<GURL>& file_urls) 548 const std::vector<GURL>& file_urls)
548 : executor_(executor), 549 : executor_(executor),
549 profile_(profile), 550 file_system_context_(file_system_context),
550 source_url_(source_url), 551 source_url_(source_url),
551 handler_extension_(handler_extension), 552 handler_extension_(handler_extension),
552 handler_pid_(handler_pid), 553 handler_pid_(handler_pid),
553 action_id_(action_id), 554 action_id_(action_id),
554 origin_file_urls_(file_urls) { 555 origin_file_urls_(file_urls) {
555 DCHECK(executor_); 556 DCHECK(executor_);
556 } 557 }
557 558
558 // Checks legitimacy of file url and grants file RO access permissions from 559 // Checks legitimacy of file url and grants file RO access permissions from
559 // handler (target) extension and its renderer process. 560 // handler (target) extension and its renderer process.
(...skipping 10 matching lines...) Expand all
570 fileapi::FileSystemType type; 571 fileapi::FileSystemType type;
571 if (!CrackFileSystemURL(origin_file_url, &file_origin_url, &type, 572 if (!CrackFileSystemURL(origin_file_url, &file_origin_url, &type,
572 &virtual_path)) { 573 &virtual_path)) {
573 return false; 574 return false;
574 } 575 }
575 576
576 if (type != fileapi::kFileSystemTypeExternal) 577 if (type != fileapi::kFileSystemTypeExternal)
577 return false; 578 return false;
578 579
579 fileapi::ExternalFileSystemMountPointProvider* external_provider = 580 fileapi::ExternalFileSystemMountPointProvider* external_provider =
580 BrowserContext::GetFileSystemContext(profile_)->external_provider(); 581 file_system_context_->external_provider();
581 if (!external_provider) 582 if (!external_provider)
582 return false; 583 return false;
583 584
584 if (!external_provider->IsAccessAllowed(file_origin_url, 585 if (!external_provider->IsAccessAllowed(file_origin_url,
585 type, 586 type,
586 virtual_path)) { 587 virtual_path)) {
587 return false; 588 return false;
588 } 589 }
589 590
590 // Make sure this url really being used by the right caller extension. 591 // Make sure this url really being used by the right caller extension.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url, 629 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url,
629 fileapi::kFileSystemTypeExternal); 630 fileapi::kFileSystemTypeExternal);
630 file->target_file_url = GURL(base_url.spec() + virtual_path.value()); 631 file->target_file_url = GURL(base_url.spec() + virtual_path.value());
631 file->virtual_path = virtual_path; 632 file->virtual_path = virtual_path;
632 file->is_directory = file_info.is_directory; 633 file->is_directory = file_info.is_directory;
633 file->absolute_path = final_file_path; 634 file->absolute_path = final_file_path;
634 return true; 635 return true;
635 } 636 }
636 637
637 ExtensionTaskExecutor* executor_; 638 ExtensionTaskExecutor* executor_;
638 Profile* profile_; 639 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
639 // Extension source URL. 640 // Extension source URL.
640 GURL source_url_; 641 GURL source_url_;
641 scoped_refptr<const Extension> handler_extension_; 642 scoped_refptr<const Extension> handler_extension_;
642 int handler_pid_; 643 int handler_pid_;
643 std::string action_id_; 644 std::string action_id_;
644 std::vector<GURL> origin_file_urls_; 645 std::vector<GURL> origin_file_urls_;
645 DISALLOW_COPY_AND_ASSIGN(ExecuteTasksFileSystemCallbackDispatcher); 646 DISALLOW_COPY_AND_ASSIGN(ExecuteTasksFileSystemCallbackDispatcher);
646 }; 647 };
647 648
648 ExtensionTaskExecutor::ExtensionTaskExecutor( 649 ExtensionTaskExecutor::ExtensionTaskExecutor(
(...skipping 24 matching lines...) Expand all
673 674
674 int handler_pid = ExtractProcessFromExtensionId(handler->id(), profile()); 675 int handler_pid = ExtractProcessFromExtensionId(handler->id(), profile());
675 if (handler_pid <= 0) { 676 if (handler_pid <= 0) {
676 if (!handler->has_lazy_background_page()) 677 if (!handler->has_lazy_background_page())
677 return false; 678 return false;
678 } 679 }
679 680
680 done_ = done; 681 done_ = done;
681 682
682 // Get local file system instance on file thread. 683 // Get local file system instance on file thread.
684 scoped_refptr<fileapi::FileSystemContext> file_system_context =
685 BrowserContext::GetFileSystemContext(profile());
683 BrowserThread::PostTask( 686 BrowserThread::PostTask(
684 BrowserThread::FILE, FROM_HERE, 687 BrowserThread::FILE, FROM_HERE,
685 base::Bind( 688 base::Bind(
686 &ExtensionTaskExecutor::RequestFileEntryOnFileThread, 689 &ExtensionTaskExecutor::RequestFileEntryOnFileThread,
687 this, 690 this,
691 file_system_context,
688 Extension::GetBaseURLFromExtensionId(handler->id()), 692 Extension::GetBaseURLFromExtensionId(handler->id()),
689 handler, 693 handler,
690 handler_pid, 694 handler_pid,
691 file_urls)); 695 file_urls));
692 return true; 696 return true;
693 } 697 }
694 698
695 void ExtensionTaskExecutor::RequestFileEntryOnFileThread( 699 void ExtensionTaskExecutor::RequestFileEntryOnFileThread(
700 scoped_refptr<fileapi::FileSystemContext> file_system_context,
696 const GURL& handler_base_url, 701 const GURL& handler_base_url,
697 const scoped_refptr<const Extension>& handler, 702 const scoped_refptr<const Extension>& handler,
698 int handler_pid, 703 int handler_pid,
699 const std::vector<GURL>& file_urls) { 704 const std::vector<GURL>& file_urls) {
700 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 705 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
701 GURL origin_url = handler_base_url.GetOrigin(); 706 GURL origin_url = handler_base_url.GetOrigin();
702 BrowserContext::GetFileSystemContext(profile())->OpenFileSystem( 707 file_system_context->OpenFileSystem(
703 origin_url, fileapi::kFileSystemTypeExternal, false, // create 708 origin_url, fileapi::kFileSystemTypeExternal, false, // create
704 ExecuteTasksFileSystemCallbackDispatcher::CreateCallback( 709 ExecuteTasksFileSystemCallbackDispatcher::CreateCallback(
705 this, 710 this,
706 profile(), 711 file_system_context,
707 source_url_, 712 source_url_,
708 handler, 713 handler,
709 handler_pid, 714 handler_pid,
710 action_id_, 715 action_id_,
711 file_urls)); 716 file_urls));
712 } 717 }
713 718
714 void ExtensionTaskExecutor::ExecuteDoneOnUIThread(bool success) { 719 void ExtensionTaskExecutor::ExecuteDoneOnUIThread(bool success) {
715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 720 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
716 if (!done_.is_null()) 721 if (!done_.is_null())
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 handler_host_permissions_[i].first, 890 handler_host_permissions_[i].first,
886 handler_host_permissions_[i].second); 891 handler_host_permissions_[i].second);
887 } 892 }
888 893
889 // We don't need this anymore. 894 // We don't need this anymore.
890 handler_host_permissions_.clear(); 895 handler_host_permissions_.clear();
891 } 896 }
892 897
893 } // namespace file_handler_util 898 } // namespace file_handler_util
894 899
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_browser_private_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698