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

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

Issue 1134733006: Push API: use (un)subscription instead of (un)registration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed pre-submit warning Created 5 years, 7 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/push_messaging/push_dispatcher.h" 5 #include "content/child/push_messaging/push_dispatcher.h"
6 6
7 #include "content/child/push_messaging/push_provider.h" 7 #include "content/child/push_messaging/push_provider.h"
8 #include "content/common/push_messaging_messages.h" 8 #include "content/common/push_messaging_messages.h"
9 9
10 namespace content { 10 namespace content {
11 11
12 PushDispatcher::PushDispatcher(ThreadSafeSender* thread_safe_sender) 12 PushDispatcher::PushDispatcher(ThreadSafeSender* thread_safe_sender)
13 : WorkerThreadMessageFilter(thread_safe_sender), next_request_id_(0) { 13 : WorkerThreadMessageFilter(thread_safe_sender), next_request_id_(0) {
14 } 14 }
15 15
16 PushDispatcher::~PushDispatcher() { 16 PushDispatcher::~PushDispatcher() {
17 } 17 }
18 18
19 int PushDispatcher::GenerateRequestId(int thread_id) { 19 int PushDispatcher::GenerateRequestId(int thread_id) {
20 base::AutoLock lock(request_id_map_lock_); 20 base::AutoLock lock(request_id_map_lock_);
21 request_id_map_[next_request_id_] = thread_id; 21 request_id_map_[next_request_id_] = thread_id;
22 return next_request_id_++; 22 return next_request_id_++;
23 } 23 }
24 24
25 bool PushDispatcher::ShouldHandleMessage(const IPC::Message& msg) const { 25 bool PushDispatcher::ShouldHandleMessage(const IPC::Message& msg) const {
26 // Note that not all Push API IPC messages flow through this class. A subset 26 // Note that not all Push API IPC messages flow through this class. A subset
27 // of the API functionality requires a direct association with a document and 27 // of the API functionality requires a direct association with a document and
28 // a frame, and for those cases the IPC messages are handled by a 28 // a frame, and for those cases the IPC messages are handled by a
29 // RenderFrameObserver. 29 // RenderFrameObserver.
30 return msg.type() == PushMessagingMsg_RegisterFromWorkerSuccess::ID || 30 return msg.type() == PushMessagingMsg_SubscribeFromWorkerSuccess::ID ||
31 msg.type() == PushMessagingMsg_RegisterFromWorkerError::ID || 31 msg.type() == PushMessagingMsg_SubscribeFromWorkerError::ID ||
32 msg.type() == PushMessagingMsg_GetRegistrationSuccess::ID || 32 msg.type() == PushMessagingMsg_GetRegistrationSuccess::ID ||
33 msg.type() == PushMessagingMsg_GetRegistrationError::ID || 33 msg.type() == PushMessagingMsg_GetRegistrationError::ID ||
34 msg.type() == PushMessagingMsg_GetPermissionStatusSuccess::ID || 34 msg.type() == PushMessagingMsg_GetPermissionStatusSuccess::ID ||
35 msg.type() == PushMessagingMsg_GetPermissionStatusError::ID || 35 msg.type() == PushMessagingMsg_GetPermissionStatusError::ID ||
36 msg.type() == PushMessagingMsg_UnregisterSuccess::ID || 36 msg.type() == PushMessagingMsg_UnsubscribeSuccess::ID ||
37 msg.type() == PushMessagingMsg_UnregisterError::ID; 37 msg.type() == PushMessagingMsg_UnsubscribeError::ID;
38 } 38 }
39 39
40 void PushDispatcher::OnFilteredMessageReceived(const IPC::Message& msg) { 40 void PushDispatcher::OnFilteredMessageReceived(const IPC::Message& msg) {
41 bool handled = PushProvider::ThreadSpecificInstance( 41 bool handled = PushProvider::ThreadSpecificInstance(
42 thread_safe_sender(), this)->OnMessageReceived(msg); 42 thread_safe_sender(), this)->OnMessageReceived(msg);
43 DCHECK(handled); 43 DCHECK(handled);
44 } 44 }
45 45
46 bool PushDispatcher::GetWorkerThreadIdForMessage(const IPC::Message& msg, 46 bool PushDispatcher::GetWorkerThreadIdForMessage(const IPC::Message& msg,
47 int* ipc_thread_id) { 47 int* ipc_thread_id) {
48 int request_id = -1; 48 int request_id = -1;
49 49
50 const bool success = PickleIterator(msg).ReadInt(&request_id); 50 const bool success = PickleIterator(msg).ReadInt(&request_id);
51 DCHECK(success); 51 DCHECK(success);
52 52
53 base::AutoLock lock(request_id_map_lock_); 53 base::AutoLock lock(request_id_map_lock_);
54 auto it = request_id_map_.find(request_id); 54 auto it = request_id_map_.find(request_id);
55 if (it != request_id_map_.end()) { 55 if (it != request_id_map_.end()) {
56 *ipc_thread_id = it->second; 56 *ipc_thread_id = it->second;
57 request_id_map_.erase(it); 57 request_id_map_.erase(it);
58 return true; 58 return true;
59 } 59 }
60 return false; 60 return false;
61 } 61 }
62 62
63 } // namespace content 63 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/push_messaging/push_messaging_message_filter.cc ('k') | content/child/push_messaging/push_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698