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 @@
#include "chrome/browser/ui/ash/app_sync_ui_state.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/pending_extension_manager.h"
#include "chrome/browser/profiles/profile.h"
......@@ -13,9 +12,7 @@
#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_observer.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#if defined(OS_CHROMEOS)
......@@ -55,7 +52,8 @@ bool AppSyncUIState::ShouldObserveAppSyncForProfile(Profile* profile) {
AppSyncUIState::AppSyncUIState(Profile* profile)
: profile_(profile),
sync_service_(NULL),
status_(STATUS_NORMAL) {
status_(STATUS_NORMAL),
extension_registry_(NULL) {
StartObserving();
}
......@@ -74,10 +72,10 @@ void AppSyncUIState::RemoveObserver(AppSyncUIStateObserver* observer) {
void AppSyncUIState::StartObserving() {
DCHECK(ShouldObserveAppSyncForProfile(profile_));
DCHECK(!sync_service_);
DCHECK(!extension_registry_);
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
content::Source<Profile>(profile_));
extension_registry_ = extensions::ExtensionRegistry::Get(profile_);
extension_registry_->AddObserver(this);
sync_service_ = ProfileSyncServiceFactory::GetForProfile(profile_);
CHECK(sync_service_);
......@@ -88,9 +86,13 @@ void AppSyncUIState::StopObserving() {
if (!sync_service_)
return;
registrar_.RemoveAll();
sync_service_->RemoveObserver(this);
sync_service_ = NULL;
if (extension_registry_)
extension_registry_->RemoveObserver(this);
extension_registry_ = NULL;
profile_ = NULL;
}
......@@ -137,14 +139,12 @@ void AppSyncUIState::OnMaxSyncingTimer() {
SetStatus(STATUS_TIMED_OUT);
}
void AppSyncUIState::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, type);
void AppSyncUIState::OnStateChanged() {
DCHECK(sync_service_);
CheckAppSync();
}
void AppSyncUIState::OnStateChanged() {
DCHECK(sync_service_);
void AppSyncUIState::OnExtensionLoaded(content::BrowserContext* browser_context,
const extensions::Extension* extension) {
CheckAppSync();
}
......@@ -13,18 +13,23 @@
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry_observer.h"
class AppSyncUIStateObserver;
class Profile;
class ProfileSyncService;
namespace extensions {
class ExtensionRegistry;
}
// AppSyncUIState watches app sync and installation and change its state
// 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
// user profile) and lasts for at the most 1 minute.
class AppSyncUIState : public KeyedService,
public content::NotificationObserver,
public ProfileSyncServiceObserver {
public ProfileSyncServiceObserver,
public extensions::ExtensionRegistryObserver {
public:
enum Status {
STATUS_NORMAL,
......@@ -62,15 +67,13 @@ class AppSyncUIState : public KeyedService,
// Invoked when |max_syncing_status_timer_| fires.
void OnMaxSyncingTimer();
// content::NotificationObserver overrides:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// ProfileSyncServiceObserver overrides:
virtual void OnStateChanged() OVERRIDE;
content::NotificationRegistrar registrar_;
// extensions::ExtensionRegistryObserver overrides:
virtual void OnExtensionLoaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension) OVERRIDE;
Profile* profile_;
ProfileSyncService* sync_service_;
......@@ -81,6 +84,8 @@ class AppSyncUIState : public KeyedService,
Status status_;
ObserverList<AppSyncUIStateObserver> observers_;
extensions::ExtensionRegistry* extension_registry_;
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