OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/file_manager/file_tasks.h" | 5 #include "chrome/browser/chromeos/file_manager/file_tasks.h" |
6 | 6 |
7 #include "apps/launcher.h" | 7 #include "apps/launcher.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 // Leaves tasks handled by the file manger itself as is and removes all others. | 100 // Leaves tasks handled by the file manger itself as is and removes all others. |
101 void KeepOnlyFileManagerInternalTasks(std::vector<FullTaskDescriptor>* tasks) { | 101 void KeepOnlyFileManagerInternalTasks(std::vector<FullTaskDescriptor>* tasks) { |
102 std::vector<FullTaskDescriptor> filtered; | 102 std::vector<FullTaskDescriptor> filtered; |
103 for (size_t i = 0; i < tasks->size(); ++i) { | 103 for (size_t i = 0; i < tasks->size(); ++i) { |
104 if ((*tasks)[i].task_descriptor().app_id == kFileManagerAppId) | 104 if ((*tasks)[i].task_descriptor().app_id == kFileManagerAppId) |
105 filtered.push_back((*tasks)[i]); | 105 filtered.push_back((*tasks)[i]); |
106 } | 106 } |
107 tasks->swap(filtered); | 107 tasks->swap(filtered); |
108 } | 108 } |
109 | 109 |
110 // Finds a task that matches |app_id| and |action_id| from |task_list|. | |
111 // Returns a mutable iterator to the handler if found. Returns task_list->end() | |
112 // if not found. | |
113 std::vector<FullTaskDescriptor>::iterator | |
114 FindTaskForExtensionIdAndActionId( | |
hashimoto
2014/03/28 07:57:10
nit: FindTaskForAppIdAndActionId? The argument is
hashimoto
2014/03/28 09:28:59
ping?
yoshiki
2014/03/28 09:31:27
Done.
| |
115 std::vector<FullTaskDescriptor>* task_list, | |
116 const std::string& app_id, | |
117 const std::string& action_id) { | |
118 DCHECK(task_list); | |
119 | |
120 std::vector<FullTaskDescriptor>::iterator iter = task_list->begin(); | |
121 while (iter != task_list->end() && | |
122 !(iter->task_descriptor().app_id == app_id && | |
123 iter->task_descriptor().action_id == action_id)) { | |
124 ++iter; | |
125 } | |
126 return iter; | |
127 } | |
128 | |
129 // Chooses a suitable video handeler and removes other internal video hander. | |
130 // Both "watch" and "gallery-video" actions are applicable which means that the | |
131 // selection is all videos. Showing them both is confusing, so we only keep | |
132 // the one that makes more sense ("watch" for single selection, "gallery" | |
133 // for multiple selection). | |
134 void ChooseSuitableVideoHandler( | |
hashimoto
2014/03/28 07:57:10
This new function is not used?
| |
135 const std::vector<GURL>& file_urls, | |
136 std::vector<FullTaskDescriptor>* task_list) { | |
137 std::vector<FullTaskDescriptor>::iterator video_player_iter = | |
138 FindTaskForExtensionIdAndActionId(task_list, kVideoPlayerAppId, "video"); | |
139 std::vector<FullTaskDescriptor>::iterator gallery_video_iter = | |
140 FindTaskForExtensionIdAndActionId( | |
141 task_list, kFileManagerAppId, "gallery-video"); | |
142 | |
143 if (video_player_iter != task_list->end() && | |
144 gallery_video_iter != task_list->end()) { | |
145 if (file_urls.size() == 1) | |
146 task_list->erase(gallery_video_iter); | |
147 else | |
148 task_list->erase(video_player_iter); | |
149 } | |
150 } | |
151 | |
110 } // namespace | 152 } // namespace |
111 | 153 |
112 FullTaskDescriptor::FullTaskDescriptor( | 154 FullTaskDescriptor::FullTaskDescriptor( |
113 const TaskDescriptor& task_descriptor, | 155 const TaskDescriptor& task_descriptor, |
114 const std::string& task_title, | 156 const std::string& task_title, |
115 const GURL& icon_url, | 157 const GURL& icon_url, |
116 bool is_default) | 158 bool is_default) |
117 : task_descriptor_(task_descriptor), | 159 : task_descriptor_(task_descriptor), |
118 task_title_(task_title), | 160 task_title_(task_title), |
119 icon_url_(icon_url), | 161 icon_url_(icon_url), |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 | 502 |
461 // Find and append file browser handler tasks. We know there aren't | 503 // Find and append file browser handler tasks. We know there aren't |
462 // duplicates because "file_browser_handlers" and "file_handlers" shouldn't | 504 // duplicates because "file_browser_handlers" and "file_handlers" shouldn't |
463 // be used in the same manifest.json. | 505 // be used in the same manifest.json. |
464 FindFileBrowserHandlerTasks(profile, file_urls, result_list); | 506 FindFileBrowserHandlerTasks(profile, file_urls, result_list); |
465 | 507 |
466 // Google documents can only be handled by internal handlers. | 508 // Google documents can only be handled by internal handlers. |
467 if (ContainsGoogleDocument(path_mime_set)) | 509 if (ContainsGoogleDocument(path_mime_set)) |
468 KeepOnlyFileManagerInternalTasks(result_list); | 510 KeepOnlyFileManagerInternalTasks(result_list); |
469 | 511 |
512 RemoveDuplicateVideoHandler(file_urls, result_list); | |
513 | |
470 ChooseAndSetDefaultTask(*profile->GetPrefs(), path_mime_set, result_list); | 514 ChooseAndSetDefaultTask(*profile->GetPrefs(), path_mime_set, result_list); |
471 } | 515 } |
472 | 516 |
473 void ChooseAndSetDefaultTask(const PrefService& pref_service, | 517 void ChooseAndSetDefaultTask(const PrefService& pref_service, |
474 const PathAndMimeTypeSet& path_mime_set, | 518 const PathAndMimeTypeSet& path_mime_set, |
475 std::vector<FullTaskDescriptor>* tasks) { | 519 std::vector<FullTaskDescriptor>* tasks) { |
476 // Collect the task IDs of default tasks from the preferences into a set. | 520 // Collect the task IDs of default tasks from the preferences into a set. |
477 std::set<std::string> default_task_ids; | 521 std::set<std::string> default_task_ids; |
478 for (PathAndMimeTypeSet::const_iterator it = path_mime_set.begin(); | 522 for (PathAndMimeTypeSet::const_iterator it = path_mime_set.begin(); |
479 it != path_mime_set.end(); ++it) { | 523 it != path_mime_set.end(); ++it) { |
(...skipping 24 matching lines...) Expand all Loading... | |
504 if (file_browser_handlers::IsFallbackFileBrowserHandler( | 548 if (file_browser_handlers::IsFallbackFileBrowserHandler( |
505 task->task_descriptor())) { | 549 task->task_descriptor())) { |
506 task->set_is_default(true); | 550 task->set_is_default(true); |
507 return; | 551 return; |
508 } | 552 } |
509 } | 553 } |
510 } | 554 } |
511 | 555 |
512 } // namespace file_tasks | 556 } // namespace file_tasks |
513 } // namespace file_manager | 557 } // namespace file_manager |
OLD | NEW |