| 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
|
|
|