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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h"
6
7 #include "base/bind.h"
8 #include "base/json/json_writer.h"
9 #include "base/values.h"
10 #include "chrome/browser/extensions/api/push_messaging/invalidation_handler.h"
11 #include "chrome/browser/extensions/event_router.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "googleurl/src/gurl.h"
15
16 using content::BrowserThread;
17
18 namespace extensions {
19
20 namespace {
21 const char kEventName[] = "experimental.pushMessaging.onMessage";
22 // Keys for JSON dictionary for the onMessage event.
23 const char kPayloadKey[] = "payload";
24 const char kSubchannelKey[] = "subchannel";
25 } // namespace
26
27 ExtensionPushMessagingEventRouter::ExtensionPushMessagingEventRouter(
28 Profile* profile)
29 : profile_(profile) {
30 }
31
32 ExtensionPushMessagingEventRouter::~ExtensionPushMessagingEventRouter() {}
33
34 void ExtensionPushMessagingEventRouter::Init() {
35 // Hook into PSS here with InvalidationHandler.
36 handler_.reset(new InvalidationHandler(this));
37 }
38
39 void ExtensionPushMessagingEventRouter::TriggerMessageForTest(
40 const std::string& extension_id,
41 int subchannel,
42 const std::string& payload) {
43 OnMessage(extension_id, subchannel, payload);
44 }
45
46 void ExtensionPushMessagingEventRouter::OnMessage(
47 const std::string& extension_id,
48 int subchannel,
49 const std::string& payload) {
50 ListValue args;
51 DictionaryValue* dict = new DictionaryValue;
52 dict->SetInteger(kSubchannelKey, subchannel);
53 dict->SetString(kPayloadKey, payload);
54
55 args.Append(dict);
56
57 std::string json_args;
58 base::JSONWriter::Write(&args, &json_args);
59 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
60 extension_id,
61 kEventName,
62 json_args,
63 profile_,
64 GURL());
65 }
66
67 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698