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

Unified Diff: content/browser/push_messaging_message_filter.cc

Issue 186023002: DO NOT REVIEW Plumb push messaging registration through to gcm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/push_messaging_message_filter.cc
diff --git a/content/browser/push_messaging_message_filter.cc b/content/browser/push_messaging_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e790f3452859cc9c6d41c2336688e5bca3a2aac3
--- /dev/null
+++ b/content/browser/push_messaging_message_filter.cc
@@ -0,0 +1,89 @@
+// Copyright 2014 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 "content/browser/push_messaging_message_filter.h"
+
+#include <string>
+
+#include "base/bind.h"
+#include "content/browser/renderer_host/render_process_host_impl.h"
+#include "content/common/push_messaging_messages.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/push_messaging_service.h"
+#include "content/public/common/content_client.h"
+
+namespace content {
+
+PushMessagingMessageFilter::PushMessagingMessageFilter(int render_process_id)
+ : BrowserMessageFilter(PushMessagingMsgStart),
+ render_process_id_(render_process_id) {}
+
+PushMessagingMessageFilter::~PushMessagingMessageFilter() {}
+
+bool PushMessagingMessageFilter::OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(PushMessagingMessageFilter, message, *message_was_ok)
+ IPC_MESSAGE_HANDLER(PushMessagingHostMsg_Register, OnRegister)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void PushMessagingMessageFilter::OnRegister(int routing_id,
+ int callbacks_id,
+ const std::string& channel_name) {
+ // TODO: Argument validation.
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&PushMessagingMessageFilter::DoRegister,
+ this,
+ routing_id,
+ callbacks_id,
+ channel_name));
+}
+
+void PushMessagingMessageFilter::DoRegister(int routing_id,
+ int callbacks_id,
+ const std::string& channel_name) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!service())
+ return;
+ service()->Register(base::Bind(&PushMessagingMessageFilter::DidRegister,
+ this,
+ routing_id,
+ callbacks_id,
+ channel_name));
+}
+
+void PushMessagingMessageFilter::DidRegister(int routing_id,
+ int callbacks_id,
+ const std::string& channel_name,
+ const std::string& registration_id,
+ PushMessagingStatus status) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (status == PUSH_MESSAGING_STATUS_OK) {
+ std::string endpoint = "test_endpoint";
+ Send(new PushMessagingMsg_RegisterSuccess(
+ routing_id, callbacks_id, endpoint, registration_id, channel_name));
+ } else {
+ Send(new PushMessagingMsg_RegisterError(routing_id, callbacks_id, status));
+ }
+}
+
+PushMessagingService* PushMessagingMessageFilter::service() {
+ if (!service_.get()) {
+ RenderProcessHostImpl* host = static_cast<RenderProcessHostImpl*>(
+ RenderProcessHost::FromID(render_process_id_));
+ if (!host)
+ return NULL;
+ service_.reset(GetContentClient()->browser()->CreatePushMessagingService(
+ host->GetBrowserContext()));
+ }
+ return service_.get();
+}
+
+} // namespace content
« no previous file with comments | « content/browser/push_messaging_message_filter.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698