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

Side by Side Diff: chrome/browser/extensions/external_provider_impl.cc

Issue 2294653002: Some linked_ptr -> unique_ptr conversion in extensions/browser. (Closed)
Patch Set: address comments Created 4 years, 3 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
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/extensions/external_provider_impl.h" 5 #include "chrome/browser/extensions/external_provider_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/linked_ptr.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/trace_event/trace_event.h" 19 #include "base/trace_event/trace_event.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "base/version.h" 21 #include "base/version.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "chrome/browser/app_mode/app_mode_utils.h" 23 #include "chrome/browser/app_mode/app_mode_utils.h"
24 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/browser_process_platform_part.h" 25 #include "chrome/browser/browser_process_platform_part.h"
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 external_loader = new ExternalPolicyLoader( 523 external_loader = new ExternalPolicyLoader(
524 ExtensionManagementFactory::GetForBrowserContext(profile), 524 ExtensionManagementFactory::GetForBrowserContext(profile),
525 ExternalPolicyLoader::FORCED); 525 ExternalPolicyLoader::FORCED);
526 external_recommended_loader = new ExternalPolicyLoader( 526 external_recommended_loader = new ExternalPolicyLoader(
527 ExtensionManagementFactory::GetForBrowserContext(profile), 527 ExtensionManagementFactory::GetForBrowserContext(profile),
528 ExternalPolicyLoader::RECOMMENDED); 528 ExternalPolicyLoader::RECOMMENDED);
529 #endif 529 #endif
530 530
531 // Policies are mandatory so they can't be skipped with command line flag. 531 // Policies are mandatory so they can't be skipped with command line flag.
532 if (external_loader.get()) { 532 if (external_loader.get()) {
533 provider_list->push_back( 533 provider_list->push_back(base::MakeUnique<ExternalProviderImpl>(
534 linked_ptr<ExternalProviderInterface>( 534 service, external_loader, profile, crx_location,
535 new ExternalProviderImpl( 535 Manifest::EXTERNAL_POLICY_DOWNLOAD, Extension::NO_FLAGS));
536 service,
537 external_loader,
538 profile,
539 crx_location,
540 Manifest::EXTERNAL_POLICY_DOWNLOAD,
541 Extension::NO_FLAGS)));
542 } 536 }
543 537
544 // Load the KioskAppExternalProvider when running in kiosk mode. 538 // Load the KioskAppExternalProvider when running in kiosk mode.
545 if (chrome::IsRunningInForcedAppMode()) { 539 if (chrome::IsRunningInForcedAppMode()) {
546 #if defined(OS_CHROMEOS) 540 #if defined(OS_CHROMEOS)
547 chromeos::KioskAppManager* kiosk_app_manager = 541 chromeos::KioskAppManager* kiosk_app_manager =
548 chromeos::KioskAppManager::Get(); 542 chromeos::KioskAppManager::Get();
549 CHECK(kiosk_app_manager); 543 CHECK(kiosk_app_manager);
550 544
551 // Kiosk primary app external provider. 545 // Kiosk primary app external provider.
552 if (!kiosk_app_manager->external_loader_created()) { 546 if (!kiosk_app_manager->external_loader_created()) {
553 // For enterprise managed kiosk apps, change the location to 547 // For enterprise managed kiosk apps, change the location to
554 // "force-installed by policy". 548 // "force-installed by policy".
555 policy::BrowserPolicyConnectorChromeOS* const connector = 549 policy::BrowserPolicyConnectorChromeOS* const connector =
556 g_browser_process->platform_part() 550 g_browser_process->platform_part()
557 ->browser_policy_connector_chromeos(); 551 ->browser_policy_connector_chromeos();
558 Manifest::Location location = Manifest::EXTERNAL_PREF; 552 Manifest::Location location = Manifest::EXTERNAL_PREF;
559 if (connector && connector->IsEnterpriseManaged()) 553 if (connector && connector->IsEnterpriseManaged())
560 location = Manifest::EXTERNAL_POLICY; 554 location = Manifest::EXTERNAL_POLICY;
561 555
562 std::unique_ptr<ExternalProviderImpl> kiosk_app_provider( 556 std::unique_ptr<ExternalProviderImpl> kiosk_app_provider(
563 new ExternalProviderImpl( 557 new ExternalProviderImpl(
564 service, kiosk_app_manager->CreateExternalLoader(), profile, 558 service, kiosk_app_manager->CreateExternalLoader(), profile,
565 location, Manifest::INVALID_LOCATION, Extension::NO_FLAGS)); 559 location, Manifest::INVALID_LOCATION, Extension::NO_FLAGS));
566 kiosk_app_provider->set_auto_acknowledge(true); 560 kiosk_app_provider->set_auto_acknowledge(true);
567 kiosk_app_provider->set_install_immediately(true); 561 kiosk_app_provider->set_install_immediately(true);
568 provider_list->push_back( 562 provider_list->push_back(std::move(kiosk_app_provider));
569 linked_ptr<ExternalProviderInterface>(kiosk_app_provider.release()));
570 } 563 }
571 564
572 // Kiosk secondary app external provider. 565 // Kiosk secondary app external provider.
573 if (!kiosk_app_manager->secondary_app_external_loader_created()) { 566 if (!kiosk_app_manager->secondary_app_external_loader_created()) {
574 std::unique_ptr<ExternalProviderImpl> secondary_kiosk_app_provider( 567 std::unique_ptr<ExternalProviderImpl> secondary_kiosk_app_provider(
575 new ExternalProviderImpl( 568 new ExternalProviderImpl(
576 service, kiosk_app_manager->CreateSecondaryAppExternalLoader(), 569 service, kiosk_app_manager->CreateSecondaryAppExternalLoader(),
577 profile, Manifest::EXTERNAL_PREF, 570 profile, Manifest::EXTERNAL_PREF,
578 Manifest::EXTERNAL_PREF_DOWNLOAD, Extension::NO_FLAGS)); 571 Manifest::EXTERNAL_PREF_DOWNLOAD, Extension::NO_FLAGS));
579 secondary_kiosk_app_provider->set_auto_acknowledge(true); 572 secondary_kiosk_app_provider->set_auto_acknowledge(true);
580 secondary_kiosk_app_provider->set_install_immediately(true); 573 secondary_kiosk_app_provider->set_install_immediately(true);
581 provider_list->push_back(linked_ptr<ExternalProviderInterface>( 574 provider_list->push_back(std::move(secondary_kiosk_app_provider));
582 secondary_kiosk_app_provider.release()));
583 } 575 }
584 #endif 576 #endif
585 return; 577 return;
586 } 578 }
587 579
588 // Extensions provided by recommended policies. 580 // Extensions provided by recommended policies.
589 if (external_recommended_loader.get()) { 581 if (external_recommended_loader.get()) {
590 provider_list->push_back(linked_ptr<ExternalProviderInterface>( 582 provider_list->push_back(base::MakeUnique<ExternalProviderImpl>(
591 new ExternalProviderImpl(service, 583 service, external_recommended_loader, profile, crx_location,
592 external_recommended_loader, 584 Manifest::EXTERNAL_PREF_DOWNLOAD, Extension::NO_FLAGS));
593 profile,
594 crx_location,
595 Manifest::EXTERNAL_PREF_DOWNLOAD,
596 Extension::NO_FLAGS)));
597 } 585 }
598 586
599 // In tests don't install extensions from default external sources. 587 // In tests don't install extensions from default external sources.
600 // It would only slowdown tests and make them flaky. 588 // It would only slowdown tests and make them flaky.
601 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 589 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
602 switches::kDisableDefaultApps)) 590 switches::kDisableDefaultApps))
603 return; 591 return;
604 592
605 // On Mac OS, items in /Library/... should be written by the superuser. 593 // On Mac OS, items in /Library/... should be written by the superuser.
606 // Check that all components of the path are writable by root only. 594 // Check that all components of the path are writable by root only.
(...skipping 13 matching lines...) Expand all
620 Extension::WAS_INSTALLED_BY_DEFAULT; 608 Extension::WAS_INSTALLED_BY_DEFAULT;
621 609
622 if (!is_chrome_os_public_session) { 610 if (!is_chrome_os_public_session) {
623 int external_apps_path_id = profile->IsSupervised() ? 611 int external_apps_path_id = profile->IsSupervised() ?
624 chrome::DIR_SUPERVISED_USERS_DEFAULT_APPS : 612 chrome::DIR_SUPERVISED_USERS_DEFAULT_APPS :
625 chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS; 613 chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS;
626 ExternalPrefLoader::Options pref_load_flags = 614 ExternalPrefLoader::Options pref_load_flags =
627 profile->IsNewProfile() 615 profile->IsNewProfile()
628 ? ExternalPrefLoader::DELAY_LOAD_UNTIL_PRIORITY_SYNC 616 ? ExternalPrefLoader::DELAY_LOAD_UNTIL_PRIORITY_SYNC
629 : ExternalPrefLoader::NONE; 617 : ExternalPrefLoader::NONE;
630 provider_list->push_back( 618 provider_list->push_back(base::MakeUnique<ExternalProviderImpl>(
631 linked_ptr<ExternalProviderInterface>(new ExternalProviderImpl( 619 service,
632 service, new ExternalPrefLoader(external_apps_path_id, 620 new ExternalPrefLoader(external_apps_path_id, pref_load_flags, profile),
633 pref_load_flags, profile), 621 profile, Manifest::EXTERNAL_PREF, Manifest::EXTERNAL_PREF_DOWNLOAD,
634 profile, Manifest::EXTERNAL_PREF, Manifest::EXTERNAL_PREF_DOWNLOAD, 622 bundled_extension_creation_flags));
635 bundled_extension_creation_flags)));
636 623
637 // OEM default apps. 624 // OEM default apps.
638 int oem_extension_creation_flags = 625 int oem_extension_creation_flags =
639 bundled_extension_creation_flags | Extension::WAS_INSTALLED_BY_OEM; 626 bundled_extension_creation_flags | Extension::WAS_INSTALLED_BY_OEM;
640 chromeos::ServicesCustomizationDocument* customization = 627 chromeos::ServicesCustomizationDocument* customization =
641 chromeos::ServicesCustomizationDocument::GetInstance(); 628 chromeos::ServicesCustomizationDocument::GetInstance();
642 provider_list->push_back(linked_ptr<ExternalProviderInterface>( 629 provider_list->push_back(base::MakeUnique<ExternalProviderImpl>(
643 new ExternalProviderImpl(service, 630 service, customization->CreateExternalLoader(profile), profile,
644 customization->CreateExternalLoader(profile), 631 Manifest::EXTERNAL_PREF, Manifest::EXTERNAL_PREF_DOWNLOAD,
645 profile, 632 oem_extension_creation_flags));
646 Manifest::EXTERNAL_PREF,
647 Manifest::EXTERNAL_PREF_DOWNLOAD,
648 oem_extension_creation_flags)));
649 } 633 }
650 #elif defined(OS_LINUX) 634 #elif defined(OS_LINUX)
651 if (!profile->IsLegacySupervised()) { 635 if (!profile->IsLegacySupervised()) {
652 provider_list->push_back( 636 provider_list->push_back(base::MakeUnique<ExternalProviderImpl>(
653 linked_ptr<ExternalProviderInterface>( 637 service,
654 new ExternalProviderImpl( 638 new ExternalPrefLoader(chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS,
655 service, 639 ExternalPrefLoader::NONE, nullptr),
656 new ExternalPrefLoader( 640 profile, Manifest::EXTERNAL_PREF, Manifest::EXTERNAL_PREF_DOWNLOAD,
657 chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, 641 bundled_extension_creation_flags));
658 ExternalPrefLoader::NONE,
659 NULL),
660 profile,
661 Manifest::EXTERNAL_PREF,
662 Manifest::EXTERNAL_PREF_DOWNLOAD,
663 bundled_extension_creation_flags)));
664 } 642 }
665 #endif 643 #endif
666 644
667 if (!profile->IsLegacySupervised()) { 645 if (!profile->IsLegacySupervised()) {
668 #if defined(OS_WIN) 646 #if defined(OS_WIN)
669 provider_list->push_back( 647 provider_list->push_back(base::MakeUnique<ExternalProviderImpl>(
670 linked_ptr<ExternalProviderInterface>( 648 service, new ExternalRegistryLoader, profile,
671 new ExternalProviderImpl( 649 Manifest::EXTERNAL_REGISTRY, Manifest::EXTERNAL_PREF_DOWNLOAD,
672 service, 650 Extension::NO_FLAGS));
673 new ExternalRegistryLoader,
674 profile,
675 Manifest::EXTERNAL_REGISTRY,
676 Manifest::EXTERNAL_PREF_DOWNLOAD,
677 Extension::NO_FLAGS)));
678 #else 651 #else
679 provider_list->push_back( 652 provider_list->push_back(base::MakeUnique<ExternalProviderImpl>(
680 linked_ptr<ExternalProviderInterface>( 653 service,
681 new ExternalProviderImpl( 654 new ExternalPrefLoader(chrome::DIR_EXTERNAL_EXTENSIONS,
682 service, 655 check_admin_permissions_on_mac, nullptr),
683 new ExternalPrefLoader(chrome::DIR_EXTERNAL_EXTENSIONS, 656 profile, Manifest::EXTERNAL_PREF, Manifest::EXTERNAL_PREF_DOWNLOAD,
684 check_admin_permissions_on_mac, 657 bundled_extension_creation_flags));
685 NULL),
686 profile,
687 Manifest::EXTERNAL_PREF,
688 Manifest::EXTERNAL_PREF_DOWNLOAD,
689 bundled_extension_creation_flags)));
690 658
691 // Define a per-user source of external extensions. 659 // Define a per-user source of external extensions.
692 #if defined(OS_MACOSX) || (defined(OS_LINUX) && defined(CHROMIUM_BUILD)) 660 #if defined(OS_MACOSX) || (defined(OS_LINUX) && defined(CHROMIUM_BUILD))
693 provider_list->push_back( 661 provider_list->push_back(base::MakeUnique<ExternalProviderImpl>(
694 linked_ptr<ExternalProviderInterface>( 662 service, new ExternalPrefLoader(chrome::DIR_USER_EXTERNAL_EXTENSIONS,
695 new ExternalProviderImpl( 663 ExternalPrefLoader::NONE, nullptr),
696 service, 664 profile, Manifest::EXTERNAL_PREF, Manifest::EXTERNAL_PREF_DOWNLOAD,
697 new ExternalPrefLoader(chrome::DIR_USER_EXTERNAL_EXTENSIONS, 665 Extension::NO_FLAGS));
698 ExternalPrefLoader::NONE,
699 NULL),
700 profile,
701 Manifest::EXTERNAL_PREF,
702 Manifest::EXTERNAL_PREF_DOWNLOAD,
703 Extension::NO_FLAGS)));
704 #endif 666 #endif
705 #endif 667 #endif
706 668
707 #if !defined(OS_CHROMEOS) 669 #if !defined(OS_CHROMEOS)
708 // The default apps are installed as INTERNAL but use the external 670 // The default apps are installed as INTERNAL but use the external
709 // extension installer codeflow. 671 // extension installer codeflow.
710 provider_list->push_back( 672 provider_list->push_back(base::MakeUnique<default_apps::Provider>(
711 linked_ptr<ExternalProviderInterface>( 673 profile, service,
712 new default_apps::Provider( 674 new ExternalPrefLoader(chrome::DIR_DEFAULT_APPS,
713 profile, 675 ExternalPrefLoader::NONE, nullptr),
714 service, 676 Manifest::INTERNAL, Manifest::INTERNAL,
715 new ExternalPrefLoader(chrome::DIR_DEFAULT_APPS, 677 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT));
716 ExternalPrefLoader::NONE,
717 NULL),
718 Manifest::INTERNAL,
719 Manifest::INTERNAL,
720 Extension::FROM_WEBSTORE |
721 Extension::WAS_INSTALLED_BY_DEFAULT)));
722 #endif 678 #endif
723 679
724 std::unique_ptr<ExternalProviderImpl> drive_migration_provider( 680 std::unique_ptr<ExternalProviderImpl> drive_migration_provider(
725 new ExternalProviderImpl( 681 new ExternalProviderImpl(
726 service, 682 service,
727 new ExtensionMigrator(profile, extension_misc::kDriveHostedAppId, 683 new ExtensionMigrator(profile, extension_misc::kDriveHostedAppId,
728 extension_misc::kDriveExtensionId), 684 extension_misc::kDriveExtensionId),
729 profile, Manifest::EXTERNAL_PREF, Manifest::EXTERNAL_PREF_DOWNLOAD, 685 profile, Manifest::EXTERNAL_PREF, Manifest::EXTERNAL_PREF_DOWNLOAD,
730 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT)); 686 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT));
731 drive_migration_provider->set_auto_acknowledge(true); 687 drive_migration_provider->set_auto_acknowledge(true);
732 provider_list->push_back(linked_ptr<ExternalProviderInterface>( 688 provider_list->push_back(std::move(drive_migration_provider));
733 drive_migration_provider.release()));
734 } 689 }
735 690
736 provider_list->push_back( 691 provider_list->push_back(base::MakeUnique<ExternalProviderImpl>(
737 linked_ptr<ExternalProviderInterface>( 692 service, new ExternalComponentLoader(profile), profile,
738 new ExternalProviderImpl( 693 Manifest::INVALID_LOCATION, Manifest::EXTERNAL_COMPONENT,
739 service, 694 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT));
740 new ExternalComponentLoader(profile),
741 profile,
742 Manifest::INVALID_LOCATION,
743 Manifest::EXTERNAL_COMPONENT,
744 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT)));
745 } 695 }
746 696
747 } // namespace extensions 697 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698