Commit f6e1d60e authored by limasdf@gmail.com's avatar limasdf@gmail.com

Use ExtensionRegistry from app_sync_ui_state.*

BUG=354046

Review URL: https://codereview.chromium.org/403843005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284741 0039d316-1c4b-4281-b951-d872f2087c98
parent a6283237
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/browser/ui/ash/app_sync_ui_state.h" #include "chrome/browser/ui/ash/app_sync_ui_state.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/pending_extension_manager.h" #include "chrome/browser/extensions/pending_extension_manager.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -13,9 +12,7 @@ ...@@ -13,9 +12,7 @@
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/ash/app_sync_ui_state_factory.h" #include "chrome/browser/ui/ash/app_sync_ui_state_factory.h"
#include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h"
#include "content/public/browser/notification_details.h" #include "extensions/browser/extension_registry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -55,7 +52,8 @@ bool AppSyncUIState::ShouldObserveAppSyncForProfile(Profile* profile) { ...@@ -55,7 +52,8 @@ bool AppSyncUIState::ShouldObserveAppSyncForProfile(Profile* profile) {
AppSyncUIState::AppSyncUIState(Profile* profile) AppSyncUIState::AppSyncUIState(Profile* profile)
: profile_(profile), : profile_(profile),
sync_service_(NULL), sync_service_(NULL),
status_(STATUS_NORMAL) { status_(STATUS_NORMAL),
extension_registry_(NULL) {
StartObserving(); StartObserving();
} }
...@@ -74,10 +72,10 @@ void AppSyncUIState::RemoveObserver(AppSyncUIStateObserver* observer) { ...@@ -74,10 +72,10 @@ void AppSyncUIState::RemoveObserver(AppSyncUIStateObserver* observer) {
void AppSyncUIState::StartObserving() { void AppSyncUIState::StartObserving() {
DCHECK(ShouldObserveAppSyncForProfile(profile_)); DCHECK(ShouldObserveAppSyncForProfile(profile_));
DCHECK(!sync_service_); DCHECK(!sync_service_);
DCHECK(!extension_registry_);
registrar_.Add(this, extension_registry_ = extensions::ExtensionRegistry::Get(profile_);
chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, extension_registry_->AddObserver(this);
content::Source<Profile>(profile_));
sync_service_ = ProfileSyncServiceFactory::GetForProfile(profile_); sync_service_ = ProfileSyncServiceFactory::GetForProfile(profile_);
CHECK(sync_service_); CHECK(sync_service_);
...@@ -88,9 +86,13 @@ void AppSyncUIState::StopObserving() { ...@@ -88,9 +86,13 @@ void AppSyncUIState::StopObserving() {
if (!sync_service_) if (!sync_service_)
return; return;
registrar_.RemoveAll();
sync_service_->RemoveObserver(this); sync_service_->RemoveObserver(this);
sync_service_ = NULL; sync_service_ = NULL;
if (extension_registry_)
extension_registry_->RemoveObserver(this);
extension_registry_ = NULL;
profile_ = NULL; profile_ = NULL;
} }
...@@ -137,14 +139,12 @@ void AppSyncUIState::OnMaxSyncingTimer() { ...@@ -137,14 +139,12 @@ void AppSyncUIState::OnMaxSyncingTimer() {
SetStatus(STATUS_TIMED_OUT); SetStatus(STATUS_TIMED_OUT);
} }
void AppSyncUIState::Observe(int type, void AppSyncUIState::OnStateChanged() {
const content::NotificationSource& source, DCHECK(sync_service_);
const content::NotificationDetails& details) {
DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, type);
CheckAppSync(); CheckAppSync();
} }
void AppSyncUIState::OnStateChanged() { void AppSyncUIState::OnExtensionLoaded(content::BrowserContext* browser_context,
DCHECK(sync_service_); const extensions::Extension* extension) {
CheckAppSync(); CheckAppSync();
} }
...@@ -13,18 +13,23 @@ ...@@ -13,18 +13,23 @@
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry_observer.h"
class AppSyncUIStateObserver; class AppSyncUIStateObserver;
class Profile; class Profile;
class ProfileSyncService; class ProfileSyncService;
namespace extensions {
class ExtensionRegistry;
}
// AppSyncUIState watches app sync and installation and change its state // AppSyncUIState watches app sync and installation and change its state
// accordingly. Its status is for UI display only. It only watches for new // accordingly. Its status is for UI display only. It only watches for new
// normal user profile (i.e. it does not watch for guest profile or exsiting // normal user profile (i.e. it does not watch for guest profile or exsiting
// user profile) and lasts for at the most 1 minute. // user profile) and lasts for at the most 1 minute.
class AppSyncUIState : public KeyedService, class AppSyncUIState : public KeyedService,
public content::NotificationObserver, public ProfileSyncServiceObserver,
public ProfileSyncServiceObserver { public extensions::ExtensionRegistryObserver {
public: public:
enum Status { enum Status {
STATUS_NORMAL, STATUS_NORMAL,
...@@ -62,15 +67,13 @@ class AppSyncUIState : public KeyedService, ...@@ -62,15 +67,13 @@ class AppSyncUIState : public KeyedService,
// Invoked when |max_syncing_status_timer_| fires. // Invoked when |max_syncing_status_timer_| fires.
void OnMaxSyncingTimer(); void OnMaxSyncingTimer();
// content::NotificationObserver overrides:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// ProfileSyncServiceObserver overrides: // ProfileSyncServiceObserver overrides:
virtual void OnStateChanged() OVERRIDE; virtual void OnStateChanged() OVERRIDE;
content::NotificationRegistrar registrar_; // extensions::ExtensionRegistryObserver overrides:
virtual void OnExtensionLoaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension) OVERRIDE;
Profile* profile_; Profile* profile_;
ProfileSyncService* sync_service_; ProfileSyncService* sync_service_;
...@@ -81,6 +84,8 @@ class AppSyncUIState : public KeyedService, ...@@ -81,6 +84,8 @@ class AppSyncUIState : public KeyedService,
Status status_; Status status_;
ObserverList<AppSyncUIStateObserver> observers_; ObserverList<AppSyncUIStateObserver> observers_;
extensions::ExtensionRegistry* extension_registry_;
DISALLOW_COPY_AND_ASSIGN(AppSyncUIState); DISALLOW_COPY_AND_ASSIGN(AppSyncUIState);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment