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

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: Rebase 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";
Mihai Parparita -not on Chrome 2012/08/01 20:05:50 The extensions infrastructure now supports auto-ge
dcheng 2012/08/01 21:15:33 Done. This is really neat!
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::OnMessage(
38 const std::string& extension_id,
39 int subchannel,
40 const std::string& payload) {
41 DictionaryValue* dict = new DictionaryValue;
42 dict->SetInteger(kSubchannelKey, subchannel);
43 dict->SetString(kPayloadKey, payload);
44
45 ListValue args;
46 args.Append(dict);
47 std::string json_args;
48 base::JSONWriter::Write(&args, &json_args);
49
50 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
51 extension_id,
52 kEventName,
53 json_args,
54 profile_,
55 GURL());
56 }
57
58 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698