OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/messaging/message_service.h" | 5 #include "chrome/browser/extensions/api/messaging/message_service.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 9 #include <limits> |
| 10 |
7 #include "base/atomic_sequence_num.h" | 11 #include "base/atomic_sequence_num.h" |
8 #include "base/bind.h" | 12 #include "base/bind.h" |
9 #include "base/callback.h" | 13 #include "base/callback.h" |
10 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
11 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
12 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
13 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
14 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/extensions/api/messaging/extension_message_port.h" | 20 #include "chrome/browser/extensions/api/messaging/extension_message_port.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 197 |
194 content::RenderProcessHost* | 198 content::RenderProcessHost* |
195 MessageService::MessagePort::GetRenderProcessHost() { | 199 MessageService::MessagePort::GetRenderProcessHost() { |
196 return NULL; | 200 return NULL; |
197 } | 201 } |
198 | 202 |
199 // static | 203 // static |
200 void MessageService::AllocatePortIdPair(int* port1, int* port2) { | 204 void MessageService::AllocatePortIdPair(int* port1, int* port2) { |
201 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 205 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
202 | 206 |
203 unsigned channel_id = | 207 unsigned channel_id = static_cast<unsigned>(g_next_channel_id.GetNext()) % |
204 static_cast<unsigned>(g_next_channel_id.GetNext()) % (kint32max/2); | 208 (std::numeric_limits<int32_t>::max() / 2); |
205 unsigned port1_id = channel_id * 2; | 209 unsigned port1_id = channel_id * 2; |
206 unsigned port2_id = channel_id * 2 + 1; | 210 unsigned port2_id = channel_id * 2 + 1; |
207 | 211 |
208 // Sanity checks to make sure our channel<->port converters are correct. | 212 // Sanity checks to make sure our channel<->port converters are correct. |
209 DCHECK(IS_OPENER_PORT_ID(port1_id)); | 213 DCHECK(IS_OPENER_PORT_ID(port1_id)); |
210 DCHECK_EQ(GET_OPPOSITE_PORT_ID(port1_id), port2_id); | 214 DCHECK_EQ(GET_OPPOSITE_PORT_ID(port1_id), port2_id); |
211 DCHECK_EQ(GET_OPPOSITE_PORT_ID(port2_id), port1_id); | 215 DCHECK_EQ(GET_OPPOSITE_PORT_ID(port2_id), port1_id); |
212 DCHECK_EQ(GET_CHANNEL_ID(port1_id), GET_CHANNEL_ID(port2_id)); | 216 DCHECK_EQ(GET_CHANNEL_ID(port1_id), GET_CHANNEL_ID(port2_id)); |
213 DCHECK_EQ(GET_CHANNEL_ID(port1_id), channel_id); | 217 DCHECK_EQ(GET_CHANNEL_ID(port1_id), channel_id); |
214 DCHECK_EQ(GET_CHANNEL_OPENER_ID(channel_id), port1_id); | 218 DCHECK_EQ(GET_CHANNEL_OPENER_ID(channel_id), port1_id); |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 | 1010 |
1007 MessageChannelMap::iterator channel_iter = channels_.find(channel_id); | 1011 MessageChannelMap::iterator channel_iter = channels_.find(channel_id); |
1008 if (channel_iter != channels_.end()) { | 1012 if (channel_iter != channels_.end()) { |
1009 for (const PendingMessage& message : queue) { | 1013 for (const PendingMessage& message : queue) { |
1010 DispatchMessage(message.first, channel_iter->second, message.second); | 1014 DispatchMessage(message.first, channel_iter->second, message.second); |
1011 } | 1015 } |
1012 } | 1016 } |
1013 } | 1017 } |
1014 | 1018 |
1015 } // namespace extensions | 1019 } // namespace extensions |
OLD | NEW |