OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 COMPONENTS_SYNC_ENGINE_IMPL_NET_SERVER_CONNECTION_MANAGER_H_ | 5 #ifndef COMPONENTS_SYNC_ENGINE_IMPL_NET_SERVER_CONNECTION_MANAGER_H_ |
6 #define COMPONENTS_SYNC_ENGINE_IMPL_NET_SERVER_CONNECTION_MANAGER_H_ | 6 #define COMPONENTS_SYNC_ENGINE_IMPL_NET_SERVER_CONNECTION_MANAGER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <iosfwd> | 10 #include <iosfwd> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/atomicops.h" | 14 #include "base/atomicops.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "base/threading/non_thread_safe.h" | 19 #include "base/threading/non_thread_safe.h" |
20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
21 #include "components/sync/base/cancelation_observer.h" | 21 #include "components/sync/base/cancelation_observer.h" |
22 #include "components/sync/base/sync_export.h" | |
23 #include "components/sync/syncable/syncable_id.h" | 22 #include "components/sync/syncable/syncable_id.h" |
24 | 23 |
25 namespace sync_pb { | 24 namespace sync_pb { |
26 class ClientToServerMessage; | 25 class ClientToServerMessage; |
27 } | 26 } |
28 | 27 |
29 namespace syncer { | 28 namespace syncer { |
30 | 29 |
31 class CancelationSignal; | 30 class CancelationSignal; |
32 | 31 |
33 namespace syncable { | 32 namespace syncable { |
34 class Directory; | 33 class Directory; |
35 } | 34 } |
36 | 35 |
37 static const int32_t kUnsetResponseCode = -1; | 36 static const int32_t kUnsetResponseCode = -1; |
38 static const int32_t kUnsetContentLength = -1; | 37 static const int32_t kUnsetContentLength = -1; |
39 static const int32_t kUnsetPayloadLength = -1; | 38 static const int32_t kUnsetPayloadLength = -1; |
40 | 39 |
41 // HttpResponse gathers the relevant output properties of an HTTP request. | 40 // HttpResponse gathers the relevant output properties of an HTTP request. |
42 // Depending on the value of the server_status code, response_code, and | 41 // Depending on the value of the server_status code, response_code, and |
43 // content_length may not be valid. | 42 // content_length may not be valid. |
44 struct SYNC_EXPORT HttpResponse { | 43 struct HttpResponse { |
45 enum ServerConnectionCode { | 44 enum ServerConnectionCode { |
46 // For uninitialized state. | 45 // For uninitialized state. |
47 NONE, | 46 NONE, |
48 | 47 |
49 // CONNECTION_UNAVAILABLE is returned when InternetConnect() fails. | 48 // CONNECTION_UNAVAILABLE is returned when InternetConnect() fails. |
50 CONNECTION_UNAVAILABLE, | 49 CONNECTION_UNAVAILABLE, |
51 | 50 |
52 // IO_ERROR is returned when reading/writing to a buffer has failed. | 51 // IO_ERROR is returned when reading/writing to a buffer has failed. |
53 IO_ERROR, | 52 IO_ERROR, |
54 | 53 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 90 |
92 static const char* GetServerConnectionCodeString(ServerConnectionCode code); | 91 static const char* GetServerConnectionCodeString(ServerConnectionCode code); |
93 }; | 92 }; |
94 | 93 |
95 struct ServerConnectionEvent { | 94 struct ServerConnectionEvent { |
96 HttpResponse::ServerConnectionCode connection_code; | 95 HttpResponse::ServerConnectionCode connection_code; |
97 explicit ServerConnectionEvent(HttpResponse::ServerConnectionCode code) | 96 explicit ServerConnectionEvent(HttpResponse::ServerConnectionCode code) |
98 : connection_code(code) {} | 97 : connection_code(code) {} |
99 }; | 98 }; |
100 | 99 |
101 class SYNC_EXPORT ServerConnectionEventListener { | 100 class ServerConnectionEventListener { |
102 public: | 101 public: |
103 virtual void OnServerConnectionEvent(const ServerConnectionEvent& event) = 0; | 102 virtual void OnServerConnectionEvent(const ServerConnectionEvent& event) = 0; |
104 | 103 |
105 protected: | 104 protected: |
106 virtual ~ServerConnectionEventListener() {} | 105 virtual ~ServerConnectionEventListener() {} |
107 }; | 106 }; |
108 | 107 |
109 // Use this class to interact with the sync server. | 108 // Use this class to interact with the sync server. |
110 // The ServerConnectionManager currently supports POSTing protocol buffers. | 109 // The ServerConnectionManager currently supports POSTing protocol buffers. |
111 // | 110 // |
112 class SYNC_EXPORT ServerConnectionManager : public CancelationObserver { | 111 class ServerConnectionManager : public CancelationObserver { |
113 public: | 112 public: |
114 // buffer_in - will be POSTed | 113 // buffer_in - will be POSTed |
115 // buffer_out - string will be overwritten with response | 114 // buffer_out - string will be overwritten with response |
116 struct PostBufferParams { | 115 struct PostBufferParams { |
117 std::string buffer_in; | 116 std::string buffer_in; |
118 std::string buffer_out; | 117 std::string buffer_out; |
119 HttpResponse response; | 118 HttpResponse response; |
120 }; | 119 }; |
121 | 120 |
122 // Abstract class providing network-layer functionality to the | 121 // Abstract class providing network-layer functionality to the |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 bool signal_handler_registered_; | 300 bool signal_handler_registered_; |
302 | 301 |
303 DISALLOW_COPY_AND_ASSIGN(ServerConnectionManager); | 302 DISALLOW_COPY_AND_ASSIGN(ServerConnectionManager); |
304 }; | 303 }; |
305 | 304 |
306 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); | 305 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); |
307 | 306 |
308 } // namespace syncer | 307 } // namespace syncer |
309 | 308 |
310 #endif // COMPONENTS_SYNC_ENGINE_IMPL_NET_SERVER_CONNECTION_MANAGER_H_ | 309 #endif // COMPONENTS_SYNC_ENGINE_IMPL_NET_SERVER_CONNECTION_MANAGER_H_ |
OLD | NEW |