Commit a0f2f3b5 authored by Pavel Yatsuk's avatar Pavel Yatsuk Committed by Commit Bot

[Sync] A few random cleanups

- Tightening access to ServerConnectionManager members
- Removing redindant functions in url_translator
- raw pointer => unique_ptr in commit.h
- Iterators => range-based loop in ProcessDownloadedUpdates

BUG=
R=pnoland@chromium.org

Change-Id: I11775719ee08d901bc2568e8298af396f417b751
Reviewed-on: https://chromium-review.googlesource.com/565650Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Commit-Queue: Pavel Yatsuk <pavely@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485402}
parent 872e1e6a
...@@ -50,15 +50,16 @@ Commit::~Commit() { ...@@ -50,15 +50,16 @@ Commit::~Commit() {
DCHECK(cleaned_up_); DCHECK(cleaned_up_);
} }
Commit* Commit::Init(ModelTypeSet requested_types, // static
ModelTypeSet enabled_types, std::unique_ptr<Commit> Commit::Init(ModelTypeSet requested_types,
size_t max_entries, ModelTypeSet enabled_types,
const std::string& account_name, size_t max_entries,
const std::string& cache_guid, const std::string& account_name,
bool cookie_jar_mismatch, const std::string& cache_guid,
bool cookie_jar_empty, bool cookie_jar_mismatch,
CommitProcessor* commit_processor, bool cookie_jar_empty,
ExtensionsActivity* extensions_activity) { CommitProcessor* commit_processor,
ExtensionsActivity* extensions_activity) {
// Gather per-type contributions. // Gather per-type contributions.
ContributionMap contributions; ContributionMap contributions;
commit_processor->GatherCommitContributions(requested_types, max_entries, commit_processor->GatherCommitContributions(requested_types, max_entries,
...@@ -109,8 +110,8 @@ Commit* Commit::Init(ModelTypeSet requested_types, ...@@ -109,8 +110,8 @@ Commit* Commit::Init(ModelTypeSet requested_types,
} }
// If we made it this far, then we've successfully prepared a commit message. // If we made it this far, then we've successfully prepared a commit message.
return new Commit(std::move(contributions), message, return base::MakeUnique<Commit>(std::move(contributions), message,
extensions_activity_buffer); extensions_activity_buffer);
} }
SyncerError Commit::PostAndProcessResponse( SyncerError Commit::PostAndProcessResponse(
......
...@@ -47,15 +47,15 @@ class Commit { ...@@ -47,15 +47,15 @@ class Commit {
~Commit(); ~Commit();
// |extensions_activity| may be null. // |extensions_activity| may be null.
static Commit* Init(ModelTypeSet requested_types, static std::unique_ptr<Commit> Init(ModelTypeSet requested_types,
ModelTypeSet enabled_types, ModelTypeSet enabled_types,
size_t max_entries, size_t max_entries,
const std::string& account_name, const std::string& account_name,
const std::string& cache_guid, const std::string& cache_guid,
bool cookie_jar_mismatch, bool cookie_jar_mismatch,
bool cookie_jar_empty, bool cookie_jar_empty,
CommitProcessor* commit_processor, CommitProcessor* commit_processor,
ExtensionsActivity* extensions_activity); ExtensionsActivity* extensions_activity);
// |extensions_activity| may be null. // |extensions_activity| may be null.
SyncerError PostAndProcessResponse(NudgeTracker* nudge_tracker, SyncerError PostAndProcessResponse(NudgeTracker* nudge_tracker,
......
...@@ -222,7 +222,7 @@ void ServerConnectionManager::InvalidateAndClearAuthToken() { ...@@ -222,7 +222,7 @@ void ServerConnectionManager::InvalidateAndClearAuthToken() {
// Copy over the token to previous invalid token. // Copy over the token to previous invalid token.
if (!auth_token_.empty()) { if (!auth_token_.empty()) {
previously_invalidated_token.assign(auth_token_); previously_invalidated_token.assign(auth_token_);
auth_token_ = std::string(); auth_token_.clear();
} }
} }
......
...@@ -228,6 +228,27 @@ class ServerConnectionManager : public CancelationObserver { ...@@ -228,6 +228,27 @@ class ServerConnectionManager : public CancelationObserver {
// ServerConnectionManager to cleanup active connections. // ServerConnectionManager to cleanup active connections.
void OnConnectionDestroyed(Connection* connection); void OnConnectionDestroyed(Connection* connection);
private:
// 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 {
public:
// |manager| must outlive this. Takes ownership of |connection|.
ScopedConnectionHelper(ServerConnectionManager* manager,
Connection* connection);
~ScopedConnectionHelper();
Connection* get();
private:
ServerConnectionManager* manager_;
std::unique_ptr<Connection> connection_;
DISALLOW_COPY_AND_ASSIGN(ScopedConnectionHelper);
};
void NotifyStatusChanged();
// The sync_server_ is the server that requests will be made to. // The sync_server_ is the server that requests will be made to.
std::string sync_server_; std::string sync_server_;
...@@ -266,27 +287,6 @@ class ServerConnectionManager : public CancelationObserver { ...@@ -266,27 +287,6 @@ class ServerConnectionManager : public CancelationObserver {
// it if necessary. // it if necessary.
Connection* active_connection_; Connection* active_connection_;
private:
// 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 {
public:
// |manager| must outlive this. Takes ownership of |connection|.
ScopedConnectionHelper(ServerConnectionManager* manager,
Connection* connection);
~ScopedConnectionHelper();
Connection* get();
private:
ServerConnectionManager* manager_;
std::unique_ptr<Connection> connection_;
DISALLOW_COPY_AND_ASSIGN(ScopedConnectionHelper);
};
void NotifyStatusChanged();
CancelationSignal* const cancelation_signal_; CancelationSignal* const cancelation_signal_;
bool signal_handler_registered_; bool signal_handler_registered_;
......
...@@ -22,15 +22,6 @@ const char kClientName[] = "Chromium"; ...@@ -22,15 +22,6 @@ const char kClientName[] = "Chromium";
#endif // defined(GOOGLE_CHROME_BUILD) #endif // defined(GOOGLE_CHROME_BUILD)
} // namespace } // namespace
// Convenience wrappers around CgiEscapePath().
string CgiEscapeString(const char* src) {
return CgiEscapeString(string(src));
}
string CgiEscapeString(const string& src) {
return net::EscapeUrlEncodedData(src, true);
}
// This method appends the query string to the sync server path. // This method appends the query string to the sync server path.
string MakeSyncServerPath(const string& path, const string& query_string) { string MakeSyncServerPath(const string& path, const string& query_string) {
string result = path; string result = path;
...@@ -42,10 +33,10 @@ string MakeSyncServerPath(const string& path, const string& query_string) { ...@@ -42,10 +33,10 @@ string MakeSyncServerPath(const string& path, const string& query_string) {
string MakeSyncQueryString(const string& client_id) { string MakeSyncQueryString(const string& client_id) {
string query; string query;
query += kParameterClient; query += kParameterClient;
query += "=" + CgiEscapeString(kClientName); query += "=" + net::EscapeUrlEncodedData(kClientName, true);
query += "&"; query += "&";
query += kParameterClientID; query += kParameterClientID;
query += "=" + CgiEscapeString(client_id); query += "=" + net::EscapeUrlEncodedData(client_id, true);
return query; return query;
} }
......
...@@ -12,10 +12,6 @@ namespace syncer { ...@@ -12,10 +12,6 @@ namespace syncer {
// Contains the declaration of a few helper functions used for generating sync // Contains the declaration of a few helper functions used for generating sync
// URLs. // URLs.
// Convenience wrappers around CgiEscapePath(), used by gaia_auth.
std::string CgiEscapeString(const char* src);
std::string CgiEscapeString(const std::string& src);
// This method appends the query string to the sync server path. // This method appends the query string to the sync server path.
std::string MakeSyncServerPath(const std::string& path, std::string MakeSyncServerPath(const std::string& path,
const std::string& query_string); const std::string& query_string);
......
...@@ -281,25 +281,23 @@ void ProcessDownloadedUpdates(syncable::Directory* dir, ...@@ -281,25 +281,23 @@ void ProcessDownloadedUpdates(syncable::Directory* dir,
const SyncEntityList& applicable_updates, const SyncEntityList& applicable_updates,
StatusController* status, StatusController* status,
UpdateCounters* counters) { UpdateCounters* counters) {
for (SyncEntityList::const_iterator update_it = applicable_updates.begin(); for (const auto* update : applicable_updates) {
update_it != applicable_updates.end(); ++update_it) { DCHECK_EQ(type, GetModelType(*update));
DCHECK_EQ(type, GetModelType(**update_it)); if (!UpdateContainsNewVersion(trans, *update)) {
if (!UpdateContainsNewVersion(trans, **update_it)) {
status->increment_num_reflected_updates_downloaded_by(1); status->increment_num_reflected_updates_downloaded_by(1);
counters->num_reflected_updates_received++; counters->num_reflected_updates_received++;
} }
if ((*update_it)->deleted()) { if (update->deleted()) {
status->increment_num_tombstone_updates_downloaded_by(1); status->increment_num_tombstone_updates_downloaded_by(1);
counters->num_tombstone_updates_received++; counters->num_tombstone_updates_received++;
} }
VerifyResult verify_result = VerifyUpdate(trans, **update_it, type); VerifyResult verify_result = VerifyUpdate(trans, *update, type);
if (verify_result != VERIFY_SUCCESS && verify_result != VERIFY_UNDELETE) if (verify_result != VERIFY_SUCCESS && verify_result != VERIFY_UNDELETE)
continue; continue;
ProcessUpdate(**update_it, dir->GetCryptographer(trans), trans); ProcessUpdate(*update, dir->GetCryptographer(trans), trans);
if ((*update_it)->ByteSize() > 0) { if (update->ByteSize() > 0) {
SyncRecordDatatypeBin("DataUse.Sync.Download.Bytes", SyncRecordDatatypeBin("DataUse.Sync.Download.Bytes",
ModelTypeToHistogramInt(type), ModelTypeToHistogramInt(type), update->ByteSize());
(*update_it)->ByteSize());
} }
UMA_HISTOGRAM_SPARSE_SLOWLY("DataUse.Sync.Download.Count", UMA_HISTOGRAM_SPARSE_SLOWLY("DataUse.Sync.Download.Count",
ModelTypeToHistogramInt(type)); ModelTypeToHistogramInt(type));
......
...@@ -39,7 +39,6 @@ namespace syncer { ...@@ -39,7 +39,6 @@ namespace syncer {
class BaseTransaction; class BaseTransaction;
namespace syncable { namespace syncable {
class BaseTransaction;
class Entry; class Entry;
class Id; class Id;
} }
......
...@@ -763,15 +763,10 @@ void MockConnectionManager::SetServerNotReachable() { ...@@ -763,15 +763,10 @@ void MockConnectionManager::SetServerNotReachable() {
void MockConnectionManager::UpdateConnectionStatus() { void MockConnectionManager::UpdateConnectionStatus() {
if (!server_reachable_) { if (!server_reachable_) {
server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; SetServerStatus(HttpResponse::CONNECTION_UNAVAILABLE);
} else { } else {
server_status_ = HttpResponse::SERVER_CONNECTION_OK; SetServerStatus(HttpResponse::SERVER_CONNECTION_OK);
} }
} }
void MockConnectionManager::SetServerStatus(
HttpResponse::ServerConnectionCode server_status) {
server_status_ = server_status;
}
} // namespace syncer } // namespace syncer
...@@ -255,7 +255,7 @@ class MockConnectionManager : public ServerConnectionManager { ...@@ -255,7 +255,7 @@ class MockConnectionManager : public ServerConnectionManager {
// requests. // requests.
void UpdateConnectionStatus(); void UpdateConnectionStatus();
void SetServerStatus(HttpResponse::ServerConnectionCode server_status); using ServerConnectionManager::SetServerStatus;
// Return by copy to be thread-safe. // Return by copy to be thread-safe.
const std::string store_birthday() { const std::string store_birthday() {
...@@ -272,7 +272,7 @@ class MockConnectionManager : public ServerConnectionManager { ...@@ -272,7 +272,7 @@ class MockConnectionManager : public ServerConnectionManager {
// Adds a new progress marker to the last update. // Adds a new progress marker to the last update.
sync_pb::DataTypeProgressMarker* AddUpdateProgressMarker(); sync_pb::DataTypeProgressMarker* AddUpdateProgressMarker();
void ResetAuthToken() { auth_token_.clear(); } void ResetAuthToken() { InvalidateAndClearAuthToken(); }
private: private:
sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, sync_pb::SyncEntity* AddUpdateFull(syncable::Id id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment