| 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 <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 Loading... |
| 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 Loading... |
| 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 |
| 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. |
| 189 base::TimeDelta finish_delay_; | 199 base::TimeDelta finish_delay_; |
| 190 | 200 |
| 201 // Timer for sending multiple requests at fixed intervals. |
| 202 base::RepeatingTimer<DialServiceImpl> request_timer_; |
| 203 |
| 204 // The delay for |request_timer_|; how long to wait between successive |
| 205 // requests. |
| 206 base::TimeDelta request_interval_; |
| 207 |
| 191 // List of observers. | 208 // List of observers. |
| 192 ObserverList<Observer> observer_list_; | 209 ObserverList<Observer> observer_list_; |
| 193 | 210 |
| 194 // Thread checker. | 211 // Thread checker. |
| 195 base::ThreadChecker thread_checker_; | 212 base::ThreadChecker thread_checker_; |
| 196 | 213 |
| 214 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestSendMultipleRequests); |
| 197 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDeviceDiscovered); | 215 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDeviceDiscovered); |
| 198 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryFinished); | 216 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryFinished); |
| 199 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryRequest); | 217 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestOnDiscoveryRequest); |
| 200 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestResponseParsing); | 218 FRIEND_TEST_ALL_PREFIXES(DialServiceTest, TestResponseParsing); |
| 201 DISALLOW_COPY_AND_ASSIGN(DialServiceImpl); | 219 DISALLOW_COPY_AND_ASSIGN(DialServiceImpl); |
| 202 }; | 220 }; |
| 203 | 221 |
| 204 } // namespace extensions | 222 } // namespace extensions |
| 205 | 223 |
| 206 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_SERVICE_H_ | 224 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_SERVICE_H_ |
| OLD | NEW |