| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "sync/test/fake_server/fake_server.h" | 5 #include "sync/test/fake_server/fake_server.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 220 |
| 221 sync_pb::ClientToServerResponse response_proto; | 221 sync_pb::ClientToServerResponse response_proto; |
| 222 bool success; | 222 bool success; |
| 223 switch (message.message_contents()) { | 223 switch (message.message_contents()) { |
| 224 case sync_pb::ClientToServerMessage::GET_UPDATES: | 224 case sync_pb::ClientToServerMessage::GET_UPDATES: |
| 225 success = HandleGetUpdatesRequest(message.get_updates(), | 225 success = HandleGetUpdatesRequest(message.get_updates(), |
| 226 response_proto.mutable_get_updates()); | 226 response_proto.mutable_get_updates()); |
| 227 break; | 227 break; |
| 228 case sync_pb::ClientToServerMessage::COMMIT: | 228 case sync_pb::ClientToServerMessage::COMMIT: |
| 229 success = HandleCommitRequest(message.commit(), | 229 success = HandleCommitRequest(message.commit(), |
| 230 message.invalidator_client_id(), |
| 230 response_proto.mutable_commit()); | 231 response_proto.mutable_commit()); |
| 231 break; | 232 break; |
| 232 default: | 233 default: |
| 233 callback.Run(net::ERR_NOT_IMPLEMENTED, 0, string());; | 234 callback.Run(net::ERR_NOT_IMPLEMENTED, 0, string());; |
| 234 return; | 235 return; |
| 235 } | 236 } |
| 236 | 237 |
| 237 if (!success) { | 238 if (!success) { |
| 238 // TODO(pvalenzuela): Add logging here so that tests have more info about | 239 // TODO(pvalenzuela): Add logging here so that tests have more info about |
| 239 // the failure. | 240 // the failure. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 return false; | 390 return false; |
| 390 } | 391 } |
| 391 SaveEntity(tombstone); | 392 SaveEntity(tombstone); |
| 392 } | 393 } |
| 393 | 394 |
| 394 return true; | 395 return true; |
| 395 } | 396 } |
| 396 | 397 |
| 397 bool FakeServer::HandleCommitRequest( | 398 bool FakeServer::HandleCommitRequest( |
| 398 const sync_pb::CommitMessage& commit, | 399 const sync_pb::CommitMessage& commit, |
| 400 const std::string& invalidator_client_id, |
| 399 sync_pb::CommitResponse* response) { | 401 sync_pb::CommitResponse* response) { |
| 400 std::map<string, string> client_to_server_ids; | 402 std::map<string, string> client_to_server_ids; |
| 401 string guid = commit.cache_guid(); | 403 string guid = commit.cache_guid(); |
| 402 ModelTypeSet committed_model_types; | 404 ModelTypeSet committed_model_types; |
| 403 | 405 |
| 404 // TODO(pvalenzuela): Add validation of CommitMessage.entries. | 406 // TODO(pvalenzuela): Add validation of CommitMessage.entries. |
| 405 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it; | 407 ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it; |
| 406 for (it = commit.entries().begin(); it != commit.entries().end(); ++it) { | 408 for (it = commit.entries().begin(); it != commit.entries().end(); ++it) { |
| 407 sync_pb::CommitResponse_EntryResponse* entry_response = | 409 sync_pb::CommitResponse_EntryResponse* entry_response = |
| 408 response->add_entryresponse(); | 410 response->add_entryresponse(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 423 } | 425 } |
| 424 | 426 |
| 425 // Record the ID if it was renamed. | 427 // Record the ID if it was renamed. |
| 426 if (entity_id != client_entity.id_string()) { | 428 if (entity_id != client_entity.id_string()) { |
| 427 client_to_server_ids[client_entity.id_string()] = entity_id; | 429 client_to_server_ids[client_entity.id_string()] = entity_id; |
| 428 } | 430 } |
| 429 FakeServerEntity* entity = entities_[entity_id]; | 431 FakeServerEntity* entity = entities_[entity_id]; |
| 430 committed_model_types.Put(entity->GetModelType()); | 432 committed_model_types.Put(entity->GetModelType()); |
| 431 } | 433 } |
| 432 | 434 |
| 433 FOR_EACH_OBSERVER(Observer, observers_, OnCommit(committed_model_types)); | 435 FOR_EACH_OBSERVER(Observer, observers_, |
| 436 OnCommit(invalidator_client_id, committed_model_types)); |
| 434 return true; | 437 return true; |
| 435 } | 438 } |
| 436 | 439 |
| 437 scoped_ptr<base::DictionaryValue> FakeServer::GetEntitiesAsDictionaryValue() { | 440 scoped_ptr<base::DictionaryValue> FakeServer::GetEntitiesAsDictionaryValue() { |
| 438 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); | 441 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); |
| 439 | 442 |
| 440 // Initialize an empty ListValue for all ModelTypes. | 443 // Initialize an empty ListValue for all ModelTypes. |
| 441 ModelTypeSet all_types = ModelTypeSet::All(); | 444 ModelTypeSet all_types = ModelTypeSet::All(); |
| 442 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) { | 445 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) { |
| 443 dictionary->Set(ModelTypeToString(it.Get()), new base::ListValue()); | 446 dictionary->Set(ModelTypeToString(it.Get()), new base::ListValue()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 472 | 475 |
| 473 void FakeServer::AddObserver(Observer* observer) { | 476 void FakeServer::AddObserver(Observer* observer) { |
| 474 observers_.AddObserver(observer); | 477 observers_.AddObserver(observer); |
| 475 } | 478 } |
| 476 | 479 |
| 477 void FakeServer::RemoveObserver(Observer* observer) { | 480 void FakeServer::RemoveObserver(Observer* observer) { |
| 478 observers_.RemoveObserver(observer); | 481 observers_.RemoveObserver(observer); |
| 479 } | 482 } |
| 480 | 483 |
| 481 } // namespace fake_server | 484 } // namespace fake_server |
| OLD | NEW |