Chromium Code Reviews| Index: chrome/browser/chromeos/file_manager/file_tasks.cc |
| diff --git a/chrome/browser/chromeos/file_manager/file_tasks.cc b/chrome/browser/chromeos/file_manager/file_tasks.cc |
| index b1d4ceea0aa18f9e89bb94cbbc47dc956cf91cc9..856b5536f8f8bfaa422ebbbe58ec3579e93c3aa7 100644 |
| --- a/chrome/browser/chromeos/file_manager/file_tasks.cc |
| +++ b/chrome/browser/chromeos/file_manager/file_tasks.cc |
| @@ -137,18 +137,18 @@ bool IsFallbackFileHandler(const file_tasks::TaskDescriptor& task) { |
| } // namespace |
| -FullTaskDescriptor::FullTaskDescriptor( |
| - const TaskDescriptor& task_descriptor, |
| - const std::string& task_title, |
| - const GURL& icon_url, |
| - bool is_default, |
| - bool is_generic_file_handler) |
| +FullTaskDescriptor::FullTaskDescriptor(const TaskDescriptor& task_descriptor, |
| + const base::string16& task_title, |
| + const GURL& icon_url, |
| + bool is_default, |
| + bool is_generic_file_handler) |
| : task_descriptor_(task_descriptor), |
| task_title_(task_title), |
| icon_url_(icon_url), |
| is_default_(is_default), |
| - is_generic_file_handler_(is_generic_file_handler) { |
| -} |
| + is_generic_file_handler_(is_generic_file_handler) {} |
| + |
| +FullTaskDescriptor::~FullTaskDescriptor() {} |
| void UpdateDefaultTask(PrefService* pref_service, |
| const std::string& task_id, |
| @@ -359,12 +359,12 @@ void FindDriveAppTasks(const drive::DriveAppRegistry& drive_app_registry, |
| GURL icon_url = drive::util::FindPreferredIcon( |
| app_info.app_icons, |
| drive::util::kPreferredIconSize); |
| - result_list->push_back( |
| - FullTaskDescriptor(descriptor, |
| - app_info.app_name, |
| - icon_url, |
| - false /* is_default */, |
| - false /* is_generic_file_handler */)); |
| + |
| + result_list->push_back(FullTaskDescriptor( |
| + descriptor, |
| + extensions::file_handler_verbs::GetTitleForExtensionAndVerb( |
| + app_info.app_name, extensions::file_handler_verbs::kOpenWith), |
| + icon_url, false /* is_default */, false /* is_generic_file_handler */)); |
| } |
| } |
| @@ -431,35 +431,47 @@ void FindFileHandlerTasks(Profile* profile, |
| continue; |
| } |
| - // Show the first good matching handler of each app. If there doesn't exist |
| - // such handler, show the first matching handler of the app. |
| - const extensions::FileHandlerInfo* file_handler = file_handlers.front(); |
| - for (auto handler : file_handlers) { |
| - if (IsGoodMatchFileHandler(*handler, entries)) { |
| - file_handler = handler; |
| - break; |
| + // A map which has as key a handler verb, and as value a pair of the |
| + // handler with which to open the given entries and a boolean marking |
| + // if the handler is a good match. |
| + std::map<std::string, std::pair<const extensions::FileHandlerInfo*, bool>> |
| + handlers_for_entries; |
| + // Show the first good matching handler of each verb supporting the given |
| + // entries that corresponds to the app. If there doesn't exist such handler, |
| + // show the first matching handler of the verb. |
| + for (const auto handler : file_handlers) { |
| + bool good_match = IsGoodMatchFileHandler(*handler, entries); |
| + auto it = handlers_for_entries.find(handler->verb); |
| + if (it == handlers_for_entries.end() || |
| + (!it->second.second /* existing handler not a good match */ && |
| + good_match)) { |
| + handlers_for_entries[handler->verb] = |
| + std::make_pair(handler, good_match); |
| } |
| } |
| - std::string task_id = file_tasks::MakeTaskID( |
| - extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id); |
| - |
| - GURL best_icon = extensions::ExtensionIconSource::GetIconURL( |
| - extension, |
| - drive::util::kPreferredIconSize, |
| - ExtensionIconSet::MATCH_BIGGER, |
| - false, // grayscale |
| - NULL); // exists |
| - |
| - // If file handler doesn't match as good match, regards it as generic file |
| - // handler. |
| - const bool is_generic_file_handler = |
| - !IsGoodMatchFileHandler(*file_handler, entries); |
| - result_list->push_back(FullTaskDescriptor( |
| - TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, |
| - file_handler->id), |
| - extension->name(), best_icon, false /* is_default */, |
| - is_generic_file_handler)); |
| + for (const auto entry : handlers_for_entries) { |
| + const extensions::FileHandlerInfo* handler = entry.second.first; |
| + std::string task_id = file_tasks::MakeTaskID( |
| + extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, handler->id); |
| + |
| + GURL best_icon = extensions::ExtensionIconSource::GetIconURL( |
| + extension, drive::util::kPreferredIconSize, |
| + ExtensionIconSet::MATCH_BIGGER, |
| + false, // grayscale |
| + NULL); // exists |
| + |
| + // If file handler doesn't match as good match, regards it as generic file |
| + // handler. |
| + const bool is_generic_file_handler = |
| + !IsGoodMatchFileHandler(*handler, entries); |
| + result_list->push_back(FullTaskDescriptor( |
| + TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, |
| + handler->id), |
| + extensions::file_handler_verbs::GetTitleForExtensionAndVerb( |
| + extension->name(), handler->verb), |
| + best_icon, false /* is_default */, is_generic_file_handler)); |
| + } |
| } |
| } |
| @@ -496,13 +508,12 @@ void FindFileBrowserHandlerTasks( |
| NULL); // exists |
| result_list->push_back(FullTaskDescriptor( |
| - TaskDescriptor(extension_id, |
| - file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, |
| + TaskDescriptor(extension_id, file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, |
| handler->id()), |
| - handler->title(), |
| - icon_url, |
| - false /* is_default */, |
| - false /* is_generic_file_handler */)); |
| + // TODO(cmihail): Should we support verbs also for FileBrowserHandler? |
|
fukino
2016/04/11 09:19:43
I think FileBrowserHandler already has the similar
cmihail
2016/04/13 07:36:46
Acknowledged.
|
| + extensions::file_handler_verbs::GetTitleForExtensionAndVerb( |
| + handler->title(), extensions::file_handler_verbs::kOpenWith), |
|
fukino
2016/04/11 09:19:43
We should not assume "Open with..." for FileBrowse
|
| + icon_url, false /* is_default */, false /* is_generic_file_handler */)); |
| } |
| } |