Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/app_sync_ui_state.h" | 5 #include "chrome/browser/ui/ash/app_sync_ui_state.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | |
| 9 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/pending_extension_manager.h" | 9 #include "chrome/browser/extensions/pending_extension_manager.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/sync/profile_sync_service.h" | 11 #include "chrome/browser/sync/profile_sync_service.h" |
| 13 #include "chrome/browser/sync/profile_sync_service_factory.h" | 12 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 14 #include "chrome/browser/ui/ash/app_sync_ui_state_factory.h" | 13 #include "chrome/browser/ui/ash/app_sync_ui_state_factory.h" |
| 15 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" | 14 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" |
| 16 #include "content/public/browser/notification_details.h" | 15 #include "extensions/browser/extension_registry.h" |
| 17 #include "content/public/browser/notification_service.h" | |
| 18 #include "content/public/browser/notification_source.h" | |
| 19 #include "extensions/browser/extension_system.h" | 16 #include "extensions/browser/extension_system.h" |
| 20 | 17 |
| 21 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
| 22 #include "chrome/browser/chromeos/login/users/user_manager.h" | 19 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 23 #endif | 20 #endif |
| 24 | 21 |
| 25 namespace { | 22 namespace { |
| 26 | 23 |
| 27 // Max loading animation time in milliseconds. | 24 // Max loading animation time in milliseconds. |
| 28 const int kMaxSyncingTimeMs = 60 * 1000; | 25 const int kMaxSyncingTimeMs = 60 * 1000; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 48 | 45 |
| 49 return profile->IsNewProfile(); | 46 return profile->IsNewProfile(); |
| 50 #else | 47 #else |
| 51 return false; | 48 return false; |
| 52 #endif | 49 #endif |
| 53 } | 50 } |
| 54 | 51 |
| 55 AppSyncUIState::AppSyncUIState(Profile* profile) | 52 AppSyncUIState::AppSyncUIState(Profile* profile) |
| 56 : profile_(profile), | 53 : profile_(profile), |
| 57 sync_service_(NULL), | 54 sync_service_(NULL), |
| 58 status_(STATUS_NORMAL) { | 55 status_(STATUS_NORMAL), |
| 56 extension_registry_(NULL) { | |
| 59 StartObserving(); | 57 StartObserving(); |
| 60 } | 58 } |
| 61 | 59 |
| 62 AppSyncUIState::~AppSyncUIState() { | 60 AppSyncUIState::~AppSyncUIState() { |
| 63 StopObserving(); | 61 StopObserving(); |
| 64 } | 62 } |
| 65 | 63 |
| 66 void AppSyncUIState::AddObserver(AppSyncUIStateObserver* observer) { | 64 void AppSyncUIState::AddObserver(AppSyncUIStateObserver* observer) { |
| 67 observers_.AddObserver(observer); | 65 observers_.AddObserver(observer); |
| 68 } | 66 } |
| 69 | 67 |
| 70 void AppSyncUIState::RemoveObserver(AppSyncUIStateObserver* observer) { | 68 void AppSyncUIState::RemoveObserver(AppSyncUIStateObserver* observer) { |
| 71 observers_.RemoveObserver(observer); | 69 observers_.RemoveObserver(observer); |
| 72 } | 70 } |
| 73 | 71 |
| 74 void AppSyncUIState::StartObserving() { | 72 void AppSyncUIState::StartObserving() { |
| 75 DCHECK(ShouldObserveAppSyncForProfile(profile_)); | 73 DCHECK(ShouldObserveAppSyncForProfile(profile_)); |
| 76 DCHECK(!sync_service_); | 74 DCHECK(!sync_service_); |
| 75 DCHECK(!extension_registry_); | |
| 77 | 76 |
| 78 registrar_.Add(this, | 77 extension_registry_ = extensions::ExtensionRegistry::Get(profile_); |
| 79 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 78 extension_registry_->AddObserver(this); |
| 80 content::Source<Profile>(profile_)); | |
| 81 | 79 |
| 82 sync_service_ = ProfileSyncServiceFactory::GetForProfile(profile_); | 80 sync_service_ = ProfileSyncServiceFactory::GetForProfile(profile_); |
| 83 CHECK(sync_service_); | 81 CHECK(sync_service_); |
| 84 sync_service_->AddObserver(this); | 82 sync_service_->AddObserver(this); |
| 85 } | 83 } |
| 86 | 84 |
| 87 void AppSyncUIState::StopObserving() { | 85 void AppSyncUIState::StopObserving() { |
| 88 if (!sync_service_) | 86 if (!sync_service_) |
| 89 return; | 87 return; |
| 90 | 88 |
| 91 registrar_.RemoveAll(); | |
| 92 sync_service_->RemoveObserver(this); | 89 sync_service_->RemoveObserver(this); |
| 93 sync_service_ = NULL; | 90 sync_service_ = NULL; |
| 91 | |
| 92 if (extension_registry_) | |
| 93 extension_registry_->RemoveObserver(this); | |
| 94 extension_registry_ = NULL; | |
| 95 | |
| 94 profile_ = NULL; | 96 profile_ = NULL; |
| 95 } | 97 } |
| 96 | 98 |
| 97 void AppSyncUIState::SetStatus(Status status) { | 99 void AppSyncUIState::SetStatus(Status status) { |
| 98 if (status_ == status) | 100 if (status_ == status) |
| 99 return; | 101 return; |
| 100 | 102 |
| 101 status_ = status; | 103 status_ = status; |
| 102 switch (status_) { | 104 switch (status_) { |
| 103 case STATUS_SYNCING: | 105 case STATUS_SYNCING: |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 130 if (synced && !has_pending_extension) | 132 if (synced && !has_pending_extension) |
| 131 SetStatus(STATUS_NORMAL); | 133 SetStatus(STATUS_NORMAL); |
| 132 else | 134 else |
| 133 SetStatus(STATUS_SYNCING); | 135 SetStatus(STATUS_SYNCING); |
| 134 } | 136 } |
| 135 | 137 |
| 136 void AppSyncUIState::OnMaxSyncingTimer() { | 138 void AppSyncUIState::OnMaxSyncingTimer() { |
| 137 SetStatus(STATUS_TIMED_OUT); | 139 SetStatus(STATUS_TIMED_OUT); |
| 138 } | 140 } |
| 139 | 141 |
| 140 void AppSyncUIState::Observe(int type, | 142 void AppSyncUIState::OnExtensionLoaded(content::BrowserContext* browser_context, |
|
James Cook
2014/07/22 16:29:24
and when you change the order in the header, chang
limasdf
2014/07/22 16:38:10
Done.
| |
| 141 const content::NotificationSource& source, | 143 const extensions::Extension* extension) { |
| 142 const content::NotificationDetails& details) { | |
| 143 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, type); | |
| 144 CheckAppSync(); | 144 CheckAppSync(); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void AppSyncUIState::OnStateChanged() { | 147 void AppSyncUIState::OnStateChanged() { |
| 148 DCHECK(sync_service_); | 148 DCHECK(sync_service_); |
| 149 CheckAppSync(); | 149 CheckAppSync(); |
| 150 } | 150 } |
| OLD | NEW |