OLD | NEW |
1 // Copyright (c) 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 SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 5 #ifndef SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
6 #define SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 6 #define SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/atomicops.h" | 11 #include "base/atomicops.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 18 #include "sync/base/sync_export.h" |
18 #include "sync/syncable/syncable_id.h" | 19 #include "sync/syncable/syncable_id.h" |
19 | 20 |
20 namespace sync_pb { | 21 namespace sync_pb { |
21 class ClientToServerMessage; | 22 class ClientToServerMessage; |
22 } | 23 } |
23 | 24 |
24 namespace syncer { | 25 namespace syncer { |
25 | 26 |
26 namespace syncable { | 27 namespace syncable { |
27 class Directory; | 28 class Directory; |
28 } | 29 } |
29 | 30 |
30 static const int32 kUnsetResponseCode = -1; | 31 static const int32 kUnsetResponseCode = -1; |
31 static const int32 kUnsetContentLength = -1; | 32 static const int32 kUnsetContentLength = -1; |
32 static const int32 kUnsetPayloadLength = -1; | 33 static const int32 kUnsetPayloadLength = -1; |
33 | 34 |
34 // HttpResponse gathers the relevant output properties of an HTTP request. | 35 // HttpResponse gathers the relevant output properties of an HTTP request. |
35 // Depending on the value of the server_status code, response_code, and | 36 // Depending on the value of the server_status code, response_code, and |
36 // content_length may not be valid. | 37 // content_length may not be valid. |
37 struct HttpResponse { | 38 struct SYNC_EXPORT_PRIVATE HttpResponse { |
38 enum ServerConnectionCode { | 39 enum ServerConnectionCode { |
39 // For uninitialized state. | 40 // For uninitialized state. |
40 NONE, | 41 NONE, |
41 | 42 |
42 // CONNECTION_UNAVAILABLE is returned when InternetConnect() fails. | 43 // CONNECTION_UNAVAILABLE is returned when InternetConnect() fails. |
43 CONNECTION_UNAVAILABLE, | 44 CONNECTION_UNAVAILABLE, |
44 | 45 |
45 // IO_ERROR is returned when reading/writing to a buffer has failed. | 46 // IO_ERROR is returned when reading/writing to a buffer has failed. |
46 IO_ERROR, | 47 IO_ERROR, |
47 | 48 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 static const char* GetServerConnectionCodeString( | 89 static const char* GetServerConnectionCodeString( |
89 ServerConnectionCode code); | 90 ServerConnectionCode code); |
90 }; | 91 }; |
91 | 92 |
92 struct ServerConnectionEvent { | 93 struct ServerConnectionEvent { |
93 HttpResponse::ServerConnectionCode connection_code; | 94 HttpResponse::ServerConnectionCode connection_code; |
94 explicit ServerConnectionEvent(HttpResponse::ServerConnectionCode code) : | 95 explicit ServerConnectionEvent(HttpResponse::ServerConnectionCode code) : |
95 connection_code(code) {} | 96 connection_code(code) {} |
96 }; | 97 }; |
97 | 98 |
98 class ServerConnectionEventListener { | 99 class SYNC_EXPORT_PRIVATE ServerConnectionEventListener { |
99 public: | 100 public: |
100 virtual void OnServerConnectionEvent(const ServerConnectionEvent& event) = 0; | 101 virtual void OnServerConnectionEvent(const ServerConnectionEvent& event) = 0; |
101 protected: | 102 protected: |
102 virtual ~ServerConnectionEventListener() {} | 103 virtual ~ServerConnectionEventListener() {} |
103 }; | 104 }; |
104 | 105 |
105 class ServerConnectionManager; | 106 class ServerConnectionManager; |
106 // A helper class that automatically notifies when the status changes. | 107 // A helper class that automatically notifies when the status changes. |
107 // TODO(tim): This class shouldn't be exposed outside of the implementation, | 108 // TODO(tim): This class shouldn't be exposed outside of the implementation, |
108 // bug 35060. | 109 // bug 35060. |
109 class ScopedServerStatusWatcher : public base::NonThreadSafe { | 110 class SYNC_EXPORT_PRIVATE ScopedServerStatusWatcher |
| 111 : public base::NonThreadSafe { |
110 public: | 112 public: |
111 ScopedServerStatusWatcher(ServerConnectionManager* conn_mgr, | 113 ScopedServerStatusWatcher(ServerConnectionManager* conn_mgr, |
112 HttpResponse* response); | 114 HttpResponse* response); |
113 virtual ~ScopedServerStatusWatcher(); | 115 virtual ~ScopedServerStatusWatcher(); |
114 private: | 116 private: |
115 ServerConnectionManager* const conn_mgr_; | 117 ServerConnectionManager* const conn_mgr_; |
116 HttpResponse* const response_; | 118 HttpResponse* const response_; |
117 DISALLOW_COPY_AND_ASSIGN(ScopedServerStatusWatcher); | 119 DISALLOW_COPY_AND_ASSIGN(ScopedServerStatusWatcher); |
118 }; | 120 }; |
119 | 121 |
120 // Use this class to interact with the sync server. | 122 // Use this class to interact with the sync server. |
121 // The ServerConnectionManager currently supports POSTing protocol buffers. | 123 // The ServerConnectionManager currently supports POSTing protocol buffers. |
122 // | 124 // |
123 class ServerConnectionManager { | 125 class SYNC_EXPORT_PRIVATE ServerConnectionManager { |
124 public: | 126 public: |
125 // buffer_in - will be POSTed | 127 // buffer_in - will be POSTed |
126 // buffer_out - string will be overwritten with response | 128 // buffer_out - string will be overwritten with response |
127 struct PostBufferParams { | 129 struct PostBufferParams { |
128 std::string buffer_in; | 130 std::string buffer_in; |
129 std::string buffer_out; | 131 std::string buffer_out; |
130 HttpResponse response; | 132 HttpResponse response; |
131 }; | 133 }; |
132 | 134 |
133 // Abstract class providing network-layer functionality to the | 135 // Abstract class providing network-layer functionality to the |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 // settings. | 345 // settings. |
344 bool FillMessageWithShareDetails(sync_pb::ClientToServerMessage* csm, | 346 bool FillMessageWithShareDetails(sync_pb::ClientToServerMessage* csm, |
345 syncable::Directory* manager, | 347 syncable::Directory* manager, |
346 const std::string& share); | 348 const std::string& share); |
347 | 349 |
348 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); | 350 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); |
349 | 351 |
350 } // namespace syncer | 352 } // namespace syncer |
351 | 353 |
352 #endif // SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 354 #endif // SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
OLD | NEW |