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

Side by Side Diff: content/child/push_messaging/push_dispatcher.cc

Issue 2690203003: Convert push_messaging IPC msgs into mojo interfaces (Closed)
Patch Set: remove DCHECK(ChildThreadImpl::Current()) Created 3 years, 10 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
OLDNEW
(Empty)
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/child/push_messaging/push_dispatcher.h"
6
7 #include "content/child/push_messaging/push_provider.h"
8 #include "content/common/push_messaging_messages.h"
9
10 namespace content {
11
12 PushDispatcher::PushDispatcher(ThreadSafeSender* thread_safe_sender)
13 : WorkerThreadMessageFilter(thread_safe_sender), next_request_id_(0) {}
14
15 PushDispatcher::~PushDispatcher() {}
16
17 int PushDispatcher::GenerateRequestId(int thread_id) {
18 base::AutoLock lock(request_id_map_lock_);
19 request_id_map_[next_request_id_] = thread_id;
20 return next_request_id_++;
21 }
22
23 bool PushDispatcher::ShouldHandleMessage(const IPC::Message& msg) const {
24 // Note that not all Push API IPC messages flow through this class. A subset
25 // of the API functionality requires a direct association with a document and
26 // a frame, and for those cases the IPC messages are handled by a
27 // RenderFrameObserver.
28 return msg.type() == PushMessagingMsg_SubscribeFromWorkerSuccess::ID ||
29 msg.type() == PushMessagingMsg_SubscribeFromWorkerError::ID ||
30 msg.type() == PushMessagingMsg_GetSubscriptionSuccess::ID ||
31 msg.type() == PushMessagingMsg_GetSubscriptionError::ID ||
32 msg.type() == PushMessagingMsg_GetPermissionStatusSuccess::ID ||
33 msg.type() == PushMessagingMsg_GetPermissionStatusError::ID ||
34 msg.type() == PushMessagingMsg_UnsubscribeSuccess::ID ||
35 msg.type() == PushMessagingMsg_UnsubscribeError::ID;
36 }
37
38 void PushDispatcher::OnFilteredMessageReceived(const IPC::Message& msg) {
39 bool handled =
40 PushProvider::ThreadSpecificInstance(thread_safe_sender(), this)
41 ->OnMessageReceived(msg);
42 DCHECK(handled);
43 }
44
45 bool PushDispatcher::GetWorkerThreadIdForMessage(const IPC::Message& msg,
46 int* ipc_thread_id) {
47 int request_id = -1;
48
49 const bool success = base::PickleIterator(msg).ReadInt(&request_id);
50 DCHECK(success);
51
52 base::AutoLock lock(request_id_map_lock_);
53 auto it = request_id_map_.find(request_id);
54 if (it != request_id_map_.end()) {
55 *ipc_thread_id = it->second;
56 request_id_map_.erase(it);
57 return true;
58 }
59 return false;
60 }
61
62 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698