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 13 matching lines...) Expand all Loading... |
24 } | 24 } |
25 | 25 |
26 namespace sync_pb { | 26 namespace sync_pb { |
27 class ClientToServerMessage; | 27 class ClientToServerMessage; |
28 } | 28 } |
29 | 29 |
30 namespace browser_sync { | 30 namespace browser_sync { |
31 | 31 |
32 class ClientToServerMessage; | 32 class ClientToServerMessage; |
33 | 33 |
34 // How many connection errors are accepted before network handles are closed | |
35 // and reopened. | |
36 static const int32 kMaxConnectionErrorsBeforeReset = 10; | |
37 | |
38 static const int32 kUnsetResponseCode = -1; | 34 static const int32 kUnsetResponseCode = -1; |
39 static const int32 kUnsetContentLength = -1; | 35 static const int32 kUnsetContentLength = -1; |
40 static const int32 kUnsetPayloadLength = -1; | 36 static const int32 kUnsetPayloadLength = -1; |
41 | 37 |
42 // HttpResponse gathers the relevant output properties of an HTTP request. | 38 // HttpResponse gathers the relevant output properties of an HTTP request. |
43 // Depending on the value of the server_status code, response_code, and | 39 // Depending on the value of the server_status code, response_code, and |
44 // content_length may not be valid. | 40 // content_length may not be valid. |
45 struct HttpResponse { | 41 struct HttpResponse { |
46 enum ServerConnectionCode { | 42 enum ServerConnectionCode { |
47 // For uninitialized state. | 43 // For uninitialized state. |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 288 |
293 protected: | 289 protected: |
294 inline std::string proto_sync_path() const { | 290 inline std::string proto_sync_path() const { |
295 return proto_sync_path_; | 291 return proto_sync_path_; |
296 } | 292 } |
297 | 293 |
298 std::string get_time_path() const { | 294 std::string get_time_path() const { |
299 return get_time_path_; | 295 return get_time_path_; |
300 } | 296 } |
301 | 297 |
302 // Called wherever a failure should be taken as an indication that we may | |
303 // be experiencing connection difficulties. | |
304 virtual bool IncrementErrorCount(); | |
305 | |
306 // NOTE: Tests rely on this protected function being virtual. | 298 // NOTE: Tests rely on this protected function being virtual. |
307 // | 299 // |
308 // Internal PostBuffer base function. | 300 // Internal PostBuffer base function. |
309 virtual bool PostBufferToPath(PostBufferParams*, | 301 virtual bool PostBufferToPath(PostBufferParams*, |
310 const std::string& path, | 302 const std::string& path, |
311 const std::string& auth_token, | 303 const std::string& auth_token, |
312 ScopedServerStatusWatcher* watcher); | 304 ScopedServerStatusWatcher* watcher); |
313 | 305 |
314 // Helper to check terminated flags and build a Connection object, installing | 306 // Helper to check terminated flags and build a Connection object, installing |
315 // it as the |active_connection_|. If this ServerConnectionManager has been | 307 // it as the |active_connection_|. If this ServerConnectionManager has been |
(...skipping 22 matching lines...) Expand all Loading... |
338 // The paths we post to. | 330 // The paths we post to. |
339 std::string proto_sync_path_; | 331 std::string proto_sync_path_; |
340 std::string get_time_path_; | 332 std::string get_time_path_; |
341 | 333 |
342 // The auth token to use in authenticated requests. Set by the AuthWatcher. | 334 // The auth token to use in authenticated requests. Set by the AuthWatcher. |
343 std::string auth_token_; | 335 std::string auth_token_; |
344 | 336 |
345 // The previous auth token that is invalid now. | 337 // The previous auth token that is invalid now. |
346 std::string previously_invalidated_token; | 338 std::string previously_invalidated_token; |
347 | 339 |
348 int error_count_; // Tracks the number of connection errors. | |
349 | |
350 ObserverList<ServerConnectionEventListener> listeners_; | 340 ObserverList<ServerConnectionEventListener> listeners_; |
351 | 341 |
352 HttpResponse::ServerConnectionCode server_status_; | 342 HttpResponse::ServerConnectionCode server_status_; |
353 bool server_reachable_; | 343 bool server_reachable_; |
354 | 344 |
355 base::ThreadChecker thread_checker_; | 345 base::ThreadChecker thread_checker_; |
356 | 346 |
357 // Protects all variables below to allow bailing out of active connections. | 347 // Protects all variables below to allow bailing out of active connections. |
358 base::Lock terminate_connection_lock_; | 348 base::Lock terminate_connection_lock_; |
359 | 349 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 // settings. | 385 // settings. |
396 bool FillMessageWithShareDetails(sync_pb::ClientToServerMessage* csm, | 386 bool FillMessageWithShareDetails(sync_pb::ClientToServerMessage* csm, |
397 syncable::DirectoryManager* manager, | 387 syncable::DirectoryManager* manager, |
398 const std::string& share); | 388 const std::string& share); |
399 | 389 |
400 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); | 390 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); |
401 | 391 |
402 } // namespace browser_sync | 392 } // namespace browser_sync |
403 | 393 |
404 #endif // CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 394 #endif // CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
OLD | NEW |