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

Unified Diff: chrome/browser/extensions/api/push_messaging/push_messaging_api.cc

Issue 11496004: Lazy initialization for PushMessagingEventRouter (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added InitializeEventRouter Created 8 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
diff --git a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
index d4405be6d25c846f8b0324a50a356c5c7dd42131..62270a5315d2219b98dde433482fc8179c302132 100644
--- a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
+++ b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/string_number_conversions.h"
#include "base/values.h"
+#include "chrome/browser/extensions/api/push_messaging/push_messaging_api_factory.h"
#include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler.h"
#include "chrome/browser/extensions/event_names.h"
#include "chrome/browser/extensions/event_router.h"
@@ -75,15 +76,6 @@ PushMessagingEventRouter::PushMessagingEventRouter(Profile* profile)
PushMessagingEventRouter::~PushMessagingEventRouter() {}
-void PushMessagingEventRouter::Shutdown() {
- // We need an explicit Shutdown() due to the dependencies among the various
- // ProfileKeyedServices. ProfileSyncService depends on ExtensionSystem, so
- // it is destroyed before us in the destruction phase of Profile shutdown.
- // As a result, we need to drop any references to it in the Shutdown() phase
- // instead.
- handler_.reset();
-}
-
void PushMessagingEventRouter::SetMapperForTest(
scoped_ptr<PushMessagingInvalidationMapper> mapper) {
handler_ = mapper.Pass();
@@ -289,4 +281,45 @@ void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure(
ReportResult(std::string(), error_text);
}
+PushMessagingAPI::PushMessagingAPI(Profile* profile)
+ : profile_(profile) {
+ ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
+ this, event_names::kOnPushMessage);
+}
+
+PushMessagingAPI::~PushMessagingAPI() {
+}
+
+// static
+PushMessagingAPI* PushMessagingAPI::Get(Profile* profile) {
+ return PushMessagingAPIFactory::GetForProfile(profile);
+}
+
+void PushMessagingAPI::Shutdown() {
+ // It's safe to call UnregisterObserver more than once.
akalin 2012/12/12 21:39:15 This comment could be clearer. How about: // Unr
Joe Thomas 2012/12/13 08:34:43 Done.
+ // UnregisterObserver would have already called when the listener
+ // got added.
+ ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
+ push_messaging_event_router_.reset();
+}
+
+void PushMessagingAPI::OnListenerAdded(
+ const extensions::EventListenerInfo& details) {
+ InitializeEventRouter();
+}
+
+void PushMessagingAPI::InitializeEventRouterForTest() {
+ InitializeEventRouter();
+}
+
+PushMessagingEventRouter* PushMessagingAPI::GetEventRouterForTest() {
+ return push_messaging_event_router_.get();
+}
+
+void PushMessagingAPI::InitializeEventRouter() {
+ DCHECK(!push_messaging_event_router_.get());
+ push_messaging_event_router_.reset(new PushMessagingEventRouter(profile_));
+ ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698