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

Side by Side Diff: chrome/browser/chromeos/file_manager/file_tasks.cc

Issue 686393002: Add isGenericFileHandler property to FileTask. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test pattern. Created 6 years, 1 month 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
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/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/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 extension_misc::kQuickOfficeExtensionId, 120 extension_misc::kQuickOfficeExtensionId,
121 }; 121 };
122 122
123 for (size_t i = 0; i < arraysize(kBuiltInApps); ++i) { 123 for (size_t i = 0; i < arraysize(kBuiltInApps); ++i) {
124 if (task.app_id == kBuiltInApps[i]) 124 if (task.app_id == kBuiltInApps[i])
125 return true; 125 return true;
126 } 126 }
127 return false; 127 return false;
128 } 128 }
129 129
130 bool IsGenericFileHandler(const extensions::FileHandlerInfo& fileHandlerInfo) {
131 return fileHandlerInfo.extensions.count("*") > 0 ||
132 fileHandlerInfo.types.count("*") > 0 ||
133 fileHandlerInfo.types.count("*/*") > 0;
134 }
135
130 } // namespace 136 } // namespace
131 137
132 FullTaskDescriptor::FullTaskDescriptor( 138 FullTaskDescriptor::FullTaskDescriptor(
133 const TaskDescriptor& task_descriptor, 139 const TaskDescriptor& task_descriptor,
134 const std::string& task_title, 140 const std::string& task_title,
135 const GURL& icon_url, 141 const GURL& icon_url,
136 bool is_default) 142 bool is_default,
143 bool is_generic_file_handler)
137 : task_descriptor_(task_descriptor), 144 : task_descriptor_(task_descriptor),
138 task_title_(task_title), 145 task_title_(task_title),
139 icon_url_(icon_url), 146 icon_url_(icon_url),
140 is_default_(is_default) { 147 is_default_(is_default),
148 is_generic_file_handler_(is_generic_file_handler) {
141 } 149 }
142 150
143 void UpdateDefaultTask(PrefService* pref_service, 151 void UpdateDefaultTask(PrefService* pref_service,
144 const std::string& task_id, 152 const std::string& task_id,
145 const std::set<std::string>& suffixes, 153 const std::set<std::string>& suffixes,
146 const std::set<std::string>& mime_types) { 154 const std::set<std::string>& mime_types) {
147 if (!pref_service) 155 if (!pref_service)
148 return; 156 return;
149 157
150 if (!mime_types.empty()) { 158 if (!mime_types.empty()) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 TaskDescriptor descriptor(app_info.app_id, 354 TaskDescriptor descriptor(app_info.app_id,
347 TASK_TYPE_DRIVE_APP, 355 TASK_TYPE_DRIVE_APP,
348 kDriveAppActionID); 356 kDriveAppActionID);
349 GURL icon_url = drive::util::FindPreferredIcon( 357 GURL icon_url = drive::util::FindPreferredIcon(
350 app_info.app_icons, 358 app_info.app_icons,
351 drive::util::kPreferredIconSize); 359 drive::util::kPreferredIconSize);
352 result_list->push_back( 360 result_list->push_back(
353 FullTaskDescriptor(descriptor, 361 FullTaskDescriptor(descriptor,
354 app_info.app_name, 362 app_info.app_name,
355 icon_url, 363 icon_url,
356 false /* is_default */)); 364 false /* is_default */,
365 false /* is_generic_file_handler */));
357 } 366 }
358 } 367 }
359 368
360 void FindFileHandlerTasks( 369 void FindFileHandlerTasks(
361 Profile* profile, 370 Profile* profile,
362 const PathAndMimeTypeSet& path_mime_set, 371 const PathAndMimeTypeSet& path_mime_set,
363 std::vector<FullTaskDescriptor>* result_list) { 372 std::vector<FullTaskDescriptor>* result_list) {
364 DCHECK(!path_mime_set.empty()); 373 DCHECK(!path_mime_set.empty());
365 DCHECK(result_list); 374 DCHECK(result_list);
366 375
367 const extensions::ExtensionSet& enabled_extensions = 376 const extensions::ExtensionSet& enabled_extensions =
368 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); 377 extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
378
369 for (extensions::ExtensionSet::const_iterator iter = 379 for (extensions::ExtensionSet::const_iterator iter =
370 enabled_extensions.begin(); 380 enabled_extensions.begin();
371 iter != enabled_extensions.end(); 381 iter != enabled_extensions.end();
372 ++iter) { 382 ++iter) {
373 const Extension* extension = iter->get(); 383 const Extension* extension = iter->get();
374 384
375 // Check that the extension can be launched via an event. This includes all 385 // Check that the extension can be launched via an event. This includes all
376 // platform apps plus whitelisted extensions. 386 // platform apps plus whitelisted extensions.
377 if (!CanLaunchViaEvent(extension)) 387 if (!CanLaunchViaEvent(extension))
378 continue; 388 continue;
379 389
380 // Ephemeral apps cannot be file handlers. 390 // Ephemeral apps cannot be file handlers.
381 if (extensions::util::IsEphemeralApp(extension->id(), profile)) 391 if (extensions::util::IsEphemeralApp(extension->id(), profile))
382 continue; 392 continue;
383 393
384 if (profile->IsOffTheRecord() && 394 if (profile->IsOffTheRecord() &&
385 !extensions::util::IsIncognitoEnabled(extension->id(), profile)) 395 !extensions::util::IsIncognitoEnabled(extension->id(), profile))
386 continue; 396 continue;
387 397
388 typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList; 398 typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList;
389 FileHandlerList file_handlers = 399 FileHandlerList file_handlers =
390 FindFileHandlersForFiles(*extension, path_mime_set); 400 FindFileHandlersForFiles(*extension, path_mime_set);
391 if (file_handlers.empty()) 401 if (file_handlers.empty())
392 continue; 402 continue;
393 403
394 // Only show the first matching handler from each app. 404 // Only show the first matching non-generic handler from each app.
fukino 2014/10/30 07:56:33 I think this comment is not correct. Non-generic h
yawano 2014/10/30 08:06:18 Yes, the comment was wrong. I fixed it.
395 const extensions::FileHandlerInfo* file_handler = file_handlers.front(); 405 const extensions::FileHandlerInfo* file_handler = nullptr;
406 for (auto handler : file_handlers) {
407 if (!IsGenericFileHandler(*handler)) {
408 file_handler = handler;
409 break;
410 }
411 }
412 if (file_handler == nullptr) {
413 file_handler = file_handlers.front();
414 }
415
396 std::string task_id = file_tasks::MakeTaskID( 416 std::string task_id = file_tasks::MakeTaskID(
397 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id); 417 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id);
398 418
399 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( 419 GURL best_icon = extensions::ExtensionIconSource::GetIconURL(
400 extension, 420 extension,
401 drive::util::kPreferredIconSize, 421 drive::util::kPreferredIconSize,
402 ExtensionIconSet::MATCH_BIGGER, 422 ExtensionIconSet::MATCH_BIGGER,
403 false, // grayscale 423 false, // grayscale
404 NULL); // exists 424 NULL); // exists
405 425
406 result_list->push_back( 426 result_list->push_back(
407 FullTaskDescriptor(TaskDescriptor(extension->id(), 427 FullTaskDescriptor(TaskDescriptor(extension->id(),
408 file_tasks::TASK_TYPE_FILE_HANDLER, 428 file_tasks::TASK_TYPE_FILE_HANDLER,
409 file_handler->id), 429 file_handler->id),
410 extension->name(), 430 extension->name(),
411 best_icon, 431 best_icon,
412 false /* is_default */)); 432 false /* is_default */,
433 IsGenericFileHandler(*file_handler)));
413 } 434 }
414 } 435 }
415 436
416 void FindFileBrowserHandlerTasks( 437 void FindFileBrowserHandlerTasks(
417 Profile* profile, 438 Profile* profile,
418 const std::vector<GURL>& file_urls, 439 const std::vector<GURL>& file_urls,
419 std::vector<FullTaskDescriptor>* result_list) { 440 std::vector<FullTaskDescriptor>* result_list) {
420 DCHECK(!file_urls.empty()); 441 DCHECK(!file_urls.empty());
421 DCHECK(result_list); 442 DCHECK(result_list);
422 443
(...skipping 21 matching lines...) Expand all
444 ExtensionIconSet::MATCH_BIGGER, 465 ExtensionIconSet::MATCH_BIGGER,
445 false, // grayscale 466 false, // grayscale
446 NULL); // exists 467 NULL); // exists
447 468
448 result_list->push_back(FullTaskDescriptor( 469 result_list->push_back(FullTaskDescriptor(
449 TaskDescriptor(extension_id, 470 TaskDescriptor(extension_id,
450 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, 471 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER,
451 handler->id()), 472 handler->id()),
452 handler->title(), 473 handler->title(),
453 icon_url, 474 icon_url,
454 false /* is_default */)); 475 false /* is_default */,
476 false /* is_generic_file_handler */));
455 } 477 }
456 } 478 }
457 479
458 void FindAllTypesOfTasks( 480 void FindAllTypesOfTasks(
459 Profile* profile, 481 Profile* profile,
460 const drive::DriveAppRegistry* drive_app_registry, 482 const drive::DriveAppRegistry* drive_app_registry,
461 const PathAndMimeTypeSet& path_mime_set, 483 const PathAndMimeTypeSet& path_mime_set,
462 const std::vector<GURL>& file_urls, 484 const std::vector<GURL>& file_urls,
463 std::vector<FullTaskDescriptor>* result_list) { 485 std::vector<FullTaskDescriptor>* result_list) {
464 DCHECK(profile); 486 DCHECK(profile);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 DCHECK(!task->is_default()); 540 DCHECK(!task->is_default());
519 if (IsFallbackFileHandler(task->task_descriptor())) { 541 if (IsFallbackFileHandler(task->task_descriptor())) {
520 task->set_is_default(true); 542 task->set_is_default(true);
521 return; 543 return;
522 } 544 }
523 } 545 }
524 } 546 }
525 547
526 } // namespace file_tasks 548 } // namespace file_tasks
527 } // namespace file_manager 549 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/file_tasks.h ('k') | chrome/browser/chromeos/file_manager/file_tasks_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698