Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / push_messaging_message_filter.cc
1 // Copyright 2014 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 "content/browser/push_messaging_message_filter.h"
6
7 #include <string>
8
9 #include "content/common/push_messaging_messages.h"
10 #include "content/public/browser/browser_thread.h"
11
12 namespace content {
13
14 PushMessagingMessageFilter::PushMessagingMessageFilter()
15     : BrowserMessageFilter(PushMessagingMsgStart) {}
16
17 PushMessagingMessageFilter::~PushMessagingMessageFilter() {}
18
19 bool PushMessagingMessageFilter::OnMessageReceived(const IPC::Message& message,
20                                                    bool* message_was_ok) {
21   bool handled = true;
22   IPC_BEGIN_MESSAGE_MAP_EX(PushMessagingMessageFilter, message, *message_was_ok)
23     IPC_MESSAGE_HANDLER(PushMessagingHostMsg_Register, OnRegister)
24     IPC_MESSAGE_UNHANDLED(handled = false)
25   IPC_END_MESSAGE_MAP()
26   return handled;
27 }
28
29 void PushMessagingMessageFilter::OnRegister(int routing_id,
30                                             int callbacks_id,
31                                             const std::string& sender_id) {
32   // TODO(mvanouwerkerk): Really implement, the below simply returns an error.
33   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
34   GURL endpoint = GURL("https://android.googleapis.com/gcm/send");
35   BrowserThread::PostTask(BrowserThread::UI,
36                           FROM_HERE,
37                           base::Bind(&PushMessagingMessageFilter::DidRegister,
38                                      this,
39                                      routing_id,
40                                      callbacks_id,
41                                      endpoint,
42                                      "",
43                                      true));
44
45 }
46
47 void PushMessagingMessageFilter::DidRegister(int routing_id,
48                                              int callbacks_id,
49                                              const GURL& endpoint,
50                                              const std::string& registration_id,
51                                              bool error) {
52   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
53   if (!error) {
54     Send(new PushMessagingMsg_RegisterSuccess(routing_id,
55                                               callbacks_id,
56                                               endpoint,
57                                               registration_id));
58   } else {
59     Send(new PushMessagingMsg_RegisterError(routing_id, callbacks_id));
60   }
61 }
62
63 }  // namespace content