| OLD | NEW |
| (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/notifications/notification_dispatcher.h" | |
| 6 | |
| 7 #include <limits> | |
| 8 | |
| 9 #include "content/child/notifications/notification_manager.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 NotificationDispatcher::NotificationDispatcher( | |
| 14 ThreadSafeSender* thread_safe_sender) | |
| 15 : WorkerThreadMessageFilter(thread_safe_sender) {} | |
| 16 | |
| 17 NotificationDispatcher::~NotificationDispatcher() {} | |
| 18 | |
| 19 int NotificationDispatcher::GenerateNotificationId(int thread_id) { | |
| 20 base::AutoLock lock(notification_id_map_lock_); | |
| 21 CHECK_LT(next_notification_id_, std::numeric_limits<int>::max()); | |
| 22 | |
| 23 notification_id_map_[next_notification_id_] = thread_id; | |
| 24 return next_notification_id_++; | |
| 25 } | |
| 26 | |
| 27 bool NotificationDispatcher::ShouldHandleMessage( | |
| 28 const IPC::Message& msg) const { | |
| 29 return IPC_MESSAGE_CLASS(msg) == PlatformNotificationMsgStart; | |
| 30 } | |
| 31 | |
| 32 void NotificationDispatcher::OnFilteredMessageReceived( | |
| 33 const IPC::Message& msg) { | |
| 34 NotificationManager::ThreadSpecificInstance(thread_safe_sender(), this) | |
| 35 ->OnMessageReceived(msg); | |
| 36 } | |
| 37 | |
| 38 bool NotificationDispatcher::GetWorkerThreadIdForMessage( | |
| 39 const IPC::Message& msg, | |
| 40 int* ipc_thread_id) { | |
| 41 int notification_id = -1; | |
| 42 const bool success = base::PickleIterator(msg).ReadInt(¬ification_id); | |
| 43 DCHECK(success); | |
| 44 | |
| 45 base::AutoLock lock(notification_id_map_lock_); | |
| 46 auto iterator = notification_id_map_.find(notification_id); | |
| 47 if (iterator != notification_id_map_.end()) { | |
| 48 *ipc_thread_id = iterator->second; | |
| 49 return true; | |
| 50 } | |
| 51 return false; | |
| 52 } | |
| 53 | |
| 54 } // namespace content | |
| OLD | NEW |