OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
6 #define CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 6 #define CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <iosfwd> | 9 #include <iosfwd> |
10 #include <string> | 10 #include <string> |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 virtual ~ServerConnectionManager(); | 196 virtual ~ServerConnectionManager(); |
197 | 197 |
198 // POSTS buffer_in and reads a response into buffer_out. Uses our currently | 198 // POSTS buffer_in and reads a response into buffer_out. Uses our currently |
199 // set auth token in our headers. | 199 // set auth token in our headers. |
200 // | 200 // |
201 // Returns true if executed successfully. | 201 // Returns true if executed successfully. |
202 virtual bool PostBufferWithCachedAuth(PostBufferParams* params, | 202 virtual bool PostBufferWithCachedAuth(PostBufferParams* params, |
203 ScopedServerStatusWatcher* watcher); | 203 ScopedServerStatusWatcher* watcher); |
204 | 204 |
205 // Checks the time on the server. Returns false if the request failed. |time| | |
206 // is an out parameter that stores the value returned from the server. | |
207 virtual bool CheckTime(int32* out_time); | |
208 | |
209 // Returns true if sync_server_ is reachable. This method verifies that the | |
210 // server is pingable and that traffic can be sent to and from it. | |
211 virtual bool IsServerReachable(); | |
212 | |
213 // Returns true if user has been successfully authenticated. | |
214 virtual bool IsUserAuthenticated(); | |
215 | |
216 // Updates status and broadcasts events on change. | |
217 bool CheckServerReachable(); | |
218 | |
219 void AddListener(ServerConnectionEventListener* listener); | 205 void AddListener(ServerConnectionEventListener* listener); |
220 void RemoveListener(ServerConnectionEventListener* listener); | 206 void RemoveListener(ServerConnectionEventListener* listener); |
221 | 207 |
222 inline std::string user_agent() const { return user_agent_; } | 208 inline std::string user_agent() const { return user_agent_; } |
223 | 209 |
224 inline HttpResponse::ServerConnectionCode server_status() const { | 210 inline HttpResponse::ServerConnectionCode server_status() const { |
225 DCHECK(thread_checker_.CalledOnValidThread()); | 211 DCHECK(thread_checker_.CalledOnValidThread()); |
226 return server_status_; | 212 return server_status_; |
227 } | 213 } |
228 | 214 |
229 inline bool server_reachable() const { return server_reachable_; } | 215 inline bool server_reachable() const { return server_reachable_; } |
230 | 216 |
231 const std::string client_id() const { return client_id_; } | 217 const std::string client_id() const { return client_id_; } |
232 | 218 |
233 // This changes the server info used by the connection manager. This allows | |
234 // a single client instance to talk to different backing servers. This is | |
235 // typically called during / after authentication so that the server url | |
236 // can be a function of the user's login id. | |
237 void SetServerParameters(const std::string& server_url, | |
238 int port, | |
239 bool use_ssl); | |
240 | |
241 // Returns the current server parameters in server_url, port and use_ssl. | 219 // Returns the current server parameters in server_url, port and use_ssl. |
242 void GetServerParameters(std::string* server_url, | 220 void GetServerParameters(std::string* server_url, |
243 int* port, | 221 int* port, |
244 bool* use_ssl) const; | 222 bool* use_ssl) const; |
245 | 223 |
246 std::string GetServerHost() const; | 224 std::string GetServerHost() const; |
247 | 225 |
248 // Factory method to create an Connection object we can use for | 226 // Factory method to create an Connection object we can use for |
249 // communication with the server. | 227 // communication with the server. |
250 virtual Connection* MakeConnection(); | 228 virtual Connection* MakeConnection(); |
(...skipping 23 matching lines...) Expand all Loading... |
274 | 252 |
275 void InvalidateAndClearAuthToken() { | 253 void InvalidateAndClearAuthToken() { |
276 DCHECK(thread_checker_.CalledOnValidThread()); | 254 DCHECK(thread_checker_.CalledOnValidThread()); |
277 // Copy over the token to previous invalid token. | 255 // Copy over the token to previous invalid token. |
278 if (!auth_token_.empty()) { | 256 if (!auth_token_.empty()) { |
279 previously_invalidated_token.assign(auth_token_); | 257 previously_invalidated_token.assign(auth_token_); |
280 auth_token_ = std::string(); | 258 auth_token_ = std::string(); |
281 } | 259 } |
282 } | 260 } |
283 | 261 |
| 262 bool HasInvalidAuthToken() { |
| 263 return auth_token_.empty(); |
| 264 } |
| 265 |
284 const std::string auth_token() const { | 266 const std::string auth_token() const { |
285 DCHECK(thread_checker_.CalledOnValidThread()); | 267 DCHECK(thread_checker_.CalledOnValidThread()); |
286 return auth_token_; | 268 return auth_token_; |
287 } | 269 } |
288 | 270 |
289 protected: | 271 protected: |
290 inline std::string proto_sync_path() const { | 272 inline std::string proto_sync_path() const { |
291 return proto_sync_path_; | 273 return proto_sync_path_; |
292 } | 274 } |
293 | 275 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 // settings. | 367 // settings. |
386 bool FillMessageWithShareDetails(sync_pb::ClientToServerMessage* csm, | 368 bool FillMessageWithShareDetails(sync_pb::ClientToServerMessage* csm, |
387 syncable::DirectoryManager* manager, | 369 syncable::DirectoryManager* manager, |
388 const std::string& share); | 370 const std::string& share); |
389 | 371 |
390 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); | 372 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); |
391 | 373 |
392 } // namespace browser_sync | 374 } // namespace browser_sync |
393 | 375 |
394 #endif // CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 376 #endif // CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
OLD | NEW |