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

Side by Side Diff: chrome/browser/chromeos/extensions/file_handler_util.cc

Issue 10556041: [File Manager] Avoiding confusion between "Watch" and "Open" actions for video files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_manager_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/extensions/file_handler_util.h" 5 #include "chrome/browser/chromeos/extensions/file_handler_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 std::string* action_id) { 223 std::string* action_id) {
224 std::vector<std::string> result; 224 std::vector<std::string> result;
225 int count = Tokenize(task_id, std::string("|"), &result); 225 int count = Tokenize(task_id, std::string("|"), &result);
226 if (count != 2) 226 if (count != 2)
227 return false; 227 return false;
228 *extension_id = result[0]; 228 *extension_id = result[0];
229 *action_id = result[1]; 229 *action_id = result[1];
230 return true; 230 return true;
231 } 231 }
232 232
233 // Find a specific handler in the handler list.
234 LastUsedHandlerList::iterator FindHandler(
235 LastUsedHandlerList* list,
236 const std::string& extension_id,
237 const std::string& id) {
238 LastUsedHandlerList::iterator iter = list->begin();
239 while (iter != list->end() &&
240 !(iter->handler->extension_id() == extension_id &&
241 iter->handler->id() == id)) {
242 iter++;
243 }
244 return iter;
245 }
246
233 // Given the list of selected files, returns array of context menu tasks 247 // Given the list of selected files, returns array of context menu tasks
234 // that are shared 248 // that are shared
235 bool FindCommonTasks(Profile* profile, 249 bool FindCommonTasks(Profile* profile,
236 const std::vector<GURL>& files_list, 250 const std::vector<GURL>& files_list,
237 LastUsedHandlerList* named_action_list) { 251 LastUsedHandlerList* named_action_list) {
238 named_action_list->clear(); 252 named_action_list->clear();
239 ActionSet common_tasks; 253 ActionSet common_tasks;
240 for (std::vector<GURL>::const_iterator it = files_list.begin(); 254 for (std::vector<GURL>::const_iterator it = files_list.begin();
241 it != files_list.end(); ++it) { 255 it != files_list.end(); ++it) {
242 ActionSet file_actions; 256 ActionSet file_actions;
(...skipping 22 matching lines...) Expand all
265 } 279 }
266 280
267 const DictionaryValue* prefs_tasks = 281 const DictionaryValue* prefs_tasks =
268 profile->GetPrefs()->GetDictionary(prefs::kLastUsedFileBrowserHandlers); 282 profile->GetPrefs()->GetDictionary(prefs::kLastUsedFileBrowserHandlers);
269 for (ActionSet::const_iterator iter = common_tasks.begin(); 283 for (ActionSet::const_iterator iter = common_tasks.begin();
270 iter != common_tasks.end(); ++iter) { 284 iter != common_tasks.end(); ++iter) {
271 // Get timestamp of when this task was used last time. 285 // Get timestamp of when this task was used last time.
272 int last_used_timestamp = 0; 286 int last_used_timestamp = 0;
273 287
274 if ((*iter)->extension_id() == kFileBrowserDomain) { 288 if ((*iter)->extension_id() == kFileBrowserDomain) {
275 // Give a little bump to the action from File Browser extenion 289 // Give a little bump to the action from File Browser extension
276 // to make sure it is the default on a fresh profile. 290 // to make sure it is the default on a fresh profile.
277 last_used_timestamp = 1; 291 last_used_timestamp = 1;
278 } 292 }
279 prefs_tasks->GetInteger(MakeTaskID((*iter)->extension_id(), (*iter)->id()), 293 prefs_tasks->GetInteger(MakeTaskID((*iter)->extension_id(), (*iter)->id()),
280 &last_used_timestamp); 294 &last_used_timestamp);
281 URLPatternSet matching_patterns = GetAllMatchingPatterns(*iter, files_list); 295 URLPatternSet matching_patterns = GetAllMatchingPatterns(*iter, files_list);
282 named_action_list->push_back(LastUsedHandler(last_used_timestamp, *iter, 296 named_action_list->push_back(LastUsedHandler(last_used_timestamp, *iter,
283 matching_patterns)); 297 matching_patterns));
284 } 298 }
285 299
300 LastUsedHandlerList::iterator watch_iter = FindHandler(
301 named_action_list, kFileBrowserDomain, kFileBrowserWatchTaskId);
302 LastUsedHandlerList::iterator gallery_iter = FindHandler(
303 named_action_list, kFileBrowserDomain, kFileBrowserGalleryTaskId);
304 if (watch_iter != named_action_list->end() &&
305 gallery_iter != named_action_list->end()) {
306 // Both "watch" and "gallery" actions are applicable which means that
307 // the selection is all videos. Showing them both is confusing. We only keep
308 // the one that makes more sense ("watch" for single selection, "gallery"
309 // for multiple selection).
310
311 if (files_list.size() == 1)
312 named_action_list->erase(gallery_iter);
313 else
314 named_action_list->erase(watch_iter);
315 }
316
286 SortLastUsedHandlerList(named_action_list); 317 SortLastUsedHandlerList(named_action_list);
287 return true; 318 return true;
288 } 319 }
289 320
290 bool GetDefaultTask( 321 bool GetDefaultTask(
291 Profile* profile, const GURL& url, const FileBrowserHandler** handler) { 322 Profile* profile, const GURL& url, const FileBrowserHandler** handler) {
292 std::vector<GURL> file_urls; 323 std::vector<GURL> file_urls;
293 file_urls.push_back(url); 324 file_urls.push_back(url);
294 325
295 LastUsedHandlerList common_tasks; 326 LastUsedHandlerList common_tasks;
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 handler_host_permissions_[i].first, 743 handler_host_permissions_[i].first,
713 handler_host_permissions_[i].second); 744 handler_host_permissions_[i].second);
714 } 745 }
715 746
716 // We don't need this anymore. 747 // We don't need this anymore.
717 handler_host_permissions_.clear(); 748 handler_host_permissions_.clear();
718 } 749 }
719 750
720 } // namespace file_handler_util 751 } // namespace file_handler_util
721 752
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_manager_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698