diff options
author | mtomasz@chromium.org <mtomasz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-11 05:59:42 +0000 |
---|---|---|
committer | mtomasz@chromium.org <mtomasz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-11 05:59:42 +0000 |
commit | fa4b4397810462f4e12760991b8187bb1e08778b (patch) | |
tree | f5c3da34d5ec8a15b7b5346ccfd1015c5e666811 | |
parent | bc480c0af6dfa5183306efe228b9ccca15a42f76 (diff) | |
download | chromium_src-fa4b4397810462f4e12760991b8187bb1e08778b.zip chromium_src-fa4b4397810462f4e12760991b8187bb1e08778b.tar.gz chromium_src-fa4b4397810462f4e12760991b8187bb1e08778b.tar.bz2 |
Revert 205380 "Merge 202384 "Replace sets with vectors when stor..."
> Merge 202384 "Replace sets with vectors when storing file handlers."
>
> > Replace sets with vectors when storing file handlers.
> >
> > This caused undeterministic behavior in setting the default task, especially on ASAN bots. Moreover, it sounds reasonable to use order of handlers as priorities.
> >
> > TEST=browser_tests on Linux ChromeOS ASAN pass.
> > BUG=243611, 242615
> >
> > Review URL: https://chromiumcodereview.appspot.com/15975004
>
> TBR=mtomasz@chromium.org
>
> Review URL: https://codereview.chromium.org/16024012
TBR=mtomasz@chromium.org
Review URL: https://codereview.chromium.org/15703016
git-svn-id: svn://svn.chromium.org/chrome/branches/1500/src@205425 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 123 insertions, 98 deletions
diff --git a/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc b/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc index 509c120..9a0175d 100644 --- a/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc +++ b/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc @@ -1017,8 +1017,8 @@ bool GetFileTasksFileBrowserFunction::RunImpl() { // the extension tasks to the Drive task list. We know there aren't duplicates // because they're entirely different kinds of tasks, but there could be both // kinds of tasks for a file type (an image file, for instance). - file_handler_util::FileBrowserHandlerList common_tasks; - file_handler_util::FileBrowserHandlerList default_tasks; + std::set<const FileBrowserHandler*> common_tasks; + std::set<const FileBrowserHandler*> default_tasks; if (!file_handler_util::FindCommonTasks(profile_, file_urls, &common_tasks)) return false; file_handler_util::FindDefaultTasks(profile_, file_paths, @@ -1026,7 +1026,7 @@ bool GetFileTasksFileBrowserFunction::RunImpl() { ExtensionService* service = extensions::ExtensionSystem::Get(profile_)->extension_service(); - for (file_handler_util::FileBrowserHandlerList::const_iterator iter = + for (std::set<const FileBrowserHandler*>::const_iterator iter = common_tasks.begin(); iter != common_tasks.end(); ++iter) { @@ -1050,8 +1050,7 @@ bool GetFileTasksFileBrowserFunction::RunImpl() { // Only set the default if there isn't already a default set. if (!default_already_set && - std::find(default_tasks.begin(), default_tasks.end(), *iter) != - default_tasks.end()) { + default_tasks.find(*iter) != default_tasks.end()) { task->SetBoolean("isDefault", true); default_already_set = true; } else { diff --git a/chrome/browser/chromeos/extensions/file_manager/file_handler_util.cc b/chrome/browser/chromeos/extensions/file_manager/file_handler_util.cc index f83f918..b4d4121 100644 --- a/chrome/browser/chromeos/extensions/file_manager/file_handler_util.cc +++ b/chrome/browser/chromeos/extensions/file_manager/file_handler_util.cc @@ -65,6 +65,8 @@ const char kDriveTaskExtensionPrefix[] = "drive-app:"; const size_t kDriveTaskExtensionPrefixLength = arraysize(kDriveTaskExtensionPrefix) - 1; +typedef std::set<const FileBrowserHandler*> FileBrowserHandlerSet; + const int kReadWriteFilePermissions = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | @@ -100,9 +102,7 @@ int ExtractProcessFromExtensionId(Profile* profile, return process->GetID(); } -// Returns true if the task should be used as a fallback. Such tasks are -// Files.app's internal handlers as well as quick office extensions. -bool IsFallbackTask(const FileBrowserHandler* task) { +bool IsBuiltinTask(const FileBrowserHandler* task) { return (task->extension_id() == kFileBrowserExtensionId || task->extension_id() == extension_misc::kQuickOfficeComponentExtensionId || @@ -110,6 +110,18 @@ bool IsFallbackTask(const FileBrowserHandler* task) { task->extension_id() == extension_misc::kQuickOfficeExtensionId); } +bool MatchesAllURLs(const FileBrowserHandler* handler) { + const std::set<URLPattern>& patterns = + handler->file_url_patterns().patterns(); + for (std::set<URLPattern>::const_iterator it = patterns.begin(); + it != patterns.end(); + ++it) { + if (it->match_all_urls()) + return true; + } + return false; +} + const FileBrowserHandler* FindFileBrowserHandler(const Extension* extension, const std::string& action_id) { FileBrowserHandler::List* handler_list = @@ -150,7 +162,7 @@ std::string EscapedUtf8ToLower(const std::string& str) { bool GetFileBrowserHandlers(Profile* profile, const GURL& selected_file_url, - FileBrowserHandlerList* results) { + FileBrowserHandlerSet* results) { ExtensionService* service = extensions::ExtensionSystem::Get(profile)->extension_service(); if (!service) @@ -180,7 +192,7 @@ bool GetFileBrowserHandlers(Profile* profile, if (!action->MatchesURL(lowercase_url)) continue; - results->push_back(action_iter->get()); + results->insert(action_iter->get()); } } return true; @@ -320,15 +332,15 @@ bool CrackTaskID(const std::string& task_id, } // Find a specific handler in the handler list. -FileBrowserHandlerList::iterator FindHandler( - FileBrowserHandlerList* handler_list, +FileBrowserHandlerSet::iterator FindHandler( + FileBrowserHandlerSet* handler_set, const std::string& extension_id, const std::string& id) { - FileBrowserHandlerList::iterator iter = handler_list->begin(); - while (iter != handler_list->end() && + FileBrowserHandlerSet::iterator iter = handler_set->begin(); + while (iter != handler_set->end() && !((*iter)->extension_id() == extension_id && (*iter)->id() == id)) { - ++iter; + iter++; } return iter; } @@ -337,8 +349,8 @@ FileBrowserHandlerList::iterator FindHandler( // that are shared between them. void FindDefaultTasks(Profile* profile, const std::vector<base::FilePath>& files_list, - const FileBrowserHandlerList& common_tasks, - FileBrowserHandlerList* default_tasks) { + const FileBrowserHandlerSet& common_tasks, + FileBrowserHandlerSet* default_tasks) { DCHECK(default_tasks); default_tasks->clear(); @@ -351,42 +363,46 @@ void FindDefaultTasks(Profile* profile, default_ids.insert(task_id); } - const FileBrowserHandler* fallback_task = NULL; + const FileBrowserHandler* builtin_task = NULL; // Convert the default task IDs collected above to one of the handler pointers // from common_tasks. - for (FileBrowserHandlerList::const_iterator task_iter = common_tasks.begin(); + for (FileBrowserHandlerSet::const_iterator task_iter = common_tasks.begin(); task_iter != common_tasks.end(); ++task_iter) { std::string task_id = MakeTaskID((*task_iter)->extension_id(), kTaskFile, (*task_iter)->id()); std::set<std::string>::iterator default_iter = default_ids.find(task_id); if (default_iter != default_ids.end()) { - default_tasks->push_back(*task_iter); + default_tasks->insert(*task_iter); continue; } - // Remember the first fallback task. - if (!fallback_task && IsFallbackTask(*task_iter)) - fallback_task = *task_iter; + // If it's a built in task, remember it. If there are no default tasks among + // common tasks, builtin task will be used as a fallback. + // Note that builtin tasks are not overlapping, so there can be at most one + // builtin tasks for each set of files. + if (IsBuiltinTask(*task_iter)) + builtin_task = *task_iter; } - // If there are no default tasks found, use fallback as default. - if (fallback_task && default_tasks->empty()) - default_tasks->push_back(fallback_task); + // If there are no default tasks found, use builtin task (if found) as a + // default. + if (builtin_task && default_tasks->empty()) + default_tasks->insert(builtin_task); } // Given the list of selected files, returns array of context menu tasks // that are shared bool FindCommonTasks(Profile* profile, const std::vector<GURL>& files_list, - FileBrowserHandlerList* common_tasks) { + FileBrowserHandlerSet* common_tasks) { DCHECK(common_tasks); common_tasks->clear(); - FileBrowserHandlerList common_task_list; + FileBrowserHandlerSet common_task_set; std::set<std::string> default_task_ids; for (std::vector<GURL>::const_iterator it = files_list.begin(); it != files_list.end(); ++it) { - FileBrowserHandlerList file_actions; + FileBrowserHandlerSet file_actions; if (!GetFileBrowserHandlers(profile, *it, &file_actions)) return false; // If there is nothing to do for one file, the intersection of tasks for all @@ -396,37 +412,38 @@ bool FindCommonTasks(Profile* profile, // For the very first file, just copy all the elements. if (it == files_list.begin()) { - common_task_list = file_actions; + common_task_set = file_actions; } else { // For all additional files, find intersection between the accumulated and // file specific set. - FileBrowserHandlerList intersection; - std::set_intersection(common_task_list.begin(), common_task_list.end(), + FileBrowserHandlerSet intersection; + std::set_intersection(common_task_set.begin(), common_task_set.end(), file_actions.begin(), file_actions.end(), - std::back_inserter(intersection)); - common_task_list = intersection; - if (common_task_list.empty()) + std::inserter(intersection, + intersection.begin())); + common_task_set = intersection; + if (common_task_set.empty()) return true; } } - FileBrowserHandlerList::iterator watch_iter = FindHandler( - &common_task_list, kFileBrowserDomain, kFileBrowserWatchTaskId); - FileBrowserHandlerList::iterator gallery_iter = FindHandler( - &common_task_list, kFileBrowserDomain, kFileBrowserGalleryTaskId); - if (watch_iter != common_task_list.end() && - gallery_iter != common_task_list.end()) { + FileBrowserHandlerSet::iterator watch_iter = FindHandler( + &common_task_set, kFileBrowserDomain, kFileBrowserWatchTaskId); + FileBrowserHandlerSet::iterator gallery_iter = FindHandler( + &common_task_set, kFileBrowserDomain, kFileBrowserGalleryTaskId); + if (watch_iter != common_task_set.end() && + gallery_iter != common_task_set.end()) { // Both "watch" and "gallery" actions are applicable which means that the // selection is all videos. Showing them both is confusing, so we only keep // the one that makes more sense ("watch" for single selection, "gallery" // for multiple selection). if (files_list.size() == 1) - common_task_list.erase(gallery_iter); + common_task_set.erase(gallery_iter); else - common_task_list.erase(watch_iter); + common_task_set.erase(watch_iter); } - common_tasks->swap(common_task_list); + common_tasks->swap(common_task_set); return true; } @@ -437,8 +454,8 @@ bool GetTaskForURLAndPath(Profile* profile, std::vector<GURL> file_urls; file_urls.push_back(url); - FileBrowserHandlerList default_tasks; - FileBrowserHandlerList common_tasks; + FileBrowserHandlerSet default_tasks; + FileBrowserHandlerSet common_tasks; if (!FindCommonTasks(profile, file_urls, &common_tasks)) return false; diff --git a/chrome/browser/chromeos/extensions/file_manager/file_handler_util.h b/chrome/browser/chromeos/extensions/file_manager/file_handler_util.h index beb0a3f..dbab083 100644 --- a/chrome/browser/chromeos/extensions/file_manager/file_handler_util.h +++ b/chrome/browser/chromeos/extensions/file_manager/file_handler_util.h @@ -28,9 +28,6 @@ class FileSystemURL; namespace file_handler_util { -// Tasks are stored as a vector in order of priorities. -typedef std::vector<const FileBrowserHandler*> FileBrowserHandlerList; - // Specifies the task type for a task id that represents some file action, Drive // action, or Web Intent action. extern const char kTaskFile[]; @@ -77,13 +74,13 @@ bool CrackTaskID(const std::string& task_id, // prefs) from the |common_tasks|. void FindDefaultTasks(Profile* profile, const std::vector<base::FilePath>& files_list, - const FileBrowserHandlerList& common_tasks, - FileBrowserHandlerList* default_tasks); + const std::set<const FileBrowserHandler*>& common_tasks, + std::set<const FileBrowserHandler*>* default_tasks); // This generates list of tasks common for all files in |file_list|. bool FindCommonTasks(Profile* profile, const std::vector<GURL>& files_list, - FileBrowserHandlerList* common_tasks); + std::set<const FileBrowserHandler*>* common_tasks); // Finds a task for a file whose URL is |url| and whose path is |path|. // Returns default task if one is defined (The default task is the task that is diff --git a/chrome/browser/resources/file_manager/manifest.json b/chrome/browser/resources/file_manager/manifest.json index 190a9d1..49bde4f 100644 --- a/chrome/browser/resources/file_manager/manifest.json +++ b/chrome/browser/resources/file_manager/manifest.json @@ -31,6 +31,35 @@ "https://drive.google.com/" ], "file_browser_handlers": [ + // Automatically opens a volume and later close Files.app when unmounted. + // TODO(mtomasz): Implement a better filtering than using file_filters. + { + "id": "auto-open", + "default_title": "__MSG_OPEN_ACTION__", + "default_icon": "images/filetype_generic.png", + "file_filters": [ + "filesystem:*" + ] + }, + // Selects the passed file after launching Files.app. + { + "id": "select", + "default_title": "__MSG_OPEN_ACTION__", + "default_icon": "images/filetype_generic.png", + "file_filters": [ + "filesystem:*" + ] + }, + // Opens the passed directory after launching Files.app. + // TODO(mtomasz): Implement a directories filtering instead of files. + { + "id": "open", + "default_title": "__MSG_OPEN_ACTION__", + "default_icon": "images/filetype_generic.png", + "file_filters": [ + "filesystem:*" + ] + }, { "id": "play", "default_title": "__MSG_PLAY_MEDIA__", @@ -178,29 +207,6 @@ "file_filters": [ "filesystem:*.gslides" ] - }, - // The following handlers are used only internally, therefore they do not - // have any file filter. - // Automatically opens a volume and later close Files.app when unmounted. - { - "id": "auto-open", - "default_title": "__MSG_OPEN_ACTION__", - "default_icon": "images/filetype_generic.png", - "file_filters": [] - }, - // Selects the passed file after launching Files.app. - { - "id": "select", - "default_title": "__MSG_OPEN_ACTION__", - "default_icon": "images/filetype_generic.png", - "file_filters": [] - }, - // Opens the passed directory after launching Files.app. - { - "id": "open", - "default_title": "__MSG_OPEN_ACTION__", - "default_icon": "images/filetype_generic.png", - "file_filters": [] } ], "chrome_url_overrides": { diff --git a/chrome/browser/resources/file_manager/manifest_new_ui.json b/chrome/browser/resources/file_manager/manifest_new_ui.json index e86db3e..cc306eb 100644 --- a/chrome/browser/resources/file_manager/manifest_new_ui.json +++ b/chrome/browser/resources/file_manager/manifest_new_ui.json @@ -32,6 +32,35 @@ "https://drive.google.com/" ], "file_browser_handlers": [ + // Automatically opens a volume and later close Files.app when unmounted. + // TODO(mtomasz): Implement a better filtering than using file_filters. + { + "id": "auto-open", + "default_title": "__MSG_OPEN_ACTION__", + "default_icon": "images/filetype_generic.png", + "file_filters": [ + "filesystem:*" + ] + }, + // Selects the passed file after launching Files.app. + { + "id": "select", + "default_title": "__MSG_OPEN_ACTION__", + "default_icon": "images/filetype_generic.png", + "file_filters": [ + "filesystem:*" + ] + }, + // Opens the passed directory after launching Files.app. + // TODO(mtomasz): Implement a directories filtering instead of files. + { + "id": "open", + "default_title": "__MSG_OPEN_ACTION__", + "default_icon": "images/filetype_generic.png", + "file_filters": [ + "filesystem:*" + ] + }, { "id": "play", "default_title": "__MSG_PLAY_MEDIA__", @@ -179,29 +208,6 @@ "file_filters": [ "filesystem:*.gslides" ] - }, - // The following handlers are used only internally, therefore they do not - // have any file filter. - // Automatically opens a volume and later close Files.app when unmounted. - { - "id": "auto-open", - "default_title": "__MSG_OPEN_ACTION__", - "default_icon": "images/filetype_generic.png", - "file_filters": [] - }, - // Selects the passed file after launching Files.app. - { - "id": "select", - "default_title": "__MSG_OPEN_ACTION__", - "default_icon": "images/filetype_generic.png", - "file_filters": [] - }, - // Opens the passed directory after launching Files.app. - { - "id": "open", - "default_title": "__MSG_OPEN_ACTION__", - "default_icon": "images/filetype_generic.png", - "file_filters": [] } ], "chrome_url_overrides": { |