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

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: Rebased. 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 127 }
128 return false; 128 return false;
129 } 129 }
130 130
131 } // namespace 131 } // namespace
132 132
133 FullTaskDescriptor::FullTaskDescriptor( 133 FullTaskDescriptor::FullTaskDescriptor(
134 const TaskDescriptor& task_descriptor, 134 const TaskDescriptor& task_descriptor,
135 const std::string& task_title, 135 const std::string& task_title,
136 const GURL& icon_url, 136 const GURL& icon_url,
137 bool is_default) 137 bool is_default,
138 bool is_generic_file_handler)
138 : task_descriptor_(task_descriptor), 139 : task_descriptor_(task_descriptor),
139 task_title_(task_title), 140 task_title_(task_title),
140 icon_url_(icon_url), 141 icon_url_(icon_url),
141 is_default_(is_default) { 142 is_default_(is_default),
143 is_generic_file_handler_(is_generic_file_handler) {
142 } 144 }
143 145
144 void UpdateDefaultTask(PrefService* pref_service, 146 void UpdateDefaultTask(PrefService* pref_service,
145 const std::string& task_id, 147 const std::string& task_id,
146 const std::set<std::string>& suffixes, 148 const std::set<std::string>& suffixes,
147 const std::set<std::string>& mime_types) { 149 const std::set<std::string>& mime_types) {
148 if (!pref_service) 150 if (!pref_service)
149 return; 151 return;
150 152
151 if (!mime_types.empty()) { 153 if (!mime_types.empty()) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 TaskDescriptor descriptor(app_info.app_id, 349 TaskDescriptor descriptor(app_info.app_id,
348 TASK_TYPE_DRIVE_APP, 350 TASK_TYPE_DRIVE_APP,
349 kDriveAppActionID); 351 kDriveAppActionID);
350 GURL icon_url = drive::util::FindPreferredIcon( 352 GURL icon_url = drive::util::FindPreferredIcon(
351 app_info.app_icons, 353 app_info.app_icons,
352 drive::util::kPreferredIconSize); 354 drive::util::kPreferredIconSize);
353 result_list->push_back( 355 result_list->push_back(
354 FullTaskDescriptor(descriptor, 356 FullTaskDescriptor(descriptor,
355 app_info.app_name, 357 app_info.app_name,
356 icon_url, 358 icon_url,
357 false /* is_default */)); 359 false /* is_default */,
360 false /* is_generic_file_handler */));
358 } 361 }
359 } 362 }
360 363
364 bool IsGenericFileHandler(
365 const extensions::FileHandlerInfo& file_handler_info) {
366 return file_handler_info.extensions.count("*") > 0 ||
367 file_handler_info.types.count("*") > 0 ||
368 file_handler_info.types.count("*/*") > 0;
369 }
370
361 void FindFileHandlerTasks( 371 void FindFileHandlerTasks(
362 Profile* profile, 372 Profile* profile,
363 const PathAndMimeTypeSet& path_mime_set, 373 const PathAndMimeTypeSet& path_mime_set,
364 std::vector<FullTaskDescriptor>* result_list) { 374 std::vector<FullTaskDescriptor>* result_list) {
365 DCHECK(!path_mime_set.empty()); 375 DCHECK(!path_mime_set.empty());
366 DCHECK(result_list); 376 DCHECK(result_list);
367 377
368 const extensions::ExtensionSet& enabled_extensions = 378 const extensions::ExtensionSet& enabled_extensions =
369 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); 379 extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
380
370 for (extensions::ExtensionSet::const_iterator iter = 381 for (extensions::ExtensionSet::const_iterator iter =
371 enabled_extensions.begin(); 382 enabled_extensions.begin();
372 iter != enabled_extensions.end(); 383 iter != enabled_extensions.end();
373 ++iter) { 384 ++iter) {
374 const Extension* extension = iter->get(); 385 const Extension* extension = iter->get();
375 386
376 // Check that the extension can be launched via an event. This includes all 387 // Check that the extension can be launched via an event. This includes all
377 // platform apps plus whitelisted extensions. 388 // platform apps plus whitelisted extensions.
378 if (!CanLaunchViaEvent(extension)) 389 if (!CanLaunchViaEvent(extension))
379 continue; 390 continue;
(...skipping 13 matching lines...) Expand all
393 continue; 404 continue;
394 405
395 // If the new ZIP unpacker is disabled, then hide its handlers, so we don't 406 // If the new ZIP unpacker is disabled, then hide its handlers, so we don't
396 // show both the legacy one and the new one in Files app for ZIP files. 407 // show both the legacy one and the new one in Files app for ZIP files.
397 if (extension->id() == extension_misc::kZIPUnpackerExtensionId && 408 if (extension->id() == extension_misc::kZIPUnpackerExtensionId &&
398 CommandLine::ForCurrentProcess()->HasSwitch( 409 CommandLine::ForCurrentProcess()->HasSwitch(
399 chromeos::switches::kDisableNewZIPUnpacker)) { 410 chromeos::switches::kDisableNewZIPUnpacker)) {
400 continue; 411 continue;
401 } 412 }
402 413
403 // Only show the first matching handler from each app. 414 // Show the first matching non-generic handler of each app. If there doesn't
404 const extensions::FileHandlerInfo* file_handler = file_handlers.front(); 415 // exist such handler, show the first matching handler of the app.
416 const extensions::FileHandlerInfo* file_handler = nullptr;
417 for (auto handler : file_handlers) {
418 if (!IsGenericFileHandler(*handler)) {
419 file_handler = handler;
420 break;
421 }
422 }
423 if (file_handler == nullptr) {
424 file_handler = file_handlers.front();
425 }
426
405 std::string task_id = file_tasks::MakeTaskID( 427 std::string task_id = file_tasks::MakeTaskID(
406 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id); 428 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id);
407 429
408 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( 430 GURL best_icon = extensions::ExtensionIconSource::GetIconURL(
409 extension, 431 extension,
410 drive::util::kPreferredIconSize, 432 drive::util::kPreferredIconSize,
411 ExtensionIconSet::MATCH_BIGGER, 433 ExtensionIconSet::MATCH_BIGGER,
412 false, // grayscale 434 false, // grayscale
413 NULL); // exists 435 NULL); // exists
414 436
415 result_list->push_back( 437 result_list->push_back(
416 FullTaskDescriptor(TaskDescriptor(extension->id(), 438 FullTaskDescriptor(TaskDescriptor(extension->id(),
417 file_tasks::TASK_TYPE_FILE_HANDLER, 439 file_tasks::TASK_TYPE_FILE_HANDLER,
418 file_handler->id), 440 file_handler->id),
419 extension->name(), 441 extension->name(),
420 best_icon, 442 best_icon,
421 false /* is_default */)); 443 false /* is_default */,
444 IsGenericFileHandler(*file_handler)));
422 } 445 }
423 } 446 }
424 447
425 void FindFileBrowserHandlerTasks( 448 void FindFileBrowserHandlerTasks(
426 Profile* profile, 449 Profile* profile,
427 const std::vector<GURL>& file_urls, 450 const std::vector<GURL>& file_urls,
428 std::vector<FullTaskDescriptor>* result_list) { 451 std::vector<FullTaskDescriptor>* result_list) {
429 DCHECK(!file_urls.empty()); 452 DCHECK(!file_urls.empty());
430 DCHECK(result_list); 453 DCHECK(result_list);
431 454
(...skipping 21 matching lines...) Expand all
453 ExtensionIconSet::MATCH_BIGGER, 476 ExtensionIconSet::MATCH_BIGGER,
454 false, // grayscale 477 false, // grayscale
455 NULL); // exists 478 NULL); // exists
456 479
457 result_list->push_back(FullTaskDescriptor( 480 result_list->push_back(FullTaskDescriptor(
458 TaskDescriptor(extension_id, 481 TaskDescriptor(extension_id,
459 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, 482 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER,
460 handler->id()), 483 handler->id()),
461 handler->title(), 484 handler->title(),
462 icon_url, 485 icon_url,
463 false /* is_default */)); 486 false /* is_default */,
487 false /* is_generic_file_handler */));
464 } 488 }
465 } 489 }
466 490
467 void FindAllTypesOfTasks( 491 void FindAllTypesOfTasks(
468 Profile* profile, 492 Profile* profile,
469 const drive::DriveAppRegistry* drive_app_registry, 493 const drive::DriveAppRegistry* drive_app_registry,
470 const PathAndMimeTypeSet& path_mime_set, 494 const PathAndMimeTypeSet& path_mime_set,
471 const std::vector<GURL>& file_urls, 495 const std::vector<GURL>& file_urls,
472 std::vector<FullTaskDescriptor>* result_list) { 496 std::vector<FullTaskDescriptor>* result_list) {
473 DCHECK(profile); 497 DCHECK(profile);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 DCHECK(!task->is_default()); 551 DCHECK(!task->is_default());
528 if (IsFallbackFileHandler(task->task_descriptor())) { 552 if (IsFallbackFileHandler(task->task_descriptor())) {
529 task->set_is_default(true); 553 task->set_is_default(true);
530 return; 554 return;
531 } 555 }
532 } 556 }
533 } 557 }
534 558
535 } // namespace file_tasks 559 } // namespace file_tasks
536 } // namespace file_manager 560 } // 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