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

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

Issue 12150002: - Invoke FinishDiscovery() if no network interfaces are detected. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplify DialService::SendNetworkList Created 7 years, 10 months 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 | Annotate | Revision Log
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 // DialService implementation 96 // DialService implementation
97 virtual bool Discover() OVERRIDE; 97 virtual bool Discover() OVERRIDE;
98 virtual void AddObserver(Observer* observer) OVERRIDE; 98 virtual void AddObserver(Observer* observer) OVERRIDE;
99 virtual void RemoveObserver(Observer* observer) OVERRIDE; 99 virtual void RemoveObserver(Observer* observer) OVERRIDE;
100 virtual bool HasObserver(Observer* observer) OVERRIDE; 100 virtual bool HasObserver(Observer* observer) OVERRIDE;
101 101
102 private: 102 private:
103 virtual ~DialServiceImpl(); 103 virtual ~DialServiceImpl();
104 104
105 // Starts the flow to construct and send a discovery request. 105 // Starts the control flow for one discovery cycle.
106 void StartRequest(); 106 void StartDiscovery();
107 107
108 // Establishes the UDP socket that is used for requests and responses, then 108 // Establishes the UDP socket that is used for requests and responses,
109 // sends a discovery request on the bound socket. Returns |true| if 109 // establishes a read callback on the socket, and sends the first discovery
110 // successful. 110 // request. Returns true if successful.
111 bool BindAndWriteSocket(const net::NetworkInterface& bind_interface); 111 bool BindSocketAndSendRequest(const net::IPAddressNumber& bind_ip_address);
112
113 // Sends a single discovery request over the socket.
114 void SendOneRequest();
112 115
113 // Callback invoked for socket writes. 116 // Callback invoked for socket writes.
114 void OnSocketWrite(int result); 117 void OnSocketWrite(int result);
115 118
116 // Method to get the network list on the FILE thread. 119 // Method to get the network list on the FILE thread.
117 void DoGetNetworkList(); 120 void DoGetNetworkList();
118 121
119 // Send the network list to IO thread. 122 // Send the network list to IO thread.
120 void SendNetworkList(const net::NetworkInterfaceList& list); 123 void SendNetworkList(const net::NetworkInterfaceList& list);
121 124
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 157
155 // The multicast address:port for search requests. 158 // The multicast address:port for search requests.
156 net::IPEndPoint send_address_; 159 net::IPEndPoint send_address_;
157 160
158 // The NetLog for this service. 161 // The NetLog for this service.
159 net::NetLog* net_log_; 162 net::NetLog* net_log_;
160 163
161 // The NetLog source for this service. 164 // The NetLog source for this service.
162 net::NetLog::Source net_log_source_; 165 net::NetLog::Source net_log_source_;
163 166
167 // NOTE(mfoltz): It would make this class cleaner to refactor most of the
justinlin 2013/02/08 08:56:20 Move this TODO to the top of this class or somewhe
mark a. foltz 2013/02/08 22:07:58 Done, and elaborated it a bit.
168 // following state into its own |DiscoveryOperation| object that was managed
169 // by the DialServiceImpl object.
170
164 // Buffer for socket writes. 171 // Buffer for socket writes.
165 scoped_refptr<net::StringIOBuffer> send_buffer_; 172 scoped_refptr<net::StringIOBuffer> send_buffer_;
166 173
167 // Marks whether there is an active write callback. 174 // Marks whether there is an active write callback.
168 bool is_writing_; 175 bool is_writing_;
169 176
170 // Buffer for socket reads. 177 // Buffer for socket reads.
171 scoped_refptr<net::IOBufferWithSize> recv_buffer_; 178 scoped_refptr<net::IOBufferWithSize> recv_buffer_;
172 179
173 // The source of of the last socket read. 180 // The source of of the last socket read.
174 net::IPEndPoint recv_address_; 181 net::IPEndPoint recv_address_;
175 182
176 // Marks whether there is an active read callback. 183 // Marks whether there is an active read callback.
177 bool is_reading_; 184 bool is_reading_;
178 185
179 // True when we are currently doing discovery. 186 // True when we are currently doing discovery.
180 bool discovery_active_; 187 bool discovery_active_;
181 188
182 // The number of requests that have been sent in the current discovery. 189 // The number of requests that have been sent in the current discovery.
183 int num_requests_sent_; 190 int num_requests_sent_;
184 191
192 // The maximum number of requests to send per discovery cycle.
193 int max_requests_;
194
185 // Timer for finishing discovery. 195 // Timer for finishing discovery.
186 base::OneShotTimer<DialServiceImpl> finish_timer_; 196 base::OneShotTimer<DialServiceImpl> finish_timer_;
187 197
188 // The delay for |finish_timer_|; how long to wait for discovery to finish. 198 // The delay for |finish_timer_|; how long to wait for discovery to finish.
199 // Setting this to zero disables the timer.
189 base::TimeDelta finish_delay_; 200 base::TimeDelta finish_delay_;
190 201
202 // Timer for sending multiple requests at fixed intervals.
203 base::RepeatingTimer<DialServiceImpl> request_timer_;
204
205 // The delay for |request_timer_|; how long to wait between successive
206 // requests.
207 base::TimeDelta request_interval_;
208
191 // List of observers. 209 // List of observers.
192 ObserverList<Observer> observer_list_; 210 ObserverList<Observer> observer_list_;
193 211
194 // Thread checker. 212 // Thread checker.
195 base::ThreadChecker thread_checker_; 213 base::ThreadChecker thread_checker_;
196 214
215 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestSendMultipleRequests);
197 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDeviceDiscovered); 216 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDeviceDiscovered);
198 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryFinished); 217 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryFinished);
199 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryRequest); 218 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryRequest);
200 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestResponseParsing); 219 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestResponseParsing);
201 DISALLOW_COPY_AND_ASSIGN(DialServiceImpl); 220 DISALLOW_COPY_AND_ASSIGN(DialServiceImpl);
202 }; 221 };
203 222
204 } // namespace extensions 223 } // namespace extensions
205 224
206 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_SERVICE_H_ 225 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/dial/dial_service.cc » ('j') | chrome/browser/extensions/api/dial/dial_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698