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

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

Issue 10543037: gdata: Convert public synchronous functions in GDataFileSystem to asynchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Satoru's and Toni's concerns. Created 8 years, 6 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/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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 &FileTaskExecutor::ExecuteFailedOnUIThread, 352 &FileTaskExecutor::ExecuteFailedOnUIThread,
353 executor_)); 353 executor_));
354 return; 354 return;
355 } 355 }
356 356
357 BrowserThread::PostTask( 357 BrowserThread::PostTask(
358 BrowserThread::UI, FROM_HERE, 358 BrowserThread::UI, FROM_HERE,
359 base::Bind( 359 base::Bind(
360 &FileTaskExecutor::ExecuteFileActionsOnUIThread, 360 &FileTaskExecutor::ExecuteFileActionsOnUIThread,
361 executor_, 361 executor_,
362 file_system_name,
363 file_system_root,
364 file_list, 362 file_list,
365 handler_pid_)); 363 base::Bind(
364 &FileTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread,
365 executor_,
366 file_system_name,
367 file_system_root,
368 file_list,
369 handler_pid_)));
366 } 370 }
367 371
368 void DidFail(base::PlatformFileError error_code) { 372 void DidFail(base::PlatformFileError error_code) {
369 BrowserThread::PostTask( 373 BrowserThread::PostTask(
370 BrowserThread::UI, FROM_HERE, 374 BrowserThread::UI, FROM_HERE,
371 base::Bind( 375 base::Bind(
372 &FileTaskExecutor::ExecuteFailedOnUIThread, 376 &FileTaskExecutor::ExecuteFailedOnUIThread,
373 executor_)); 377 executor_));
374 } 378 }
375 379
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 handler_pid, 546 handler_pid,
543 action_id_, 547 action_id_,
544 file_urls)); 548 file_urls));
545 } 549 }
546 550
547 void FileTaskExecutor::ExecuteFailedOnUIThread() { 551 void FileTaskExecutor::ExecuteFailedOnUIThread() {
548 Done(false); 552 Done(false);
549 } 553 }
550 554
551 void FileTaskExecutor::ExecuteFileActionsOnUIThread( 555 void FileTaskExecutor::ExecuteFileActionsOnUIThread(
556 const FileDefinitionList& file_list,
557 const base::Closure& callback) {
558 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
559
560 ExtensionService* service = profile_->GetExtensionService();
561 if (!service) {
562 Done(false);
tbarzic 2012/06/08 17:59:13 this can be extracted to a separate function..
hshi1 2012/06/08 18:21:41 Done.
563 return;
564 }
565
566 const Extension* extension = service->GetExtensionById(extension_id_, false);
567 if (!extension) {
568 Done(false);
569 return;
570 }
571
572 InitHandlerHostFileAccessPermissions(file_list, extension, action_id_,
573 callback);
574 }
575
576 void FileTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread(
552 const std::string& file_system_name, 577 const std::string& file_system_name,
553 const GURL& file_system_root, 578 const GURL& file_system_root,
554 const FileDefinitionList& file_list, 579 const FileDefinitionList& file_list,
555 int handler_pid) { 580 int handler_pid) {
556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
557 582
558 ExtensionService* service = profile_->GetExtensionService(); 583 ExtensionService* service = profile_->GetExtensionService();
559 if (!service) { 584 if (!service) {
560 Done(false); 585 Done(false);
561 return; 586 return;
562 } 587 }
563 588
564 const Extension* extension = service->GetExtensionById(extension_id_, false); 589 const Extension* extension = service->GetExtensionById(extension_id_, false);
565 if (!extension) { 590 if (!extension) {
566 Done(false); 591 Done(false);
567 return; 592 return;
568 } 593 }
569 594
570 InitHandlerHostFileAccessPermissions(file_list, extension, action_id_);
571
572 if (handler_pid > 0) { 595 if (handler_pid > 0) {
573 SetupPermissionsAndDispatchEvent(file_system_name, file_system_root, 596 SetupPermissionsAndDispatchEvent(file_system_name, file_system_root,
574 file_list, handler_pid, NULL); 597 file_list, handler_pid, NULL);
575 } else { 598 } else {
576 // We have to wake the handler background page before we proceed. 599 // We have to wake the handler background page before we proceed.
577 extensions::LazyBackgroundTaskQueue* queue = 600 extensions::LazyBackgroundTaskQueue* queue =
578 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); 601 ExtensionSystem::Get(profile_)->lazy_background_task_queue();
579 if (!queue->ShouldEnqueueTask(profile_, extension)) { 602 if (!queue->ShouldEnqueueTask(profile_, extension)) {
580 Done(false); 603 Done(false);
581 return; 604 return;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 extension_id_, std::string("fileBrowserHandler.onExecute"), 664 extension_id_, std::string("fileBrowserHandler.onExecute"),
642 json_args, profile_, 665 json_args, profile_,
643 GURL()); 666 GURL());
644 667
645 Done(true); 668 Done(true);
646 } 669 }
647 670
648 void FileTaskExecutor::InitHandlerHostFileAccessPermissions( 671 void FileTaskExecutor::InitHandlerHostFileAccessPermissions(
649 const FileDefinitionList& file_list, 672 const FileDefinitionList& file_list,
650 const Extension* handler_extension, 673 const Extension* handler_extension,
651 const std::string& action_id) { 674 const std::string& action_id,
675 const base::Closure& callback) {
652 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 676 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
653 677
678 scoped_ptr<std::vector<FilePath> > gdata_paths(new std::vector<FilePath>);
654 for (FileDefinitionList::const_iterator iter = file_list.begin(); 679 for (FileDefinitionList::const_iterator iter = file_list.begin();
655 iter != file_list.end(); 680 iter != file_list.end();
656 ++iter) { 681 ++iter) {
657 // Setup permission for file's absolute file. 682 // Setup permission for file's absolute file.
658 handler_host_permissions_.push_back(std::make_pair( 683 handler_host_permissions_.push_back(std::make_pair(
659 iter->absolute_path, 684 iter->absolute_path,
660 GetAccessPermissionsForHandler(handler_extension, action_id))); 685 GetAccessPermissionsForHandler(handler_extension, action_id)));
661 686
662 if (!gdata::util::IsUnderGDataMountPoint(iter->absolute_path)) 687 if (gdata::util::IsUnderGDataMountPoint(iter->absolute_path))
663 continue; 688 gdata_paths->push_back(iter->absolute_path);
689 }
664 690
665 // If the file is on gdata mount point, we'll have to give handler host 691 if (gdata_paths->empty()) {
666 // permissions for file's gdata cache paths. 692 // Invoke callback if none of the files are on gdata mount point.
667 // This has to be called on UI thread. 693 callback.Run();
668 gdata::util::InsertGDataCachePathsPermissions(profile_, iter->absolute_path, 694 return;
669 &handler_host_permissions_);
670 } 695 }
696
697 // For files on gdata mount point, we'll have to give handler host permissions
698 // for their cache paths. This has to be called on UI thread.
699 gdata::util::InsertGDataCachePathsPermissions(profile_,
700 gdata_paths.Pass(),
701 &handler_host_permissions_,
702 callback);
671 } 703 }
672 704
673 void FileTaskExecutor::SetupHandlerHostFileAccessPermissions(int handler_pid) { 705 void FileTaskExecutor::SetupHandlerHostFileAccessPermissions(int handler_pid) {
674 for (size_t i = 0; i < handler_host_permissions_.size(); i++) { 706 for (size_t i = 0; i < handler_host_permissions_.size(); i++) {
675 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( 707 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
676 handler_pid, 708 handler_pid,
677 handler_host_permissions_[i].first, 709 handler_host_permissions_[i].first,
678 handler_host_permissions_[i].second); 710 handler_host_permissions_[i].second);
679 } 711 }
680 712
681 // We don't need this anymore. 713 // We don't need this anymore.
682 handler_host_permissions_.clear(); 714 handler_host_permissions_.clear();
683 } 715 }
684 716
685 } // namespace file_handler_util 717 } // namespace file_handler_util
686 718
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698