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

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

Issue 10837013: Chrome Cloud Messaging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: InvalidationHandler + event Created 8 years, 5 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
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
new file mode 100644
index 0000000000000000000000000000000000000000..f6c837c18a53c3800d5d78358394ea380adc66bb
--- /dev/null
+++ b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
@@ -0,0 +1,67 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h"
+
+#include "base/bind.h"
+#include "base/json/json_writer.h"
+#include "base/values.h"
+#include "chrome/browser/extensions/api/push_messaging/invalidation_handler.h"
+#include "chrome/browser/extensions/event_router.h"
+#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/browser_thread.h"
+#include "googleurl/src/gurl.h"
+
+using content::BrowserThread;
+
+namespace extensions {
+
+namespace {
+const char kEventName[] = "experimental.pushMessaging.onMessage";
+// Keys for JSON dictionary for the onMessage event.
+const char kPayloadKey[] = "payload";
+const char kSubchannelKey[] = "subchannel";
+} // namespace
+
+ExtensionPushMessagingEventRouter::ExtensionPushMessagingEventRouter(
+ Profile* profile)
+ : profile_(profile) {
+}
+
+ExtensionPushMessagingEventRouter::~ExtensionPushMessagingEventRouter() {}
+
+void ExtensionPushMessagingEventRouter::Init() {
+ // Hook into PSS here with InvalidationHandler.
+ handler_.reset(new InvalidationHandler(this));
+}
+
+void ExtensionPushMessagingEventRouter::TriggerMessageForTest(
+ const std::string& extension_id,
+ int subchannel,
+ const std::string& payload) {
+ OnMessage(extension_id, subchannel, payload);
+}
+
+void ExtensionPushMessagingEventRouter::OnMessage(
+ const std::string& extension_id,
+ int subchannel,
+ const std::string& payload) {
+ ListValue args;
+ DictionaryValue* dict = new DictionaryValue;
+ dict->SetInteger(kSubchannelKey, subchannel);
+ dict->SetString(kPayloadKey, payload);
+
+ args.Append(dict);
+
+ std::string json_args;
+ base::JSONWriter::Write(&args, &json_args);
+ profile_->GetExtensionEventRouter()->DispatchEventToExtension(
+ extension_id,
+ kEventName,
+ json_args,
+ profile_,
+ GURL());
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698