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

Unified Diff: chrome/browser/chromeos/file_manager/file_tasks.cc

Issue 1872223002: Add verbs API to file handlers. Modify the Chrome OS UI so that it displayes the internationalized … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments mentioned by fukino@. Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
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..8bbb87f28d3d25815d2a587a9751099ee8338455 100644
--- a/chrome/browser/chromeos/file_manager/file_tasks.cc
+++ b/chrome/browser/chromeos/file_manager/file_tasks.cc
@@ -137,18 +137,16 @@ 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) {}
void UpdateDefaultTask(PrefService* pref_service,
const std::string& task_id,
@@ -359,12 +357,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 +429,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,12 +506,9 @@ 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 */,
+ handler->title(), icon_url, false /* is_default */,
false /* is_generic_file_handler */));
}
}

Powered by Google App Engine
This is Rietveld 408576698