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

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

Issue 2925973002: Migrate upgrade notifications to observer (Closed)
Patch Set: Add DISALLOW_COPY_AND_ASSIGN 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 *command_line, profile)) 345 *command_line, profile))
345 extensions_enabled_ = false; 346 extensions_enabled_ = false;
346 347
347 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, 348 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
348 content::NotificationService::AllBrowserContextsAndSources()); 349 content::NotificationService::AllBrowserContextsAndSources());
349 registrar_.Add(this, 350 registrar_.Add(this,
350 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 351 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
351 content::NotificationService::AllBrowserContextsAndSources()); 352 content::NotificationService::AllBrowserContextsAndSources());
352 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 353 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
353 content::NotificationService::AllBrowserContextsAndSources()); 354 content::NotificationService::AllBrowserContextsAndSources());
354 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
355 content::NotificationService::AllBrowserContextsAndSources());
356 registrar_.Add(this, 355 registrar_.Add(this,
357 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 356 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
358 content::Source<Profile>(profile_)); 357 content::Source<Profile>(profile_));
359 358
359 UpgradeDetector::GetInstance()->AddObserver(this);
360
360 extensions::ExtensionManagementFactory::GetForBrowserContext(profile_) 361 extensions::ExtensionManagementFactory::GetForBrowserContext(profile_)
361 ->AddObserver(this); 362 ->AddObserver(this);
362 363
363 // Set up the ExtensionUpdater. 364 // Set up the ExtensionUpdater.
364 if (autoupdate_enabled) { 365 if (autoupdate_enabled) {
365 int update_frequency = extensions::kDefaultUpdateFrequencySeconds; 366 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
366 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { 367 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
367 base::StringToInt(command_line->GetSwitchValueASCII( 368 base::StringToInt(command_line->GetSwitchValueASCII(
368 switches::kExtensionsUpdateFrequency), 369 switches::kExtensionsUpdateFrequency),
369 &update_frequency); 370 &update_frequency);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength", 407 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
407 install_directory_.value().length(), 1, 500, 100); 408 install_directory_.value().length(), 1, 500, 100);
408 } 409 }
409 410
410 extensions::PendingExtensionManager* 411 extensions::PendingExtensionManager*
411 ExtensionService::pending_extension_manager() { 412 ExtensionService::pending_extension_manager() {
412 return &pending_extension_manager_; 413 return &pending_extension_manager_;
413 } 414 }
414 415
415 ExtensionService::~ExtensionService() { 416 ExtensionService::~ExtensionService() {
417 UpgradeDetector::GetInstance()->RemoveObserver(this);
416 // No need to unload extensions here because they are profile-scoped, and the 418 // No need to unload extensions here because they are profile-scoped, and the
417 // profile is in the process of being deleted. 419 // profile is in the process of being deleted.
418 for (const auto& provider : external_extension_providers_) 420 for (const auto& provider : external_extension_providers_)
419 provider->ServiceShutdown(); 421 provider->ServiceShutdown();
420 } 422 }
421 423
422 void ExtensionService::Shutdown() { 424 void ExtensionService::Shutdown() {
423 extensions::ExtensionManagementFactory::GetInstance() 425 extensions::ExtensionManagementFactory::GetInstance()
424 ->GetForBrowserContext(profile()) 426 ->GetForBrowserContext(profile())
425 ->RemoveObserver(this); 427 ->RemoveObserver(this);
(...skipping 1815 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2576 2578
2577 if (!has_orphaned_dev_tools && !is_component_extension) 2579 if (!has_orphaned_dev_tools && !is_component_extension)
2578 return; 2580 return;
2579 2581
2580 // Wake up the event page by posting a dummy task. 2582 // Wake up the event page by posting a dummy task.
2581 extensions::LazyBackgroundTaskQueue* queue = 2583 extensions::LazyBackgroundTaskQueue* queue =
2582 extensions::LazyBackgroundTaskQueue::Get(profile_); 2584 extensions::LazyBackgroundTaskQueue::Get(profile_);
2583 queue->AddPendingTask(profile_, extension->id(), 2585 queue->AddPendingTask(profile_, extension->id(),
2584 base::Bind(&DoNothingWithExtensionHost)); 2586 base::Bind(&DoNothingWithExtensionHost));
2585 } 2587 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/service_process/service_process_control.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698