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

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: 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
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,
dgozman 2012/06/18 15:21:14 no space before &
Vladislav Kaznacheev 2012/06/18 17:05:54 Done.
237 const std::string & id) {
238 LastUsedHandlerList::iterator iter = list->begin();
239 while (iter != list->end() &&
240 !(iter->handler->extension_id() == extension_id &&
dgozman 2012/06/18 15:21:14 I'd indent this with 3 more spaces.
Vladislav Kaznacheev 2012/06/18 17:05:54 Done.
241 iter->handler->id() == id))
242 iter++;
dgozman 2012/06/18 15:21:14 AFAIK, while body must be a block.
Vladislav Kaznacheev 2012/06/18 17:05:54 Done.
243 return iter;
244 }
245
233 // Given the list of selected files, returns array of context menu tasks 246 // Given the list of selected files, returns array of context menu tasks
234 // that are shared 247 // that are shared
235 bool FindCommonTasks(Profile* profile, 248 bool FindCommonTasks(Profile* profile,
236 const std::vector<GURL>& files_list, 249 const std::vector<GURL>& files_list,
237 LastUsedHandlerList* named_action_list) { 250 LastUsedHandlerList* named_action_list) {
238 named_action_list->clear(); 251 named_action_list->clear();
239 ActionSet common_tasks; 252 ActionSet common_tasks;
240 for (std::vector<GURL>::const_iterator it = files_list.begin(); 253 for (std::vector<GURL>::const_iterator it = files_list.begin();
241 it != files_list.end(); ++it) { 254 it != files_list.end(); ++it) {
242 ActionSet file_actions; 255 ActionSet file_actions;
(...skipping 22 matching lines...) Expand all
265 } 278 }
266 279
267 const DictionaryValue* prefs_tasks = 280 const DictionaryValue* prefs_tasks =
268 profile->GetPrefs()->GetDictionary(prefs::kLastUsedFileBrowserHandlers); 281 profile->GetPrefs()->GetDictionary(prefs::kLastUsedFileBrowserHandlers);
269 for (ActionSet::const_iterator iter = common_tasks.begin(); 282 for (ActionSet::const_iterator iter = common_tasks.begin();
270 iter != common_tasks.end(); ++iter) { 283 iter != common_tasks.end(); ++iter) {
271 // Get timestamp of when this task was used last time. 284 // Get timestamp of when this task was used last time.
272 int last_used_timestamp = 0; 285 int last_used_timestamp = 0;
273 286
274 if ((*iter)->extension_id() == kFileBrowserDomain) { 287 if ((*iter)->extension_id() == kFileBrowserDomain) {
275 // Give a little bump to the action from File Browser extenion 288 // Give a little bump to the action from File Browser extension
276 // to make sure it is the default on a fresh profile. 289 // to make sure it is the default on a fresh profile.
277 last_used_timestamp = 1; 290 last_used_timestamp = 1;
278 } 291 }
279 prefs_tasks->GetInteger(MakeTaskID((*iter)->extension_id(), (*iter)->id()), 292 prefs_tasks->GetInteger(MakeTaskID((*iter)->extension_id(), (*iter)->id()),
280 &last_used_timestamp); 293 &last_used_timestamp);
281 URLPatternSet matching_patterns = GetAllMatchingPatterns(*iter, files_list); 294 URLPatternSet matching_patterns = GetAllMatchingPatterns(*iter, files_list);
282 named_action_list->push_back(LastUsedHandler(last_used_timestamp, *iter, 295 named_action_list->push_back(LastUsedHandler(last_used_timestamp, *iter,
283 matching_patterns)); 296 matching_patterns));
284 } 297 }
285 298
299 LastUsedHandlerList::iterator watch_iter = FindHandler(
300 named_action_list, kFileBrowserDomain, kFileBrowserWatchTaskId);
301 LastUsedHandlerList::iterator gallery_iter = FindHandler(
302 named_action_list, kFileBrowserDomain, kFileBrowserGalleryTaskId);
303 if (watch_iter != named_action_list->end() &&
304 gallery_iter != named_action_list->end()) {
305 // Both "watch" and "gallery" actions are applicable which means that
306 // the selection is all videos. Showing them both is confusing. We only keep
307 // the one that makes more sense ("watch" for single selection, "gallery"
308 // for multiple selection).
309
310 if (files_list.size() == 1)
311 named_action_list->erase(gallery_iter);
312 else
313 named_action_list->erase(watch_iter);
314 }
315
286 SortLastUsedHandlerList(named_action_list); 316 SortLastUsedHandlerList(named_action_list);
287 return true; 317 return true;
288 } 318 }
289 319
290 bool GetDefaultTask( 320 bool GetDefaultTask(
291 Profile* profile, const GURL& url, const FileBrowserHandler** handler) { 321 Profile* profile, const GURL& url, const FileBrowserHandler** handler) {
292 std::vector<GURL> file_urls; 322 std::vector<GURL> file_urls;
293 file_urls.push_back(url); 323 file_urls.push_back(url);
294 324
295 LastUsedHandlerList common_tasks; 325 LastUsedHandlerList common_tasks;
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 handler_host_permissions_[i].first, 742 handler_host_permissions_[i].first,
713 handler_host_permissions_[i].second); 743 handler_host_permissions_[i].second);
714 } 744 }
715 745
716 // We don't need this anymore. 746 // We don't need this anymore.
717 handler_host_permissions_.clear(); 747 handler_host_permissions_.clear();
718 } 748 }
719 749
720 } // namespace file_handler_util 750 } // namespace file_handler_util
721 751
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698