| OLD | NEW |
| 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 #ifndef CONTENT_CHILD_PUSH_MESSAGING_PUSH_DISPATCHER_H_ | 5 #ifndef CONTENT_CHILD_PUSH_MESSAGING_PUSH_DISPATCHER_H_ |
| 6 #define CONTENT_CHILD_PUSH_MESSAGING_PUSH_DISPATCHER_H_ | 6 #define CONTENT_CHILD_PUSH_MESSAGING_PUSH_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "content/child/worker_thread_message_filter.h" | 11 #include "content/child/worker_thread_message_filter.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 class PushDispatcher : public WorkerThreadMessageFilter { | 15 class PushDispatcher : public WorkerThreadMessageFilter { |
| 16 public: | 16 public: |
| 17 explicit PushDispatcher(ThreadSafeSender* thread_safe_sender); | 17 explicit PushDispatcher(ThreadSafeSender* thread_safe_sender); |
| 18 | 18 |
| 19 // Generates a process-unique new request id. Stores it in a map as key to | 19 // Generates a process-unique new request id. Stores it in a map as key to |
| 20 // |thread_id| and returns it. This method can be called on any thread. | 20 // |thread_id| and returns it. This method can be called on any thread. |
| 21 // Note that the registration requests from document contexts do not go via | 21 // Note that the subscription requests from document contexts do not go via |
| 22 // this class and their request ids may overlap with the ones generated here. | 22 // this class and their request ids may overlap with the ones generated here. |
| 23 int GenerateRequestId(int thread_id); | 23 int GenerateRequestId(int thread_id); |
| 24 | 24 |
| 25 protected: | 25 protected: |
| 26 ~PushDispatcher() override; | 26 ~PushDispatcher() override; |
| 27 | 27 |
| 28 private: | 28 private: |
| 29 // WorkerThreadMessageFilter: | 29 // WorkerThreadMessageFilter: |
| 30 bool ShouldHandleMessage(const IPC::Message& msg) const override; | 30 bool ShouldHandleMessage(const IPC::Message& msg) const override; |
| 31 void OnFilteredMessageReceived(const IPC::Message& msg) override; | 31 void OnFilteredMessageReceived(const IPC::Message& msg) override; |
| 32 bool GetWorkerThreadIdForMessage(const IPC::Message& msg, | 32 bool GetWorkerThreadIdForMessage(const IPC::Message& msg, |
| 33 int* ipc_thread_id) override; | 33 int* ipc_thread_id) override; |
| 34 | 34 |
| 35 base::Lock request_id_map_lock_; | 35 base::Lock request_id_map_lock_; |
| 36 std::map<int, int> request_id_map_; // Maps request id to thread id. | 36 std::map<int, int> request_id_map_; // Maps request id to thread id. |
| 37 int next_request_id_; | 37 int next_request_id_; |
| 38 | 38 |
| 39 DISALLOW_COPY_AND_ASSIGN(PushDispatcher); | 39 DISALLOW_COPY_AND_ASSIGN(PushDispatcher); |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 } // namespace content | 42 } // namespace content |
| 43 | 43 |
| 44 #endif // CONTENT_CHILD_PUSH_MESSAGING_PUSH_DISPATCHER_H_ | 44 #endif // CONTENT_CHILD_PUSH_MESSAGING_PUSH_DISPATCHER_H_ |
| OLD | NEW |