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

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: 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_,
tbarzic 2012/06/07 22:47:56 why do you create callback here instead in Execute
hshi1 2012/06/08 00:22:05 Because several parameters (such as file_system_na
tbarzic 2012/06/08 17:59:13 Yeah, but this way it harder to follow what's goin
hshi1 2012/06/08 18:21:41 Done.
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(
552 const std::string& file_system_name,
553 const GURL& file_system_root,
554 const FileDefinitionList& file_list, 556 const FileDefinitionList& file_list,
555 int handler_pid) { 557 const ExecuteFileActionsCallback& callback) {
556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 558 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
557 559
558 ExtensionService* service = profile_->GetExtensionService(); 560 ExtensionService* service = profile_->GetExtensionService();
559 if (!service) { 561 if (!service) {
560 Done(false); 562 Done(false);
561 return; 563 return;
562 } 564 }
563 565
564 const Extension* extension = service->GetExtensionById(extension_id_, false); 566 const Extension* extension = service->GetExtensionById(extension_id_, false);
565 if (!extension) { 567 if (!extension) {
566 Done(false); 568 Done(false);
567 return; 569 return;
568 } 570 }
569 571
570 InitHandlerHostFileAccessPermissions(file_list, extension, action_id_); 572 InitHandlerHostFileAccessPermissions(file_list, extension, action_id_,
573 callback);
574 }
575
576 void FileTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread(
577 const std::string& file_system_name,
578 const GURL& file_system_root,
579 const FileDefinitionList& file_list,
580 int handler_pid,
581 const Extension* extension) {
tbarzic 2012/06/07 22:47:56 what if the extension goes away while we were gett
hshi1 2012/06/08 00:22:05 Done.
582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
571 583
572 if (handler_pid > 0) { 584 if (handler_pid > 0) {
573 SetupPermissionsAndDispatchEvent(file_system_name, file_system_root, 585 SetupPermissionsAndDispatchEvent(file_system_name, file_system_root,
574 file_list, handler_pid, NULL); 586 file_list, handler_pid, NULL);
575 } else { 587 } else {
576 // We have to wake the handler background page before we proceed. 588 // We have to wake the handler background page before we proceed.
577 extensions::LazyBackgroundTaskQueue* queue = 589 extensions::LazyBackgroundTaskQueue* queue =
578 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); 590 ExtensionSystem::Get(profile_)->lazy_background_task_queue();
579 if (!queue->ShouldEnqueueTask(profile_, extension)) { 591 if (!queue->ShouldEnqueueTask(profile_, extension)) {
580 Done(false); 592 Done(false);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 extension_id_, std::string("fileBrowserHandler.onExecute"), 653 extension_id_, std::string("fileBrowserHandler.onExecute"),
642 json_args, profile_, 654 json_args, profile_,
643 GURL()); 655 GURL());
644 656
645 Done(true); 657 Done(true);
646 } 658 }
647 659
648 void FileTaskExecutor::InitHandlerHostFileAccessPermissions( 660 void FileTaskExecutor::InitHandlerHostFileAccessPermissions(
649 const FileDefinitionList& file_list, 661 const FileDefinitionList& file_list,
650 const Extension* handler_extension, 662 const Extension* handler_extension,
651 const std::string& action_id) { 663 const std::string& action_id,
664 const ExecuteFileActionsCallback& callback) {
652 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 665 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
653 666
667 scoped_ptr<std::vector<FilePath> > gdata_paths(new std::vector<FilePath>);
654 for (FileDefinitionList::const_iterator iter = file_list.begin(); 668 for (FileDefinitionList::const_iterator iter = file_list.begin();
655 iter != file_list.end(); 669 iter != file_list.end();
656 ++iter) { 670 ++iter) {
657 // Setup permission for file's absolute file. 671 // Setup permission for file's absolute file.
658 handler_host_permissions_.push_back(std::make_pair( 672 handler_host_permissions_.push_back(std::make_pair(
659 iter->absolute_path, 673 iter->absolute_path,
660 GetAccessPermissionsForHandler(handler_extension, action_id))); 674 GetAccessPermissionsForHandler(handler_extension, action_id)));
661 675
662 if (!gdata::util::IsUnderGDataMountPoint(iter->absolute_path)) 676 if (gdata::util::IsUnderGDataMountPoint(iter->absolute_path))
663 continue; 677 gdata_paths->push_back(iter->absolute_path);
678 }
664 679
665 // If the file is on gdata mount point, we'll have to give handler host 680 // For files on gdata mount point, we'll have to give handler host permissions
666 // permissions for file's gdata cache paths. 681 // for their cache paths. This has to be called on UI thread.
667 // This has to be called on UI thread. 682 gdata::util::InsertGDataCachePathsPermissions(
tbarzic 2012/06/07 22:47:56 We don't really have to go to gdata_util if there
hshi1 2012/06/08 00:22:05 Done.
668 gdata::util::InsertGDataCachePathsPermissions(profile_, iter->absolute_path, 683 profile_,
669 &handler_host_permissions_); 684 gdata_paths.Pass(),
670 } 685 &handler_host_permissions_,
686 base::Bind(callback,
tbarzic 2012/06/07 22:47:56 this fits in a single line
hshi1 2012/06/08 00:22:05 Done.
687 handler_extension));
satorux1 2012/06/07 22:47:17 nit: merge the line to the previous line?
hshi1 2012/06/08 00:22:05 Done.
671 } 688 }
672 689
673 void FileTaskExecutor::SetupHandlerHostFileAccessPermissions(int handler_pid) { 690 void FileTaskExecutor::SetupHandlerHostFileAccessPermissions(int handler_pid) {
674 for (size_t i = 0; i < handler_host_permissions_.size(); i++) { 691 for (size_t i = 0; i < handler_host_permissions_.size(); i++) {
675 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( 692 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
676 handler_pid, 693 handler_pid,
677 handler_host_permissions_[i].first, 694 handler_host_permissions_[i].first,
678 handler_host_permissions_[i].second); 695 handler_host_permissions_[i].second);
679 } 696 }
680 697
681 // We don't need this anymore. 698 // We don't need this anymore.
682 handler_host_permissions_.clear(); 699 handler_host_permissions_.clear();
683 } 700 }
684 701
685 } // namespace file_handler_util 702 } // namespace file_handler_util
686 703
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698