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

Unified Diff: chrome/browser/chromeos/extensions/file_manager/file_handler_util.cc

Issue 15975004: Replace sets with vectors when storing file handlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 7 years, 7 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/extensions/file_manager/file_handler_util.cc
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 c9f36002e814ec4219a5843f4c59c6a84471541d..4c281a169feba305c5545621ea534f9d5473dada 100644
--- a/chrome/browser/chromeos/extensions/file_manager/file_handler_util.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/file_handler_util.cc
@@ -65,8 +65,6 @@ 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 |
@@ -160,7 +158,7 @@ std::string EscapedUtf8ToLower(const std::string& str) {
bool GetFileBrowserHandlers(Profile* profile,
const GURL& selected_file_url,
- FileBrowserHandlerSet* results) {
+ FileBrowserHandlerList* results) {
ExtensionService* service =
extensions::ExtensionSystem::Get(profile)->extension_service();
if (!service)
@@ -190,7 +188,7 @@ bool GetFileBrowserHandlers(Profile* profile,
if (!action->MatchesURL(lowercase_url))
continue;
- results->insert(action_iter->get());
+ results->push_back(action_iter->get());
}
}
return true;
@@ -330,12 +328,12 @@ bool CrackTaskID(const std::string& task_id,
}
// Find a specific handler in the handler list.
-FileBrowserHandlerSet::iterator FindHandler(
- FileBrowserHandlerSet* handler_set,
+FileBrowserHandlerList::iterator FindHandler(
+ FileBrowserHandlerList* handler_list,
hashimoto 2013/05/24 08:38:57 nit: Could you add const while you are here?
mtomasz 2013/05/24 10:37:59 If I do that, then I have to return a const_iterat
hashimoto 2013/05/24 11:15:51 Oops, I was too careless to forget to look at how
const std::string& extension_id,
const std::string& id) {
- FileBrowserHandlerSet::iterator iter = handler_set->begin();
- while (iter != handler_set->end() &&
+ FileBrowserHandlerList::iterator iter = handler_list->begin();
+ while (iter != handler_list->end() &&
!((*iter)->extension_id() == extension_id &&
(*iter)->id() == id)) {
iter++;
hashimoto 2013/05/24 08:38:57 nit: Could you fix this to ++iter while you are he
mtomasz 2013/05/24 10:37:59 If I do that then it makes lots of stuff complicat
hashimoto 2013/05/24 11:15:51 I just wanted you to use preincrement (++iter) ins
mtomasz 2013/05/27 01:20:20 Done.
@@ -347,8 +345,8 @@ FileBrowserHandlerSet::iterator FindHandler(
// that are shared between them.
void FindDefaultTasks(Profile* profile,
const std::vector<base::FilePath>& files_list,
- const FileBrowserHandlerSet& common_tasks,
- FileBrowserHandlerSet* default_tasks) {
+ const FileBrowserHandlerList& common_tasks,
+ FileBrowserHandlerList* default_tasks) {
DCHECK(default_tasks);
default_tasks->clear();
@@ -364,13 +362,13 @@ void FindDefaultTasks(Profile* profile,
const FileBrowserHandler* builtin_task = NULL;
// Convert the default task IDs collected above to one of the handler pointers
// from common_tasks.
- for (FileBrowserHandlerSet::const_iterator task_iter = common_tasks.begin();
+ for (FileBrowserHandlerList::const_iterator task_iter = common_tasks.begin();
hashimoto 2013/05/24 08:38:57 nit: Use size_t to iterate over a vector.
mtomasz 2013/05/24 10:37:59 Why is it better? We work extensively on iterators
hashimoto 2013/05/24 11:15:51 Fair enough.
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->insert(*task_iter);
+ default_tasks->push_back(*task_iter);
continue;
}
@@ -385,22 +383,22 @@ void FindDefaultTasks(Profile* profile,
// 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);
+ default_tasks->push_back(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,
- FileBrowserHandlerSet* common_tasks) {
+ FileBrowserHandlerList* common_tasks) {
DCHECK(common_tasks);
common_tasks->clear();
- FileBrowserHandlerSet common_task_set;
+ FileBrowserHandlerList common_task_list;
std::set<std::string> default_task_ids;
for (std::vector<GURL>::const_iterator it = files_list.begin();
it != files_list.end(); ++it) {
- FileBrowserHandlerSet file_actions;
+ FileBrowserHandlerList 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
@@ -410,38 +408,37 @@ bool FindCommonTasks(Profile* profile,
// For the very first file, just copy all the elements.
if (it == files_list.begin()) {
- common_task_set = file_actions;
+ common_task_list = file_actions;
} else {
// For all additional files, find intersection between the accumulated and
// file specific set.
- FileBrowserHandlerSet intersection;
- std::set_intersection(common_task_set.begin(), common_task_set.end(),
+ FileBrowserHandlerList intersection;
+ std::set_intersection(common_task_list.begin(), common_task_list.end(),
file_actions.begin(), file_actions.end(),
- std::inserter(intersection,
- intersection.begin()));
- common_task_set = intersection;
- if (common_task_set.empty())
+ std::back_inserter(intersection));
+ common_task_list = intersection;
+ if (common_task_list.empty())
return true;
}
}
- 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()) {
+ 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()) {
// 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_set.erase(gallery_iter);
+ common_task_list.erase(gallery_iter);
else
- common_task_set.erase(watch_iter);
+ common_task_list.erase(watch_iter);
}
- common_tasks->swap(common_task_set);
+ common_tasks->swap(common_task_list);
return true;
}
@@ -452,8 +449,8 @@ bool GetTaskForURLAndPath(Profile* profile,
std::vector<GURL> file_urls;
file_urls.push_back(url);
- FileBrowserHandlerSet default_tasks;
- FileBrowserHandlerSet common_tasks;
+ FileBrowserHandlerList default_tasks;
+ FileBrowserHandlerList common_tasks;
if (!FindCommonTasks(profile, file_urls, &common_tasks))
return false;

Powered by Google App Engine
This is Rietveld 408576698