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

Side by Side Diff: chrome/browser/extensions/api/push_messaging/push_messaging_api.cc

Issue 10828087: Add skeleton implementation of ExtensionPushMessagingEventRouter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Docs 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/event_router.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "googleurl/src/gurl.h"
14
15 using content::BrowserThread;
16
17 namespace extensions {
18
19 namespace {
20 const char kEventName[] = "experimental.pushMessaging.onMessage";
21 // Keys for JSON dictionary for the onMessage event.
22 const char kPayloadKey[] = "payload";
23 const char kSubchannelKey[] = "subchannel";
24 } // namespace
25
26 ExtensionPushMessagingEventRouter::ExtensionPushMessagingEventRouter(
27 Profile* profile)
28 : profile_(profile) {
29 }
30
31 ExtensionPushMessagingEventRouter::~ExtensionPushMessagingEventRouter() {}
32
33 void ExtensionPushMessagingEventRouter::Init() {
34 // TODO(dcheng): Add hooks into InvalidationHandler when landed.
35 }
36
37 void ExtensionPushMessagingEventRouter::TriggerMessageForTest(
38 const std::string& extension_id,
39 int subchannel,
40 const std::string& payload) {
41 OnMessage(extension_id, subchannel, payload);
42 }
43
44 void ExtensionPushMessagingEventRouter::OnMessage(
45 const std::string& extension_id,
46 int subchannel,
47 const std::string& payload) {
48 ListValue args;
Munjal (Google) 2012/07/31 17:36:12 Define args closer to its first use; before args.A
dcheng 2012/07/31 19:04:11 Done.
49 DictionaryValue* dict = new DictionaryValue;
50 dict->SetInteger(kSubchannelKey, subchannel);
51 dict->SetString(kPayloadKey, payload);
52
53 args.Append(dict);
54
55 std::string json_args;
56 base::JSONWriter::Write(&args, &json_args);
57 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
58 extension_id,
Munjal (Google) 2012/07/31 17:36:12 Nit: indentation.
dcheng 2012/07/31 19:04:11 Done.
59 kEventName,
60 json_args,
61 profile_,
62 GURL());
63 }
64
65 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698