Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/browser/sync/engine/net/server_connection_manager.h

Issue 6690020: sync: hook up ServerConnectionManager <> SyncerThread2 and tie up more loose ends (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/debug
Patch Set: fix Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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>
11 11
12 #include "base/atomicops.h" 12 #include "base/atomicops.h"
13 #include "base/observer_list_threadsafe.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
14 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
15 #include "chrome/browser/sync/syncable/syncable_id.h" 16 #include "chrome/browser/sync/syncable/syncable_id.h"
16 #include "chrome/common/deprecated/event_sys.h" 17 #include "chrome/common/deprecated/event_sys.h"
17 #include "chrome/common/deprecated/event_sys-inl.h" 18 #include "chrome/common/deprecated/event_sys-inl.h"
18 #include "chrome/common/net/http_return.h" 19 #include "chrome/common/net/http_return.h"
19 20
20 namespace syncable { 21 namespace syncable {
21 class WriteTransaction; 22 class WriteTransaction;
22 class DirectoryManager; 23 class DirectoryManager;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 : response_code(kUnsetResponseCode), 101 : response_code(kUnsetResponseCode),
101 content_length(kUnsetContentLength), 102 content_length(kUnsetContentLength),
102 payload_length(kUnsetPayloadLength), 103 payload_length(kUnsetPayloadLength),
103 server_status(NONE) {} 104 server_status(NONE) {}
104 }; 105 };
105 106
106 inline bool IsGoodReplyFromServer(HttpResponse::ServerConnectionCode code) { 107 inline bool IsGoodReplyFromServer(HttpResponse::ServerConnectionCode code) {
107 return code >= HttpResponse::SERVER_CONNECTION_OK; 108 return code >= HttpResponse::SERVER_CONNECTION_OK;
108 } 109 }
109 110
111 // TODO(tim): Deprecated.
110 struct ServerConnectionEvent { 112 struct ServerConnectionEvent {
111 // Traits. 113 // Traits.
112 typedef ServerConnectionEvent EventType; 114 typedef ServerConnectionEvent EventType;
113 enum WhatHappened { 115 enum WhatHappened {
114 SHUTDOWN, 116 SHUTDOWN,
115 STATUS_CHANGED 117 STATUS_CHANGED
116 }; 118 };
117 119
118 static inline bool IsChannelShutdownEvent(const EventType& event) { 120 static inline bool IsChannelShutdownEvent(const EventType& event) {
119 return SHUTDOWN == event.what_happened; 121 return SHUTDOWN == event.what_happened;
120 } 122 }
121 123
122 WhatHappened what_happened; 124 WhatHappened what_happened;
123 HttpResponse::ServerConnectionCode connection_code; 125 HttpResponse::ServerConnectionCode connection_code;
124 bool server_reachable; 126 bool server_reachable;
125 }; 127 };
126 128
129 struct ServerConnectionEvent2 {
130 HttpResponse::ServerConnectionCode connection_code;
131 bool server_reachable;
132 ServerConnectionEvent2(HttpResponse::ServerConnectionCode code,
133 bool server_reachable) :
134 connection_code(code), server_reachable(server_reachable) {}
135 };
136
137 class ServerConnectionEventListener {
138 public:
139 virtual void OnServerConnectionEvent(const ServerConnectionEvent2& event) = 0;
140 protected:
141 virtual ~ServerConnectionEventListener() {}
142 };
143
127 class ServerConnectionManager; 144 class ServerConnectionManager;
128 // A helper class that automatically notifies when the status changes. 145 // A helper class that automatically notifies when the status changes.
129 // TODO(tim): This class shouldn't be exposed outside of the implementation, 146 // TODO(tim): This class shouldn't be exposed outside of the implementation,
130 // bug 35060. 147 // bug 35060.
131 class ScopedServerStatusWatcher { 148 class ScopedServerStatusWatcher {
132 public: 149 public:
133 ScopedServerStatusWatcher(ServerConnectionManager* conn_mgr, 150 ScopedServerStatusWatcher(ServerConnectionManager* conn_mgr,
134 HttpResponse* response); 151 HttpResponse* response);
135 ~ScopedServerStatusWatcher(); 152 ~ScopedServerStatusWatcher();
136 private: 153 private:
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 virtual bool IsUserAuthenticated(); 250 virtual bool IsUserAuthenticated();
234 251
235 // Updates status and broadcasts events on change. 252 // Updates status and broadcasts events on change.
236 bool CheckServerReachable(); 253 bool CheckServerReachable();
237 254
238 // Signal the shutdown event to notify listeners. 255 // Signal the shutdown event to notify listeners.
239 virtual void kill(); 256 virtual void kill();
240 257
241 inline Channel* channel() const { return channel_; } 258 inline Channel* channel() const { return channel_; }
242 259
260 void AddListener(ServerConnectionEventListener* listener);
261 void RemoveListener(ServerConnectionEventListener* listener);
262
243 inline std::string user_agent() const { return user_agent_; } 263 inline std::string user_agent() const { return user_agent_; }
244 264
245 inline HttpResponse::ServerConnectionCode server_status() const { 265 inline HttpResponse::ServerConnectionCode server_status() const {
246 return server_status_; 266 return server_status_;
247 } 267 }
248 268
249 inline bool server_reachable() const { return server_reachable_; } 269 inline bool server_reachable() const { return server_reachable_; }
250 270
251 const std::string client_id() const { return client_id_; } 271 const std::string client_id() const { return client_id_; }
252 272
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 std::string proto_sync_path_; 357 std::string proto_sync_path_;
338 std::string get_time_path_; 358 std::string get_time_path_;
339 359
340 mutable base::Lock auth_token_mutex_; 360 mutable base::Lock auth_token_mutex_;
341 // The auth token to use in authenticated requests. Set by the AuthWatcher. 361 // The auth token to use in authenticated requests. Set by the AuthWatcher.
342 std::string auth_token_; 362 std::string auth_token_;
343 363
344 base::Lock error_count_mutex_; // Protects error_count_ 364 base::Lock error_count_mutex_; // Protects error_count_
345 int error_count_; // Tracks the number of connection errors. 365 int error_count_; // Tracks the number of connection errors.
346 366
367 // TODO(tim): Deprecated.
347 Channel* const channel_; 368 Channel* const channel_;
348 369
370 scoped_refptr<ObserverListThreadSafe<ServerConnectionEventListener> >
371 listeners_;
372
349 // Volatile so various threads can call server_status() without 373 // Volatile so various threads can call server_status() without
350 // synchronization. 374 // synchronization.
351 volatile HttpResponse::ServerConnectionCode server_status_; 375 volatile HttpResponse::ServerConnectionCode server_status_;
352 bool server_reachable_; 376 bool server_reachable_;
353 377
354 // A counter that is incremented everytime ResetAuthStatus() is called. 378 // A counter that is incremented everytime ResetAuthStatus() is called.
355 volatile base::subtle::AtomicWord reset_count_; 379 volatile base::subtle::AtomicWord reset_count_;
356 380
357 private: 381 private:
358 friend class Post; 382 friend class Post;
(...skipping 11 matching lines...) Expand all
370 // settings. 394 // settings.
371 bool FillMessageWithShareDetails(sync_pb::ClientToServerMessage* csm, 395 bool FillMessageWithShareDetails(sync_pb::ClientToServerMessage* csm,
372 syncable::DirectoryManager* manager, 396 syncable::DirectoryManager* manager,
373 const std::string& share); 397 const std::string& share);
374 398
375 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); 399 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr);
376 400
377 } // namespace browser_sync 401 } // namespace browser_sync
378 402
379 #endif // CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ 403 #endif // CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/model_safe_worker.cc ('k') | chrome/browser/sync/engine/net/server_connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698