Chromium Code Reviews| Index: sync/engine/net/server_connection_manager.h |
| diff --git a/sync/engine/net/server_connection_manager.h b/sync/engine/net/server_connection_manager.h |
| index 3bd533e78fdd07d555e54d296e9b70465fd5bbf6..a00c0e873e6425132a37a8dc4e631d72cec8208f 100644 |
| --- a/sync/engine/net/server_connection_manager.h |
| +++ b/sync/engine/net/server_connection_manager.h |
| @@ -8,14 +8,13 @@ |
| #include <iosfwd> |
| #include <string> |
| -#include "base/atomicops.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/observer_list.h" |
| #include "base/strings/string_util.h" |
| -#include "base/synchronization/lock.h" |
| #include "base/threading/non_thread_safe.h" |
| #include "base/threading/thread_checker.h" |
| #include "sync/base/sync_export.h" |
| +#include "sync/internal_api/public/base/cancelation_observer.h" |
| #include "sync/syncable/syncable_id.h" |
| namespace sync_pb { |
| @@ -24,6 +23,8 @@ class ClientToServerMessage; |
| namespace syncer { |
| +class CancelationSignal; |
| + |
| namespace syncable { |
| class Directory; |
| } |
| @@ -183,7 +184,8 @@ class SYNC_EXPORT_PRIVATE ServerConnectionManager { |
| ServerConnectionManager(const std::string& server, |
| int port, |
| bool use_ssl, |
| - bool use_oauth2_token); |
| + bool use_oauth2_token, |
| + CancelationSignal* const cancelation_signal); |
|
tim (not reviewing)
2013/09/06 21:47:34
I think you can omit the *const here and keep it i
rlarocque
2013/09/06 22:42:53
Yep, this is the result of a regex gone wrong. I
|
| virtual ~ServerConnectionManager(); |
| @@ -213,13 +215,7 @@ class SYNC_EXPORT_PRIVATE ServerConnectionManager { |
| // Factory method to create an Connection object we can use for |
| // communication with the server. |
| - virtual Connection* MakeConnection(); |
| - |
| - // Aborts any active HTTP POST request. |
| - // We expect this to get called on a different thread than the valid |
| - // ThreadChecker thread, as we want to kill any pending http traffic without |
| - // having to wait for the request to complete. |
| - void TerminateAllIO(); |
| + virtual scoped_ptr<Connection> MakeConnection(); |
| void set_client_id(const std::string& client_id) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| @@ -272,10 +268,6 @@ class SYNC_EXPORT_PRIVATE ServerConnectionManager { |
| // terminated, this will return NULL. |
| Connection* MakeActiveConnection(); |
| - // Called by Connection objects as they are destroyed to allow the |
| - // ServerConnectionManager to cleanup active connections. |
| - void OnConnectionDestroyed(Connection* connection); |
| - |
| // The sync_server_ is the server that requests will be made to. |
| std::string sync_server_; |
| @@ -308,35 +300,34 @@ class SYNC_EXPORT_PRIVATE ServerConnectionManager { |
| base::ThreadChecker thread_checker_; |
| - // Protects all variables below to allow bailing out of active connections. |
| - base::Lock terminate_connection_lock_; |
| - |
| - // If true, we've been told to terminate IO and expect to be destroyed |
| - // shortly. No future network requests will be made. |
| - bool terminated_; |
| - |
| - // A non-owning pointer to any active http connection, so that we can abort |
| - // it if necessary. |
| - Connection* active_connection_; |
| + CancelationSignal* const cancelation_signal_; |
| private: |
| friend class Connection; |
| friend class ScopedServerStatusWatcher; |
| - // A class to help deal with cleaning up active Connection objects when (for |
| - // ex) multiple early-exits are present in some scope. ScopedConnectionHelper |
| - // informs the ServerConnectionManager before the Connection object it takes |
| - // ownership of is destroyed. |
| - class ScopedConnectionHelper { |
| + // A class to help manage the active connection. It handles the registration |
| + // and unregistration with the CancelationSignal. It also takes ownership of |
| + // the connection and will delete it if the abort signal was sent early or |
| + // when this class goes out of scope. |
| + class ScopedConnectionHelper : public CancelationObserver { |
| public: |
| - // |manager| must outlive this. Takes ownership of |connection|. |
| - ScopedConnectionHelper(ServerConnectionManager* manager, |
| - Connection* connection); |
| - ~ScopedConnectionHelper(); |
| + ScopedConnectionHelper(CancelationSignal* cancelation_signal, |
| + scoped_ptr<Connection> connection); |
| + virtual ~ScopedConnectionHelper(); |
| Connection* get(); |
| + |
| + // Called from a different thread when the CancelationObserver's |
| + // RequestStop() is called and this class has been registered as a handler. |
| + // |
| + // Marked final because there's no way to safely override it. See comment |
| + // in this class' destructor. |
| + virtual void OnStopRequested() OVERRIDE FINAL; |
| + |
| private: |
| - ServerConnectionManager* manager_; |
| + CancelationSignal* const cancelation_signal_; |
| scoped_ptr<Connection> connection_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ScopedConnectionHelper); |
| }; |