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

Unified Diff: sync/test/fake_server/fake_server.cc

Issue 234113002: Use FakeServer-based invalidations for Sync tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: sync/test/fake_server/fake_server.cc
diff --git a/sync/test/fake_server/fake_server.cc b/sync/test/fake_server/fake_server.cc
index 3827a85f99291a7e4c872c4f0a8fdf9d5d676dc6..b915c7f547d071d72af27b8d17e5ca26c5b4b553 100644
--- a/sync/test/fake_server/fake_server.cc
+++ b/sync/test/fake_server/fake_server.cc
@@ -4,6 +4,7 @@
#include "sync/test/fake_server/fake_server.h"
+#include <algorithm>
#include <limits>
#include <string>
#include <vector>
@@ -29,9 +30,9 @@
using std::string;
using std::vector;
-using base::AutoLock;
using syncer::GetModelType;
using syncer::ModelType;
+using syncer::ModelTypeSet;
// The default birthday value.
static const char kDefaultBirthday[] = "1234567890";
@@ -237,11 +238,11 @@ void FakeServer::SaveEntity(FakeServerEntity* entity) {
entities_[entity->GetId()] = entity;
}
-int FakeServer::HandleCommand(const string& request,
- int* response_code,
- string* response) {
- AutoLock lock(lock_);
-
+void FakeServer::HandleCommand(const string& request,
+ const base::Closure& callback,
+ int* error_code,
+ int* response_code,
+ string* response) {
sync_pb::ClientToServerMessage message;
bool parsed = message.ParseFromString(request);
DCHECK(parsed);
@@ -258,20 +259,25 @@ int FakeServer::HandleCommand(const string& request,
response_proto.mutable_commit());
break;
default:
- return net::ERR_NOT_IMPLEMENTED;
+ *error_code = net::ERR_NOT_IMPLEMENTED;
+ callback.Run();
+ return;
}
if (!success) {
// TODO(pvalenzuela): Add logging here so that tests have more info about
// the failure.
- return net::HTTP_BAD_REQUEST;
pval...(no longer on Chromium) 2014/04/24 01:08:53 this value was incorrect (it's the error code, not
+ *error_code = net::HTTP_BAD_REQUEST;
+ callback.Run();
+ return;
}
response_proto.set_error_code(sync_pb::SyncEnums::SUCCESS);
response_proto.set_store_birthday(birthday_);
*response_code = net::HTTP_OK;
*response = response_proto.SerializeAsString();
- return 0;
+ *error_code = 0;
+ callback.Run();
}
bool FakeServer::HandleGetUpdatesRequest(
@@ -327,6 +333,7 @@ bool FakeServer::CommitEntity(
const sync_pb::SyncEntity& client_entity,
sync_pb::CommitResponse_EntryResponse* entry_response,
string client_guid,
+ ModelType* model_type,
rlarocque 2014/04/22 18:22:22 This is starting to look a little awkward. Could
pval...(no longer on Chromium) 2014/04/24 01:08:53 done / looks good to me
std::map<string, string>* client_to_server_ids) {
if (client_entity.version() == 0 && client_entity.deleted()) {
return false;
@@ -384,6 +391,7 @@ bool FakeServer::CommitEntity(
SaveEntity(entity);
BuildEntryResponseForSuccessfulCommit(entry_response, entity);
+ *model_type = entity->GetModelType();
return true;
}
@@ -441,6 +449,7 @@ bool FakeServer::HandleCommitRequest(
sync_pb::CommitResponse* response) {
std::map<string, string> client_to_server_ids;
string guid = commit.cache_guid();
+ ModelTypeSet committed_model_types;
// TODO(pvalenzuela): Add validation of CommitMessage.entries.
::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it;
@@ -448,12 +457,23 @@ bool FakeServer::HandleCommitRequest(
sync_pb::CommitResponse_EntryResponse* entry_response =
response->add_entryresponse();
- if (!CommitEntity(*it, entry_response, guid, &client_to_server_ids)) {
+ ModelType model_type;
+ if (!CommitEntity(*it,
+ entry_response,
+ guid,
+ &model_type,
+ &client_to_server_ids)) {
return false;
}
+ committed_model_types.Put(model_type);
}
+ FOR_EACH_OBSERVER(Observer, observers_, OnCommit(committed_model_types));
return true;
}
+void FakeServer::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
} // namespace fake_server

Powered by Google App Engine
This is Rietveld 408576698