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

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

Issue 500043003: Add PolicyProvider to ExtensionManagement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-1
Patch Set: fixes to #3 Created 6 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/extension_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <set> 9 #include <set>
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 47 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
48 #include "chrome/browser/ui/webui/favicon_source.h" 48 #include "chrome/browser/ui/webui/favicon_source.h"
49 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" 49 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
50 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 50 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
51 #include "chrome/browser/ui/webui/theme_source.h" 51 #include "chrome/browser/ui/webui/theme_source.h"
52 #include "chrome/common/chrome_switches.h" 52 #include "chrome/common/chrome_switches.h"
53 #include "chrome/common/crash_keys.h" 53 #include "chrome/common/crash_keys.h"
54 #include "chrome/common/extensions/extension_constants.h" 54 #include "chrome/common/extensions/extension_constants.h"
55 #include "chrome/common/extensions/features/feature_channel.h" 55 #include "chrome/common/extensions/features/feature_channel.h"
56 #include "chrome/common/extensions/manifest_url_handler.h" 56 #include "chrome/common/extensions/manifest_url_handler.h"
57 #include "chrome/common/pref_names.h"
58 #include "chrome/common/url_constants.h" 57 #include "chrome/common/url_constants.h"
59 #include "components/crx_file/id_util.h" 58 #include "components/crx_file/id_util.h"
60 #include "components/signin/core/browser/signin_manager.h" 59 #include "components/signin/core/browser/signin_manager.h"
61 #include "components/startup_metric_utils/startup_metric_utils.h" 60 #include "components/startup_metric_utils/startup_metric_utils.h"
62 #include "content/public/browser/devtools_agent_host.h" 61 #include "content/public/browser/devtools_agent_host.h"
63 #include "content/public/browser/notification_service.h" 62 #include "content/public/browser/notification_service.h"
64 #include "content/public/browser/render_process_host.h" 63 #include "content/public/browser/render_process_host.h"
65 #include "content/public/browser/storage_partition.h" 64 #include "content/public/browser/storage_partition.h"
66 #include "extensions/browser/event_router.h" 65 #include "extensions/browser/event_router.h"
67 #include "extensions/browser/extension_host.h" 66 #include "extensions/browser/extension_host.h"
68 #include "extensions/browser/extension_prefs.h" 67 #include "extensions/browser/extension_prefs.h"
69 #include "extensions/browser/extension_registry.h" 68 #include "extensions/browser/extension_registry.h"
70 #include "extensions/browser/extension_system.h" 69 #include "extensions/browser/extension_system.h"
71 #include "extensions/browser/install_flag.h" 70 #include "extensions/browser/install_flag.h"
72 #include "extensions/browser/pref_names.h"
73 #include "extensions/browser/runtime_data.h" 71 #include "extensions/browser/runtime_data.h"
74 #include "extensions/browser/uninstall_reason.h" 72 #include "extensions/browser/uninstall_reason.h"
75 #include "extensions/browser/update_observer.h" 73 #include "extensions/browser/update_observer.h"
76 #include "extensions/common/extension_messages.h" 74 #include "extensions/common/extension_messages.h"
77 #include "extensions/common/feature_switch.h" 75 #include "extensions/common/feature_switch.h"
78 #include "extensions/common/file_util.h" 76 #include "extensions/common/file_util.h"
79 #include "extensions/common/manifest_constants.h" 77 #include "extensions/common/manifest_constants.h"
80 #include "extensions/common/manifest_handlers/background_info.h" 78 #include "extensions/common/manifest_handlers/background_info.h"
81 #include "extensions/common/one_shot_event.h" 79 #include "extensions/common/one_shot_event.h"
82 #include "extensions/common/permissions/permission_message_provider.h" 80 #include "extensions/common/permissions/permission_message_provider.h"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 registrar_.Add(this, 289 registrar_.Add(this,
292 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 290 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
293 content::NotificationService::AllBrowserContextsAndSources()); 291 content::NotificationService::AllBrowserContextsAndSources());
294 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 292 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
295 content::NotificationService::AllBrowserContextsAndSources()); 293 content::NotificationService::AllBrowserContextsAndSources());
296 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, 294 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
297 content::NotificationService::AllBrowserContextsAndSources()); 295 content::NotificationService::AllBrowserContextsAndSources());
298 registrar_.Add(this, 296 registrar_.Add(this,
299 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 297 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
300 content::Source<Profile>(profile_)); 298 content::Source<Profile>(profile_));
301 pref_change_registrar_.Init(profile->GetPrefs()); 299
302 base::Closure callback = 300 extensions::ExtensionManagementFactory::GetInstance()
303 base::Bind(&ExtensionService::OnExtensionInstallPrefChanged, 301 ->GetForBrowserContext(profile_)
304 base::Unretained(this)); 302 ->AddObserver(this);
305 pref_change_registrar_.Add(extensions::pref_names::kInstallAllowList,
306 callback);
307 pref_change_registrar_.Add(extensions::pref_names::kInstallDenyList,
308 callback);
309 pref_change_registrar_.Add(extensions::pref_names::kAllowedTypes, callback);
310 303
311 // Set up the ExtensionUpdater 304 // Set up the ExtensionUpdater
312 if (autoupdate_enabled) { 305 if (autoupdate_enabled) {
313 int update_frequency = extensions::kDefaultUpdateFrequencySeconds; 306 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
314 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { 307 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
315 base::StringToInt(command_line->GetSwitchValueASCII( 308 base::StringToInt(command_line->GetSwitchValueASCII(
316 switches::kExtensionsUpdateFrequency), 309 switches::kExtensionsUpdateFrequency),
317 &update_frequency); 310 &update_frequency);
318 } 311 }
319 updater_.reset(new extensions::ExtensionUpdater( 312 updater_.reset(new extensions::ExtensionUpdater(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 363
371 extensions::ProviderCollection::const_iterator i; 364 extensions::ProviderCollection::const_iterator i;
372 for (i = external_extension_providers_.begin(); 365 for (i = external_extension_providers_.begin();
373 i != external_extension_providers_.end(); ++i) { 366 i != external_extension_providers_.end(); ++i) {
374 extensions::ExternalProviderInterface* provider = i->get(); 367 extensions::ExternalProviderInterface* provider = i->get();
375 provider->ServiceShutdown(); 368 provider->ServiceShutdown();
376 } 369 }
377 } 370 }
378 371
379 void ExtensionService::Shutdown() { 372 void ExtensionService::Shutdown() {
373 extensions::ExtensionManagementFactory::GetInstance()
374 ->GetForBrowserContext(profile())
375 ->RemoveObserver(this);
380 system_->management_policy()->UnregisterProvider( 376 system_->management_policy()->UnregisterProvider(
381 shared_module_policy_provider_.get()); 377 shared_module_policy_provider_.get());
382 } 378 }
383 379
384 const Extension* ExtensionService::GetExtensionById( 380 const Extension* ExtensionService::GetExtensionById(
385 const std::string& id, bool include_disabled) const { 381 const std::string& id, bool include_disabled) const {
386 int include_mask = ExtensionRegistry::ENABLED; 382 int include_mask = ExtensionRegistry::ENABLED;
387 if (include_disabled) { 383 if (include_disabled) {
388 // Include blacklisted extensions here because there are hundreds of 384 // Include blacklisted extensions here because there are hundreds of
389 // callers of this function, and many might assume that this includes those 385 // callers of this function, and many might assume that this includes those
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 } 1721 }
1726 } else { 1722 } else {
1727 AddNewOrUpdatedExtension(extension, 1723 AddNewOrUpdatedExtension(extension,
1728 initial_state, 1724 initial_state,
1729 install_flags, 1725 install_flags,
1730 page_ordinal, 1726 page_ordinal,
1731 install_parameter); 1727 install_parameter);
1732 } 1728 }
1733 } 1729 }
1734 1730
1731 void ExtensionService::OnExtensionManagementSettingsChanged() {
1732 error_controller_->ShowErrorIfNeeded();
1733 CheckManagementPolicy();
1734 }
1735
1735 void ExtensionService::AddNewOrUpdatedExtension( 1736 void ExtensionService::AddNewOrUpdatedExtension(
1736 const Extension* extension, 1737 const Extension* extension,
1737 Extension::State initial_state, 1738 Extension::State initial_state,
1738 int install_flags, 1739 int install_flags,
1739 const syncer::StringOrdinal& page_ordinal, 1740 const syncer::StringOrdinal& page_ordinal,
1740 const std::string& install_parameter) { 1741 const std::string& install_parameter) {
1741 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1742 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1742 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id()); 1743 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
1743 extension_prefs_->OnExtensionInstalled( 1744 extension_prefs_->OnExtensionInstalled(
1744 extension, initial_state, page_ordinal, install_flags, install_parameter); 1745 extension, initial_state, page_ordinal, install_flags, install_parameter);
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
2111 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: { 2112 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
2112 OnProfileDestructionStarted(); 2113 OnProfileDestructionStarted();
2113 break; 2114 break;
2114 } 2115 }
2115 2116
2116 default: 2117 default:
2117 NOTREACHED() << "Unexpected notification type."; 2118 NOTREACHED() << "Unexpected notification type.";
2118 } 2119 }
2119 } 2120 }
2120 2121
2121 void ExtensionService::OnExtensionInstallPrefChanged() {
2122 error_controller_->ShowErrorIfNeeded();
2123 CheckManagementPolicy();
2124 }
2125
2126 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { 2122 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) {
2127 // Extensions installed by policy can't be disabled. So even if a previous 2123 // Extensions installed by policy can't be disabled. So even if a previous
2128 // installation disabled the extension, make sure it is now enabled. 2124 // installation disabled the extension, make sure it is now enabled.
2129 if (system_->management_policy()->MustRemainEnabled(extension, NULL)) 2125 if (system_->management_policy()->MustRemainEnabled(extension, NULL))
2130 return true; 2126 return true;
2131 2127
2132 if (extension_prefs_->IsExtensionDisabled(extension->id())) 2128 if (extension_prefs_->IsExtensionDisabled(extension->id()))
2133 return false; 2129 return false;
2134 2130
2135 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { 2131 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 } 2355 }
2360 2356
2361 void ExtensionService::OnProfileDestructionStarted() { 2357 void ExtensionService::OnProfileDestructionStarted() {
2362 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); 2358 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2363 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); 2359 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2364 it != ids_to_unload.end(); 2360 it != ids_to_unload.end();
2365 ++it) { 2361 ++it) {
2366 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); 2362 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2367 } 2363 }
2368 } 2364 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698