Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ui/ash/launcher/launcher_extension_app_updater.h" | 5 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | |
| 9 #include "chrome/common/extensions/extension_constants.h" | |
| 7 #include "extensions/browser/extension_registry.h" | 10 #include "extensions/browser/extension_registry.h" |
| 8 | 11 |
| 9 LauncherExtensionAppUpdater::LauncherExtensionAppUpdater( | 12 LauncherExtensionAppUpdater::LauncherExtensionAppUpdater( |
| 10 Delegate* delegate, | 13 Delegate* delegate, |
| 11 content::BrowserContext* browser_context) | 14 content::BrowserContext* browser_context) |
| 12 : LauncherAppUpdater(delegate, browser_context) { | 15 : LauncherAppUpdater(delegate, browser_context) { |
| 13 extensions::ExtensionRegistry::Get(browser_context)->AddObserver(this); | 16 StartObservingExtensionRegistry(); |
| 17 | |
| 18 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | |
| 19 // ArcAuthService may not be available for some unit tests. | |
| 20 if (arc_auth_service) | |
| 21 arc_auth_service->AddObserver(this); | |
| 14 } | 22 } |
| 15 | 23 |
| 16 LauncherExtensionAppUpdater::~LauncherExtensionAppUpdater() { | 24 LauncherExtensionAppUpdater::~LauncherExtensionAppUpdater() { |
| 17 extensions::ExtensionRegistry::Get(browser_context())->RemoveObserver(this); | 25 StopObservingExtensionRegistry(); |
| 26 | |
| 27 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | |
| 28 if (arc_auth_service) | |
| 29 arc_auth_service->RemoveObserver(this); | |
| 18 } | 30 } |
| 19 | 31 |
| 20 void LauncherExtensionAppUpdater::OnExtensionLoaded( | 32 void LauncherExtensionAppUpdater::OnExtensionLoaded( |
| 21 content::BrowserContext* browser_context, | 33 content::BrowserContext* browser_context, |
| 22 const extensions::Extension* extension) { | 34 const extensions::Extension* extension) { |
| 23 delegate()->OnAppInstalled(browser_context, extension->id()); | 35 delegate()->OnAppInstalled(browser_context, extension->id()); |
| 24 } | 36 } |
| 25 | 37 |
| 26 void LauncherExtensionAppUpdater::OnExtensionUnloaded( | 38 void LauncherExtensionAppUpdater::OnExtensionUnloaded( |
| 27 content::BrowserContext* browser_context, | 39 content::BrowserContext* browser_context, |
| 28 const extensions::Extension* extension, | 40 const extensions::Extension* extension, |
| 29 extensions::UnloadedExtensionInfo::Reason reason) { | 41 extensions::UnloadedExtensionInfo::Reason reason) { |
| 30 if (reason == extensions::UnloadedExtensionInfo::REASON_UNINSTALL) | 42 if (reason == extensions::UnloadedExtensionInfo::REASON_UNINSTALL) |
| 31 delegate()->OnAppUninstalled(browser_context, extension->id()); | 43 delegate()->OnAppUninstalled(browser_context, extension->id()); |
| 32 else | 44 else |
| 33 delegate()->OnAppUpdated(browser_context, extension->id()); | 45 delegate()->OnAppUpdated(browser_context, extension->id()); |
| 34 } | 46 } |
| 47 | |
| 48 void LauncherExtensionAppUpdater::OnExtensionUninstalled( | |
| 49 content::BrowserContext* browser_context, | |
| 50 const extensions::Extension* extension, | |
| 51 extensions::UninstallReason reason) { | |
| 52 if (reason == extensions::UNINSTALL_REASON_FOR_TESTING) | |
| 53 delegate()->OnAppUninstalled(browser_context, extension->id()); | |
| 54 } | |
| 55 | |
| 56 void LauncherExtensionAppUpdater::OnShutdown( | |
| 57 extensions::ExtensionRegistry* registry) { | |
| 58 DCHECK_EQ(extension_registry_, registry); | |
| 59 StopObservingExtensionRegistry(); | |
| 60 } | |
| 61 | |
| 62 void LauncherExtensionAppUpdater::OnOptInChanged( | |
| 63 arc::ArcAuthService::State state) { | |
| 64 if (!chromeos::ProfileHelper::IsPrimaryProfile( | |
| 65 Profile::FromBrowserContext(browser_context()))) { | |
| 66 return; | |
| 67 } | |
| 68 UpdateHostApps(); | |
| 69 } | |
| 70 | |
| 71 void LauncherExtensionAppUpdater::StartObservingExtensionRegistry() { | |
| 72 DCHECK(!extension_registry_); | |
| 73 extension_registry_ = extensions::ExtensionRegistry::Get(browser_context()); | |
| 74 extension_registry_->AddObserver(this); | |
| 75 } | |
| 76 | |
| 77 void LauncherExtensionAppUpdater::StopObservingExtensionRegistry() { | |
| 78 if (extension_registry_) | |
| 79 extension_registry_->RemoveObserver(this); | |
|
Mr4D (OOO till 08-26)
2016/06/15 23:03:23
you might do if (!extension_registry_) return; ..
| |
| 80 extension_registry_ = nullptr; | |
| 81 } | |
| 82 | |
| 83 void LauncherExtensionAppUpdater::UpdateHostApps() { | |
| 84 if (!extension_registry_) | |
| 85 return; | |
| 86 | |
| 87 UpdateHostApps(extension_registry_->enabled_extensions()); | |
| 88 UpdateHostApps(extension_registry_->disabled_extensions()); | |
| 89 UpdateHostApps(extension_registry_->terminated_extensions()); | |
| 90 UpdateHostApp(extension_misc::kChromeAppId); | |
| 91 } | |
| 92 | |
| 93 void LauncherExtensionAppUpdater::UpdateHostApps( | |
| 94 const extensions::ExtensionSet& extensions) { | |
| 95 content::BrowserContext* context = browser_context(); | |
| 96 extensions::ExtensionSet::const_iterator it; | |
| 97 for (it = extensions.begin(); it != extensions.end(); ++it) { | |
| 98 if ((*it)->is_hosted_app()) | |
| 99 delegate()->OnAppUpdated(context, (*it)->id()); | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 void LauncherExtensionAppUpdater::UpdateHostApp(const std::string& app_id) { | |
| 104 delegate()->OnAppUpdated(browser_context(), app_id); | |
| 105 } | |
| OLD | NEW |