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..a7072e7f90aed49f7135e4d46dcf642a9570b2a1 100644 |
| --- a/chrome/browser/chromeos/file_manager/file_tasks.cc |
| +++ b/chrome/browser/chromeos/file_manager/file_tasks.cc |
| @@ -137,18 +137,20 @@ 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 std::string& task_title, |
| + const std::string& task_verb, |
| + const GURL& icon_url, |
| + bool is_default, |
| + bool is_generic_file_handler) |
| : task_descriptor_(task_descriptor), |
| task_title_(task_title), |
| + task_verb_(task_verb), |
| 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() {} |
|
fukino
2016/04/18 08:06:05
Looks unnecessary :)
cmihail
2016/04/21 09:36:43
See header comment.
|
| void UpdateDefaultTask(PrefService* pref_service, |
| const std::string& task_id, |
| @@ -359,12 +361,11 @@ 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, app_info.app_name, |
| + extensions::file_handler_verbs::kOpenWith, icon_url, |
| + false /* is_default */, false /* is_generic_file_handler */)); |
| } |
| } |
| @@ -431,35 +432,46 @@ 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), |
| + extension->name(), handler->verb, best_icon, false /* is_default */, |
| + is_generic_file_handler)); |
| + } |
| } |
| } |
| @@ -496,13 +508,10 @@ 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 */)); |
| + handler->title(), "" /* no verb for FileBrowserHandler */, icon_url, |
| + false /* is_default */, false /* is_generic_file_handler */)); |
| } |
| } |