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

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

Issue 23455020: file_manager: IsFallbackFileBrowserHandler() to take TaskDescriptor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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_manager/file_browser_handlers. h" 5 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_handlers. 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/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 if (ShouldBeOpenedWithBrowser(extension->id(), action_id)) { 519 if (ShouldBeOpenedWithBrowser(extension->id(), action_id)) {
520 return OpenFilesWithBrowser(profile, file_urls); 520 return OpenFilesWithBrowser(profile, file_urls);
521 } 521 }
522 522
523 // The executor object will be self deleted on completion. 523 // The executor object will be self deleted on completion.
524 (new FileBrowserHandlerExecutor( 524 (new FileBrowserHandlerExecutor(
525 profile, extension, tab_id, action_id))->Execute(file_urls, done); 525 profile, extension, tab_id, action_id))->Execute(file_urls, done);
526 return true; 526 return true;
527 } 527 }
528 528
529 bool IsFallbackFileBrowserHandler(const FileBrowserHandler* handler) { 529 bool IsFallbackFileBrowserHandler(const file_tasks::TaskDescriptor& task) {
530 const std::string& extension_id = handler->extension_id(); 530 return (task.task_type == file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER &&
531 return (extension_id == kFileManagerAppId || 531 (task.app_id == kFileManagerAppId ||
532 extension_id == extension_misc::kQuickOfficeComponentExtensionId || 532 task.app_id == extension_misc::kQuickOfficeComponentExtensionId ||
533 extension_id == extension_misc::kQuickOfficeDevExtensionId || 533 task.app_id == extension_misc::kQuickOfficeDevExtensionId ||
534 extension_id == extension_misc::kQuickOfficeExtensionId); 534 task.app_id == extension_misc::kQuickOfficeExtensionId));
535 } 535 }
536 536
537 FileBrowserHandlerList FindDefaultFileBrowserHandlers( 537 FileBrowserHandlerList FindDefaultFileBrowserHandlers(
538 const PrefService& pref_service, 538 const PrefService& pref_service,
539 const std::vector<base::FilePath>& file_list, 539 const std::vector<base::FilePath>& file_list,
540 const FileBrowserHandlerList& common_handlers) { 540 const FileBrowserHandlerList& common_handlers) {
541 FileBrowserHandlerList default_handlers; 541 FileBrowserHandlerList default_handlers;
542 542
543 std::set<std::string> default_ids; 543 std::set<std::string> default_ids;
544 for (std::vector<base::FilePath>::const_iterator it = file_list.begin(); 544 for (std::vector<base::FilePath>::const_iterator it = file_list.begin();
545 it != file_list.end(); ++it) { 545 it != file_list.end(); ++it) {
546 std::string task_id = file_tasks::GetDefaultTaskIdFromPrefs( 546 std::string task_id = file_tasks::GetDefaultTaskIdFromPrefs(
547 pref_service, "", it->Extension()); 547 pref_service, "", it->Extension());
548 if (!task_id.empty()) 548 if (!task_id.empty())
549 default_ids.insert(task_id); 549 default_ids.insert(task_id);
550 } 550 }
551 551
552 const FileBrowserHandler* fallback_handler = NULL; 552 const FileBrowserHandler* fallback_handler = NULL;
553 // Convert the default task IDs collected above to one of the handler pointers 553 // Convert the default task IDs collected above to one of the handler pointers
554 // from common_handlers. 554 // from common_handlers.
555 for (size_t i = 0; i < common_handlers.size(); ++i) { 555 for (size_t i = 0; i < common_handlers.size(); ++i) {
556 const FileBrowserHandler* handler = common_handlers[i]; 556 const FileBrowserHandler* handler = common_handlers[i];
557 std::string task_id = file_tasks::MakeTaskID( 557 const file_tasks::TaskDescriptor task_descriptor(
558 handler->extension_id(), 558 handler->extension_id(),
559 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, 559 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER,
560 handler->id()); 560 handler->id());
561 const std::string task_id =
562 file_tasks::TaskDescriptorToId(task_descriptor);
561 std::set<std::string>::iterator default_iter = default_ids.find(task_id); 563 std::set<std::string>::iterator default_iter = default_ids.find(task_id);
562 if (default_iter != default_ids.end()) { 564 if (default_iter != default_ids.end()) {
563 default_handlers.push_back(handler); 565 default_handlers.push_back(handler);
564 continue; 566 continue;
565 } 567 }
566 568
567 // Remember the first fallback handler. 569 // Remember the first fallback handler.
568 if (!fallback_handler && IsFallbackFileBrowserHandler(handler)) 570 if (!fallback_handler && IsFallbackFileBrowserHandler(task_descriptor))
569 fallback_handler = handler; 571 fallback_handler = handler;
570 } 572 }
571 573
572 // If there are no default handlers found, use fallback as default. 574 // If there are no default handlers found, use fallback as default.
573 if (fallback_handler && default_handlers.empty()) 575 if (fallback_handler && default_handlers.empty())
574 default_handlers.push_back(fallback_handler); 576 default_handlers.push_back(fallback_handler);
575 577
576 return default_handlers; 578 return default_handlers;
577 } 579 }
578 580
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 } 658 }
657 659
658 // If there are no default handlers, use first handler in the list (file 660 // If there are no default handlers, use first handler in the list (file
659 // manager does the same in this situation). TODO(tbarzic): This is not so 661 // manager does the same in this situation). TODO(tbarzic): This is not so
660 // optimal behaviour. 662 // optimal behaviour.
661 return *common_handlers.begin(); 663 return *common_handlers.begin();
662 } 664 }
663 665
664 } // namespace file_browser_handlers 666 } // namespace file_browser_handlers
665 } // namespace file_manager 667 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698