Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| OLD | NEW |