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

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

Issue 2925973002: Migrate upgrade notifications to observer (Closed)
Patch Set: Clean up code Created 3 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "chrome/browser/extensions/shared_module_service.h" 53 #include "chrome/browser/extensions/shared_module_service.h"
54 #include "chrome/browser/extensions/unpacked_installer.h" 54 #include "chrome/browser/extensions/unpacked_installer.h"
55 #include "chrome/browser/extensions/updater/chrome_extension_downloader_factory. h" 55 #include "chrome/browser/extensions/updater/chrome_extension_downloader_factory. h"
56 #include "chrome/browser/extensions/updater/extension_updater.h" 56 #include "chrome/browser/extensions/updater/extension_updater.h"
57 #include "chrome/browser/google/google_brand.h" 57 #include "chrome/browser/google/google_brand.h"
58 #include "chrome/browser/profiles/profile.h" 58 #include "chrome/browser/profiles/profile.h"
59 #include "chrome/browser/search/thumbnail_source.h" 59 #include "chrome/browser/search/thumbnail_source.h"
60 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 60 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
61 #include "chrome/browser/ui/webui/favicon_source.h" 61 #include "chrome/browser/ui/webui/favicon_source.h"
62 #include "chrome/browser/ui/webui/theme_source.h" 62 #include "chrome/browser/ui/webui/theme_source.h"
63 #include "chrome/browser/upgrade_detector.h"
63 #include "chrome/common/chrome_switches.h" 64 #include "chrome/common/chrome_switches.h"
64 #include "chrome/common/crash_keys.h" 65 #include "chrome/common/crash_keys.h"
65 #include "chrome/common/extensions/extension_constants.h" 66 #include "chrome/common/extensions/extension_constants.h"
66 #include "chrome/common/features.h" 67 #include "chrome/common/features.h"
67 #include "chrome/common/url_constants.h" 68 #include "chrome/common/url_constants.h"
68 #include "components/content_settings/core/browser/host_content_settings_map.h" 69 #include "components/content_settings/core/browser/host_content_settings_map.h"
69 #include "components/crx_file/id_util.h" 70 #include "components/crx_file/id_util.h"
70 #include "content/public/browser/devtools_agent_host.h" 71 #include "content/public/browser/devtools_agent_host.h"
71 #include "content/public/browser/notification_service.h" 72 #include "content/public/browser/notification_service.h"
72 #include "content/public/browser/render_process_host.h" 73 #include "content/public/browser/render_process_host.h"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 *command_line, profile)) 341 *command_line, profile))
341 extensions_enabled_ = false; 342 extensions_enabled_ = false;
342 343
343 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, 344 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
344 content::NotificationService::AllBrowserContextsAndSources()); 345 content::NotificationService::AllBrowserContextsAndSources());
345 registrar_.Add(this, 346 registrar_.Add(this,
346 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 347 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
347 content::NotificationService::AllBrowserContextsAndSources()); 348 content::NotificationService::AllBrowserContextsAndSources());
348 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 349 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
349 content::NotificationService::AllBrowserContextsAndSources()); 350 content::NotificationService::AllBrowserContextsAndSources());
350 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
351 content::NotificationService::AllBrowserContextsAndSources());
352 registrar_.Add(this, 351 registrar_.Add(this,
353 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 352 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
354 content::Source<Profile>(profile_)); 353 content::Source<Profile>(profile_));
355 354
355 UpgradeDetector::GetInstance()->AddObserver(this);
356
356 extensions::ExtensionManagementFactory::GetForBrowserContext(profile_) 357 extensions::ExtensionManagementFactory::GetForBrowserContext(profile_)
357 ->AddObserver(this); 358 ->AddObserver(this);
358 359
359 // Set up the ExtensionUpdater. 360 // Set up the ExtensionUpdater.
360 if (autoupdate_enabled) { 361 if (autoupdate_enabled) {
361 int update_frequency = extensions::kDefaultUpdateFrequencySeconds; 362 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
362 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { 363 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
363 base::StringToInt(command_line->GetSwitchValueASCII( 364 base::StringToInt(command_line->GetSwitchValueASCII(
364 switches::kExtensionsUpdateFrequency), 365 switches::kExtensionsUpdateFrequency),
365 &update_frequency); 366 &update_frequency);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength", 403 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
403 install_directory_.value().length(), 1, 500, 100); 404 install_directory_.value().length(), 1, 500, 100);
404 } 405 }
405 406
406 extensions::PendingExtensionManager* 407 extensions::PendingExtensionManager*
407 ExtensionService::pending_extension_manager() { 408 ExtensionService::pending_extension_manager() {
408 return &pending_extension_manager_; 409 return &pending_extension_manager_;
409 } 410 }
410 411
411 ExtensionService::~ExtensionService() { 412 ExtensionService::~ExtensionService() {
413 UpgradeDetector::GetInstance()->RemoveObserver(this);
412 // No need to unload extensions here because they are profile-scoped, and the 414 // No need to unload extensions here because they are profile-scoped, and the
413 // profile is in the process of being deleted. 415 // profile is in the process of being deleted.
414 for (const auto& provider : external_extension_providers_) 416 for (const auto& provider : external_extension_providers_)
415 provider->ServiceShutdown(); 417 provider->ServiceShutdown();
416 } 418 }
417 419
418 void ExtensionService::Shutdown() { 420 void ExtensionService::Shutdown() {
419 extensions::ExtensionManagementFactory::GetInstance() 421 extensions::ExtensionManagementFactory::GetInstance()
420 ->GetForBrowserContext(profile()) 422 ->GetForBrowserContext(profile())
421 ->RemoveObserver(this); 423 ->RemoveObserver(this);
(...skipping 1819 matching lines...) Expand 10 before | Expand all | Expand 10 after
2241 } 2243 }
2242 } 2244 }
2243 2245
2244 process_map->RemoveAllFromProcess(process->GetID()); 2246 process_map->RemoveAllFromProcess(process->GetID());
2245 BrowserThread::PostTask( 2247 BrowserThread::PostTask(
2246 BrowserThread::IO, FROM_HERE, 2248 BrowserThread::IO, FROM_HERE,
2247 base::BindOnce(&extensions::InfoMap::UnregisterAllExtensionsInProcess, 2249 base::BindOnce(&extensions::InfoMap::UnregisterAllExtensionsInProcess,
2248 system_->info_map(), process->GetID())); 2250 system_->info_map(), process->GetID()));
2249 break; 2251 break;
2250 } 2252 }
2251 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
2252 // Notify observers that chrome update is available.
2253 for (auto& observer : update_observers_)
2254 observer.OnChromeUpdateAvailable();
2255 break;
2256 }
2257 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: { 2253 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
2258 OnProfileDestructionStarted(); 2254 OnProfileDestructionStarted();
2259 break; 2255 break;
2260 } 2256 }
2261 2257
2262 default: 2258 default:
2263 NOTREACHED() << "Unexpected notification type."; 2259 NOTREACHED() << "Unexpected notification type.";
2264 } 2260 }
2265 } 2261 }
2266 2262
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 MaybeFinishDelayedInstallation(extension_id); 2348 MaybeFinishDelayedInstallation(extension_id);
2353 } 2349 }
2354 } 2350 }
2355 2351
2356 void ExtensionService::OnBlacklistUpdated() { 2352 void ExtensionService::OnBlacklistUpdated() {
2357 blacklist_->GetBlacklistedIDs( 2353 blacklist_->GetBlacklistedIDs(
2358 registry_->GenerateInstalledExtensionsSet()->GetIDs(), 2354 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
2359 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr())); 2355 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
2360 } 2356 }
2361 2357
2358 void ExtensionService::OnUpgradeRecommended() {
2359 // Notify observers that chrome update is available.
2360 for (auto& observer : update_observers_)
2361 observer.OnChromeUpdateAvailable();
2362 }
2363
2362 void ExtensionService::ManageBlacklist( 2364 void ExtensionService::ManageBlacklist(
2363 const extensions::Blacklist::BlacklistStateMap& state_map) { 2365 const extensions::Blacklist::BlacklistStateMap& state_map) {
2364 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2366 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2365 2367
2366 std::set<std::string> blacklisted; 2368 std::set<std::string> blacklisted;
2367 ExtensionIdSet greylist; 2369 ExtensionIdSet greylist;
2368 ExtensionIdSet unchanged; 2370 ExtensionIdSet unchanged;
2369 for (const auto& it : state_map) { 2371 for (const auto& it : state_map) {
2370 switch (it.second) { 2372 switch (it.second) {
2371 case extensions::NOT_BLACKLISTED: 2373 case extensions::NOT_BLACKLISTED:
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 for (const auto& extension : registry_->disabled_extensions()) { 2552 for (const auto& extension : registry_->disabled_extensions()) {
2551 if (SharedModuleInfo::IsSharedModule(extension.get())) 2553 if (SharedModuleInfo::IsSharedModule(extension.get()))
2552 to_enable.push_back(extension); 2554 to_enable.push_back(extension);
2553 } 2555 }
2554 for (const auto& extension : to_enable) { 2556 for (const auto& extension : to_enable) {
2555 EnableExtension(extension->id()); 2557 EnableExtension(extension->id());
2556 } 2558 }
2557 2559
2558 OnBlacklistUpdated(); 2560 OnBlacklistUpdated();
2559 } 2561 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698