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

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: patch-5 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 d92305af16281e95976783f8079680ab16237206..07144329bfe5e41fe636180e0cd592b8f825d6b3 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();
@@ -290,4 +282,39 @@ 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() {
+ ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
akalin 2012/12/11 22:21:53 Perhaps add a comment saying that it's okay to unr
Joe Thomas 2012/12/12 02:39:27 Done.
+ push_messaging_event_router_.reset();
+}
+
+void PushMessagingAPI::OnListenerAdded(
+ const extensions::EventListenerInfo& details) {
+ push_messaging_event_router_.reset(new PushMessagingEventRouter(profile_));
akalin 2012/12/11 22:21:53 perhaps DCHECK that push_messaging_event_router_ i
Joe Thomas 2012/12/12 02:39:27 Done.
+ ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
+}
+
+void PushMessagingAPI::InitializePushMessagingEventRouterForTest() {
Yoyo Zhou 2012/12/11 22:07:27 It seems to me this isn't necessary for the tests
akalin 2012/12/11 22:23:41 If it's common for tests to trigger OnListenerAdde
Joe Thomas 2012/12/12 02:39:27 Done.
+ push_messaging_event_router_.reset(new PushMessagingEventRouter(profile_));
akalin 2012/12/11 22:21:53 can probably just call OnListenerAdded() directly
Joe Thomas 2012/12/12 02:39:27 OnListenerAdded() takes a parameter and we don't k
akalin 2012/12/12 02:41:01 Can you then add a private helper function like:
Joe Thomas 2012/12/12 03:13:49 Done.
+ ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
+}
+
+PushMessagingEventRouter*
+ PushMessagingAPI::GetPushMessagingEventRouterForTest() {
+ return push_messaging_event_router_.get();
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698