Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: chrome/browser/extensions/api/dial/dial_service.h

Issue 117853004: "Reland" of r241209. DialServiceImpl now binds to all ipv4 and interfaces instead of just the first (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string> 8 #include <string>
9 9
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // here. 119 // here.
120 DialSocket( 120 DialSocket(
121 const base::Closure& discovery_request_cb, 121 const base::Closure& discovery_request_cb,
122 const base::Callback<void(const DialDeviceData&)>& device_discovered_cb, 122 const base::Callback<void(const DialDeviceData&)>& device_discovered_cb,
123 const base::Closure& on_error_cb); 123 const base::Closure& on_error_cb);
124 ~DialSocket(); 124 ~DialSocket();
125 125
126 // Creates a socket using |net_log| and |net_log_source| and binds it to 126 // Creates a socket using |net_log| and |net_log_source| and binds it to
127 // |bind_ip_address|. 127 // |bind_ip_address|.
128 bool CreateAndBindSocket(const net::IPAddressNumber& bind_ip_address, 128 bool CreateAndBindSocket(const net::IPAddressNumber& bind_ip_address,
129 net::NetLog* net_log, 129 net::NetLog* net_log,
130 net::NetLog::Source net_log_source); 130 net::NetLog::Source net_log_source);
131 131
132 // Sends a single discovery request |send_buffer| to |send_address| 132 // Sends a single discovery request |send_buffer| to |send_address|
133 // over the socket. 133 // over the socket.
134 void SendOneRequest(const net::IPEndPoint& send_address, 134 void SendOneRequest(const net::IPEndPoint& send_address,
135 const scoped_refptr<net::StringIOBuffer>& send_buffer); 135 const scoped_refptr<net::StringIOBuffer>& send_buffer);
136 136
137 // Returns true if the socket is closed. 137 // Returns true if the socket is closed.
138 bool IsClosed(); 138 bool IsClosed();
139 139
140 private: 140 private:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 // The callback to be invoked when there is an error with socket operations. 189 // The callback to be invoked when there is an error with socket operations.
190 base::Closure on_error_cb_; 190 base::Closure on_error_cb_;
191 191
192 // Marks whether there is an active write callback. 192 // Marks whether there is an active write callback.
193 bool is_writing_; 193 bool is_writing_;
194 194
195 // Marks whether there is an active read callback. 195 // Marks whether there is an active read callback.
196 bool is_reading_; 196 bool is_reading_;
197 197
198 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestNotifyOnError);
198 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDeviceDiscovered); 199 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDeviceDiscovered);
199 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryRequest); 200 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryRequest);
200 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestResponseParsing); 201 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestResponseParsing);
201 DISALLOW_COPY_AND_ASSIGN(DialSocket); 202 DISALLOW_COPY_AND_ASSIGN(DialSocket);
202 }; 203 };
203 204
204 // Starts the control flow for one discovery cycle. 205 // Starts the control flow for one discovery cycle.
205 void StartDiscovery(); 206 void StartDiscovery();
206 207
207 // Send the network list to IO thread. 208 // For each network interface in |list|, finds all unqiue IPv4 network
209 // interfaces and call |DiscoverOnAddresses()| with their IP addresses.
208 void SendNetworkList(const net::NetworkInterfaceList& list); 210 void SendNetworkList(const net::NetworkInterfaceList& list);
209 211
210 // Calls |BindAndAddSocket()| for each address in |ip_addresses|, calls 212 // Calls |BindAndAddSocket()| for each address in |ip_addresses|, calls
211 // |SendOneRequest()|, and start the timer to finish discovery if needed. 213 // |SendOneRequest()|, and start the timer to finish discovery if needed.
214 // The (Address family, interface index) of each address in |ip_addresses|
215 // must be unique. If |ip_address| is empty, calls |FinishDiscovery()|.
212 void DiscoverOnAddresses( 216 void DiscoverOnAddresses(
213 const std::vector<net::IPAddressNumber>& ip_addresses); 217 const std::vector<net::IPAddressNumber>& ip_addresses);
214 218
215 // Creates a DialSocket, binds it to |bind_ip_address| and if 219 // Creates a DialSocket, binds it to |bind_ip_address| and if
216 // successful, add the DialSocket to |dial_sockets_|. 220 // successful, add the DialSocket to |dial_sockets_|.
217 void BindAndAddSocket(const net::IPAddressNumber& bind_ip_address); 221 void BindAndAddSocket(const net::IPAddressNumber& bind_ip_address);
218 222
219 // Creates a DialSocket with callbacks to this object. 223 // Creates a DialSocket with callbacks to this object.
220 scoped_ptr<DialSocket> CreateDialSocket(); 224 scoped_ptr<DialSocket> CreateDialSocket();
221 225
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 base::TimeDelta request_interval_; 282 base::TimeDelta request_interval_;
279 283
280 // List of observers. 284 // List of observers.
281 ObserverList<Observer> observer_list_; 285 ObserverList<Observer> observer_list_;
282 286
283 // Thread checker. 287 // Thread checker.
284 base::ThreadChecker thread_checker_; 288 base::ThreadChecker thread_checker_;
285 289
286 friend class DialServiceTest; 290 friend class DialServiceTest;
287 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestSendMultipleRequests); 291 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestSendMultipleRequests);
292 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestMultipleNetworkInterfaces);
293 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestNotifyOnError);
288 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDeviceDiscovered); 294 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDeviceDiscovered);
289 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryFinished); 295 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryFinished);
290 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryRequest); 296 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryRequest);
291 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestResponseParsing); 297 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestResponseParsing);
292 DISALLOW_COPY_AND_ASSIGN(DialServiceImpl); 298 DISALLOW_COPY_AND_ASSIGN(DialServiceImpl);
293 }; 299 };
294 300
295 } // namespace extensions 301 } // namespace extensions
296 302
297 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_SERVICE_H_ 303 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698