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

Unified Diff: chrome/browser/extensions/api/gcm/gcm_api.cc

Issue 189803002: [GCM] Observe the event listener adding such that GCM can be started (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months 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
« no previous file with comments | « chrome/browser/extensions/api/gcm/gcm_api.h ('k') | chrome/browser/services/gcm/gcm_profile_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/gcm/gcm_api.cc
diff --git a/chrome/browser/extensions/api/gcm/gcm_api.cc b/chrome/browser/extensions/api/gcm/gcm_api.cc
index 03a9b9abdbd9a10bf7d20ac71b96b9948aaec360..2028ce15b2f49496658601b62a3c3373b7e151b3 100644
--- a/chrome/browser/extensions/api/gcm/gcm_api.cc
+++ b/chrome/browser/extensions/api/gcm/gcm_api.cc
@@ -15,7 +15,6 @@
#include "chrome/browser/services/gcm/gcm_profile_service.h"
#include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
#include "chrome/common/extensions/api/gcm.h"
-#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
@@ -179,9 +178,18 @@ bool GcmSendFunction::ValidateMessageData(
return total_size != 0;
}
-GcmJsEventRouter::GcmJsEventRouter(Profile* profile) : profile_(profile) {}
+GcmJsEventRouter::GcmJsEventRouter(Profile* profile) : profile_(profile) {
+ ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
+ this, api::gcm::OnMessage::kEventName);
+ ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
+ this, api::gcm::OnMessagesDeleted::kEventName);
+ ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
+ this, api::gcm::OnSendError::kEventName);
+}
-GcmJsEventRouter::~GcmJsEventRouter() {}
+GcmJsEventRouter::~GcmJsEventRouter() {
+ ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
+}
void GcmJsEventRouter::OnMessage(
const std::string& app_id,
@@ -223,4 +231,11 @@ void GcmJsEventRouter::OnSendError(const std::string& app_id,
app_id, event.Pass());
}
+void GcmJsEventRouter::OnListenerAdded(const EventListenerInfo& details) {
+ if (gcm::GCMProfileService::GetGCMEnabledState(profile_) ==
+ gcm::GCMProfileService::ALWAYS_DISABLED)
fgorski 2014/03/07 17:56:07 nit: {} would make it more clear, given that if ha
+ return;
+ gcm::GCMProfileServiceFactory::GetForProfile(profile_)->Start();
+}
+
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/gcm/gcm_api.h ('k') | chrome/browser/services/gcm/gcm_profile_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698