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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_SERVICE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_SERVICE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
17 #include "net/base/ip_address.h" | 17 #include "net/base/ip_address.h" |
18 #include "net/log/net_log.h" | 18 #include "net/log/net_log_source.h" |
19 #include "net/udp/udp_socket.h" | 19 #include "net/udp/udp_socket.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 class IOBuffer; | 22 class IOBuffer; |
23 class IPEndPoint; | 23 class IPEndPoint; |
24 class StringIOBuffer; | 24 class StringIOBuffer; |
| 25 class NetLog; |
25 struct NetworkInterface; | 26 struct NetworkInterface; |
26 } | 27 } |
27 | 28 |
28 namespace extensions { | 29 namespace extensions { |
29 | 30 |
30 class DialDeviceData; | 31 class DialDeviceData; |
31 | 32 |
32 // DialService accepts requests to discover devices, sends multiple M-SEARCH | 33 // DialService accepts requests to discover devices, sends multiple M-SEARCH |
33 // requests via UDP multicast, and notifies observers when a DIAL-compliant | 34 // requests via UDP multicast, and notifies observers when a DIAL-compliant |
34 // device responds. | 35 // device responds. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 DialSocket( | 119 DialSocket( |
119 const base::Closure& discovery_request_cb, | 120 const base::Closure& discovery_request_cb, |
120 const base::Callback<void(const DialDeviceData&)>& device_discovered_cb, | 121 const base::Callback<void(const DialDeviceData&)>& device_discovered_cb, |
121 const base::Closure& on_error_cb); | 122 const base::Closure& on_error_cb); |
122 ~DialSocket(); | 123 ~DialSocket(); |
123 | 124 |
124 // Creates a socket using |net_log| and |net_log_source| and binds it to | 125 // Creates a socket using |net_log| and |net_log_source| and binds it to |
125 // |bind_ip_address|. | 126 // |bind_ip_address|. |
126 bool CreateAndBindSocket(const net::IPAddress& bind_ip_address, | 127 bool CreateAndBindSocket(const net::IPAddress& bind_ip_address, |
127 net::NetLog* net_log, | 128 net::NetLog* net_log, |
128 net::NetLog::Source net_log_source); | 129 net::NetLogSource net_log_source); |
129 | 130 |
130 // Sends a single discovery request |send_buffer| to |send_address| | 131 // Sends a single discovery request |send_buffer| to |send_address| |
131 // over the socket. | 132 // over the socket. |
132 void SendOneRequest(const net::IPEndPoint& send_address, | 133 void SendOneRequest(const net::IPEndPoint& send_address, |
133 const scoped_refptr<net::StringIOBuffer>& send_buffer); | 134 const scoped_refptr<net::StringIOBuffer>& send_buffer); |
134 | 135 |
135 // Returns true if the socket is closed. | 136 // Returns true if the socket is closed. |
136 bool IsClosed(); | 137 bool IsClosed(); |
137 | 138 |
138 private: | 139 private: |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 bool HasOpenSockets(); | 238 bool HasOpenSockets(); |
238 | 239 |
239 // DialSockets for each network interface whose ip address was | 240 // DialSockets for each network interface whose ip address was |
240 // successfully bound. | 241 // successfully bound. |
241 std::vector<std::unique_ptr<DialSocket>> dial_sockets_; | 242 std::vector<std::unique_ptr<DialSocket>> dial_sockets_; |
242 | 243 |
243 // The NetLog for this service. | 244 // The NetLog for this service. |
244 net::NetLog* const net_log_; | 245 net::NetLog* const net_log_; |
245 | 246 |
246 // The NetLog source for this service. | 247 // The NetLog source for this service. |
247 net::NetLog::Source net_log_source_; | 248 net::NetLogSource net_log_source_; |
248 | 249 |
249 // The multicast address:port for search requests. | 250 // The multicast address:port for search requests. |
250 net::IPEndPoint send_address_; | 251 net::IPEndPoint send_address_; |
251 | 252 |
252 // Buffer for socket writes. | 253 // Buffer for socket writes. |
253 scoped_refptr<net::StringIOBuffer> send_buffer_; | 254 scoped_refptr<net::StringIOBuffer> send_buffer_; |
254 | 255 |
255 // True when we are currently doing discovery. | 256 // True when we are currently doing discovery. |
256 bool discovery_active_; | 257 bool discovery_active_; |
257 | 258 |
(...skipping 29 matching lines...) Expand all Loading... |
287 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDeviceDiscovered); | 288 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDeviceDiscovered); |
288 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryFinished); | 289 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryFinished); |
289 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryRequest); | 290 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryRequest); |
290 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestResponseParsing); | 291 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestResponseParsing); |
291 DISALLOW_COPY_AND_ASSIGN(DialServiceImpl); | 292 DISALLOW_COPY_AND_ASSIGN(DialServiceImpl); |
292 }; | 293 }; |
293 | 294 |
294 } // namespace extensions | 295 } // namespace extensions |
295 | 296 |
296 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_SERVICE_H_ | 297 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_SERVICE_H_ |
OLD | NEW |