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

Unified Diff: chrome/browser/sync/engine/net/server_connection_manager.h

Issue 7792022: sync: abort active HTTP requests on shutdown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: initial Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/engine/net/server_connection_manager.h
diff --git a/chrome/browser/sync/engine/net/server_connection_manager.h b/chrome/browser/sync/engine/net/server_connection_manager.h
index bc26ac6ab9c4c56ac86e80047ce00589bbee6349..88366f364a788864b575c1b9fbfbf9e218e5d3d4 100644
--- a/chrome/browser/sync/engine/net/server_connection_manager.h
+++ b/chrome/browser/sync/engine/net/server_connection_manager.h
@@ -13,6 +13,7 @@
#include "base/observer_list.h"
#include "base/string_util.h"
#include "base/threading/non_thread_safe.h"
+#include "base/threading/thread_checker.h"
#include "base/synchronization/lock.h"
#include "chrome/browser/sync/syncable/syncable_id.h"
#include "chrome/common/net/http_return.h"
@@ -140,7 +141,7 @@ class ScopedServerStatusWatcher : public base::NonThreadSafe {
// Use this class to interact with the sync server.
// The ServerConnectionManager currently supports POSTing protocol buffers.
//
-class ServerConnectionManager : public base::NonThreadSafe {
+class ServerConnectionManager {
public:
// buffer_in - will be POSTed
// buffer_out - string will be overwritten with response
@@ -154,11 +155,10 @@ class ServerConnectionManager : public base::NonThreadSafe {
// Abstract class providing network-layer functionality to the
// ServerConnectionManager. Subclasses implement this using an HTTP stack of
// their choice.
- class Post {
+ class Connection {
public:
- explicit Post(ServerConnectionManager* scm) : scm_(scm), timing_info_(0) {
- }
- virtual ~Post() { }
+ explicit Connection(ServerConnectionManager* scm);
+ virtual ~Connection();
// Called to initialize and perform an HTTP POST.
virtual bool Init(const char* path,
@@ -166,6 +166,10 @@ class ServerConnectionManager : public base::NonThreadSafe {
const std::string& payload,
HttpResponse* response) = 0;
+ // Immediately abandons a pending HTTP POST request and unblocks caller
+ // in Init.
+ virtual void Abort() = 0;
+
bool ReadBufferResponse(std::string* buffer_out, HttpResponse* response,
bool require_response);
bool ReadDownloadResponse(HttpResponse* response, std::string* buffer_out);
@@ -231,7 +235,7 @@ class ServerConnectionManager : public base::NonThreadSafe {
inline std::string user_agent() const { return user_agent_; }
inline HttpResponse::ServerConnectionCode server_status() const {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
return server_status_;
}
@@ -254,19 +258,25 @@ class ServerConnectionManager : public base::NonThreadSafe {
std::string GetServerHost() const;
- // Factory method to create a Post object we can use for communication with
- // the server.
- virtual Post* MakePost();
+ // 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();
void set_client_id(const std::string& client_id) {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(client_id_.empty());
client_id_.assign(client_id);
}
// Returns true if the auth token is succesfully set and false otherwise.
bool set_auth_token(const std::string& auth_token) {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
if (previously_invalidated_token != auth_token) {
auth_token_.assign(auth_token);
previously_invalidated_token = std::string();
@@ -276,7 +286,7 @@ class ServerConnectionManager : public base::NonThreadSafe {
}
void InvalidateAndClearAuthToken() {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
// Copy over the token to previous invalid token.
if (!auth_token_.empty()) {
previously_invalidated_token.assign(auth_token_);
@@ -285,7 +295,7 @@ class ServerConnectionManager : public base::NonThreadSafe {
}
const std::string auth_token() const {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
return auth_token_;
}
@@ -342,8 +352,21 @@ class ServerConnectionManager : public base::NonThreadSafe {
HttpResponse::ServerConnectionCode server_status_;
bool server_reachable_;
+ 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_;
+
private:
- friend class Post;
+ friend class Connection;
friend class ScopedServerStatusWatcher;
void NotifyStatusChanged();

Powered by Google App Engine
This is Rietveld 408576698