| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 // Leaves tasks handled by the file manger itself as is and removes all others. | 101 // Leaves tasks handled by the file manger itself as is and removes all others. |
| 102 void KeepOnlyFileManagerInternalTasks(std::vector<FullTaskDescriptor>* tasks) { | 102 void KeepOnlyFileManagerInternalTasks(std::vector<FullTaskDescriptor>* tasks) { |
| 103 std::vector<FullTaskDescriptor> filtered; | 103 std::vector<FullTaskDescriptor> filtered; |
| 104 for (size_t i = 0; i < tasks->size(); ++i) { | 104 for (size_t i = 0; i < tasks->size(); ++i) { |
| 105 if ((*tasks)[i].task_descriptor().app_id == kFileManagerAppId) | 105 if ((*tasks)[i].task_descriptor().app_id == kFileManagerAppId) |
| 106 filtered.push_back((*tasks)[i]); | 106 filtered.push_back((*tasks)[i]); |
| 107 } | 107 } |
| 108 tasks->swap(filtered); | 108 tasks->swap(filtered); |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Finds a task that matches |app_id| and |action_id| from |task_list|. | |
| 112 // Returns a mutable iterator to the handler if found. Returns task_list->end() | |
| 113 // if not found. | |
| 114 std::vector<FullTaskDescriptor>::iterator | |
| 115 FindTaskForAppIdAndActionId( | |
| 116 std::vector<FullTaskDescriptor>* task_list, | |
| 117 const std::string& app_id, | |
| 118 const std::string& action_id) { | |
| 119 DCHECK(task_list); | |
| 120 | |
| 121 std::vector<FullTaskDescriptor>::iterator iter = task_list->begin(); | |
| 122 while (iter != task_list->end() && | |
| 123 !(iter->task_descriptor().app_id == app_id && | |
| 124 iter->task_descriptor().action_id == action_id)) { | |
| 125 ++iter; | |
| 126 } | |
| 127 return iter; | |
| 128 } | |
| 129 | |
| 130 void ChooseSuitableGalleryHandler(std::vector<FullTaskDescriptor>* task_list) { | 111 void ChooseSuitableGalleryHandler(std::vector<FullTaskDescriptor>* task_list) { |
| 131 const bool disable_new_gallery = | 112 const bool disable_new_gallery = |
| 132 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 113 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 133 chromeos::switches::kFileManagerEnableNewGallery) == "false"; | 114 chromeos::switches::kFileManagerEnableNewGallery) == "false"; |
| 134 std::vector<FullTaskDescriptor>::iterator it = task_list->begin(); | 115 std::vector<FullTaskDescriptor>::iterator it = task_list->begin(); |
| 135 while (it != task_list->end()) { | 116 while (it != task_list->end()) { |
| 136 if (disable_new_gallery) { | 117 if (disable_new_gallery) { |
| 137 if (it->task_descriptor().app_id == kGalleryAppId) | 118 if (it->task_descriptor().app_id == kGalleryAppId) |
| 138 it = task_list->erase(it); | 119 it = task_list->erase(it); |
| 139 else | 120 else |
| 140 ++it; | 121 ++it; |
| 141 } else { | 122 } else { |
| 142 if (it->task_descriptor().app_id == kFileManagerAppId && | 123 if (it->task_descriptor().app_id == kFileManagerAppId && |
| 143 (it->task_descriptor().action_id == "gallery" || | 124 it->task_descriptor().action_id == "gallery") { |
| 144 it->task_descriptor().action_id == "gallery-video")) { | |
| 145 it = task_list->erase(it); | 125 it = task_list->erase(it); |
| 146 } else { | 126 } else { |
| 147 ++it; | 127 ++it; |
| 148 } | 128 } |
| 149 } | 129 } |
| 150 } | 130 } |
| 151 } | 131 } |
| 152 | 132 |
| 153 // Chooses a suitable video handeler and removes other internal video hander. | |
| 154 // Both "watch" and "gallery-video" actions are applicable which means that the | |
| 155 // selection is all videos. Showing them both is confusing, so we only keep | |
| 156 // the one that makes more sense ("watch" for single selection, "gallery" | |
| 157 // for multiple selection). | |
| 158 void ChooseSuitableVideoHandler( | |
| 159 const std::vector<GURL>& file_urls, | |
| 160 std::vector<FullTaskDescriptor>* task_list) { | |
| 161 std::vector<FullTaskDescriptor>::iterator video_player_iter = | |
| 162 FindTaskForAppIdAndActionId(task_list, kVideoPlayerAppId, "video"); | |
| 163 std::vector<FullTaskDescriptor>::iterator gallery_video_iter; | |
| 164 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 165 chromeos::switches::kFileManagerEnableNewGallery) == "false") { | |
| 166 gallery_video_iter = FindTaskForAppIdAndActionId( | |
| 167 task_list, kFileManagerAppId, "gallery-video"); | |
| 168 } else { | |
| 169 gallery_video_iter = | |
| 170 FindTaskForAppIdAndActionId(task_list, kGalleryAppId, "open"); | |
| 171 } | |
| 172 | |
| 173 if (video_player_iter != task_list->end() && | |
| 174 gallery_video_iter != task_list->end()) { | |
| 175 if (file_urls.size() == 1) | |
| 176 task_list->erase(gallery_video_iter); | |
| 177 else | |
| 178 task_list->erase(video_player_iter); | |
| 179 } | |
| 180 } | |
| 181 | |
| 182 } // namespace | 133 } // namespace |
| 183 | 134 |
| 184 FullTaskDescriptor::FullTaskDescriptor( | 135 FullTaskDescriptor::FullTaskDescriptor( |
| 185 const TaskDescriptor& task_descriptor, | 136 const TaskDescriptor& task_descriptor, |
| 186 const std::string& task_title, | 137 const std::string& task_title, |
| 187 const GURL& icon_url, | 138 const GURL& icon_url, |
| 188 bool is_default) | 139 bool is_default) |
| 189 : task_descriptor_(task_descriptor), | 140 : task_descriptor_(task_descriptor), |
| 190 task_title_(task_title), | 141 task_title_(task_title), |
| 191 icon_url_(icon_url), | 142 icon_url_(icon_url), |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 // Find and append file browser handler tasks. We know there aren't | 484 // Find and append file browser handler tasks. We know there aren't |
| 534 // duplicates because "file_browser_handlers" and "file_handlers" shouldn't | 485 // duplicates because "file_browser_handlers" and "file_handlers" shouldn't |
| 535 // be used in the same manifest.json. | 486 // be used in the same manifest.json. |
| 536 FindFileBrowserHandlerTasks(profile, file_urls, result_list); | 487 FindFileBrowserHandlerTasks(profile, file_urls, result_list); |
| 537 | 488 |
| 538 // Google documents can only be handled by internal handlers. | 489 // Google documents can only be handled by internal handlers. |
| 539 if (ContainsGoogleDocument(path_mime_set)) | 490 if (ContainsGoogleDocument(path_mime_set)) |
| 540 KeepOnlyFileManagerInternalTasks(result_list); | 491 KeepOnlyFileManagerInternalTasks(result_list); |
| 541 | 492 |
| 542 ChooseSuitableGalleryHandler(result_list); | 493 ChooseSuitableGalleryHandler(result_list); |
| 543 ChooseSuitableVideoHandler(file_urls, result_list); | |
| 544 | |
| 545 ChooseAndSetDefaultTask(*profile->GetPrefs(), path_mime_set, result_list); | 494 ChooseAndSetDefaultTask(*profile->GetPrefs(), path_mime_set, result_list); |
| 546 } | 495 } |
| 547 | 496 |
| 548 void ChooseAndSetDefaultTask(const PrefService& pref_service, | 497 void ChooseAndSetDefaultTask(const PrefService& pref_service, |
| 549 const PathAndMimeTypeSet& path_mime_set, | 498 const PathAndMimeTypeSet& path_mime_set, |
| 550 std::vector<FullTaskDescriptor>* tasks) { | 499 std::vector<FullTaskDescriptor>* tasks) { |
| 551 // Collect the task IDs of default tasks from the preferences into a set. | 500 // Collect the task IDs of default tasks from the preferences into a set. |
| 552 std::set<std::string> default_task_ids; | 501 std::set<std::string> default_task_ids; |
| 553 for (PathAndMimeTypeSet::const_iterator it = path_mime_set.begin(); | 502 for (PathAndMimeTypeSet::const_iterator it = path_mime_set.begin(); |
| 554 it != path_mime_set.end(); ++it) { | 503 it != path_mime_set.end(); ++it) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 579 if (file_browser_handlers::IsFallbackFileBrowserHandler( | 528 if (file_browser_handlers::IsFallbackFileBrowserHandler( |
| 580 task->task_descriptor())) { | 529 task->task_descriptor())) { |
| 581 task->set_is_default(true); | 530 task->set_is_default(true); |
| 582 return; | 531 return; |
| 583 } | 532 } |
| 584 } | 533 } |
| 585 } | 534 } |
| 586 | 535 |
| 587 } // namespace file_tasks | 536 } // namespace file_tasks |
| 588 } // namespace file_manager | 537 } // namespace file_manager |
| OLD | NEW |