Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / child / notifications / notification_dispatcher.cc
blob1c6fb54216238c0b697add551a09d3761c80c6a1
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.
5 #include "content/child/notifications/notification_dispatcher.h"
7 #include <limits>
9 #include "content/child/notifications/notification_manager.h"
11 namespace content {
13 NotificationDispatcher::NotificationDispatcher(
14 ThreadSafeSender* thread_safe_sender)
15 : WorkerThreadMessageFilter(thread_safe_sender) {
18 NotificationDispatcher::~NotificationDispatcher() {}
20 int NotificationDispatcher::GenerateNotificationId(int thread_id) {
21 base::AutoLock lock(notification_id_map_lock_);
22 CHECK_LT(next_notification_id_, std::numeric_limits<int>::max());
24 notification_id_map_[next_notification_id_] = thread_id;
25 return next_notification_id_++;
28 bool NotificationDispatcher::ShouldHandleMessage(
29 const IPC::Message& msg) const {
30 return IPC_MESSAGE_CLASS(msg) == PlatformNotificationMsgStart;
33 void NotificationDispatcher::OnFilteredMessageReceived(
34 const IPC::Message& msg) {
35 NotificationManager::ThreadSpecificInstance(thread_safe_sender(),
36 main_thread_task_runner(),
37 this)->OnMessageReceived(msg);
40 bool NotificationDispatcher::GetWorkerThreadIdForMessage(
41 const IPC::Message& msg,
42 int* ipc_thread_id) {
43 int notification_id = -1;
44 const bool success = base::PickleIterator(msg).ReadInt(&notification_id);
45 DCHECK(success);
47 base::AutoLock lock(notification_id_map_lock_);
48 auto iterator = notification_id_map_.find(notification_id);
49 if (iterator != notification_id_map_.end()) {
50 *ipc_thread_id = iterator->second;
51 return true;
53 return false;
56 } // namespace content