| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 if (version < min_version) | 138 if (version < min_version) |
| 139 min_version = version; | 139 min_version = version; |
| 140 } | 140 } |
| 141 | 141 |
| 142 return scoped_ptr<UpdateSieve>( | 142 return scoped_ptr<UpdateSieve>( |
| 143 new UpdateSieve(request_from_version, min_version)); | 143 new UpdateSieve(request_from_version, min_version)); |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace | 146 } // namespace |
| 147 | 147 |
| 148 FakeServer::FakeServer() : version_(0), store_birthday_(kDefaultStoreBirthday) { | 148 FakeServer::FakeServer() : version_(0), |
| 149 store_birthday_(kDefaultStoreBirthday), |
| 150 error_type_(sync_pb::SyncEnums::SUCCESS) { |
| 149 keystore_keys_.push_back(kDefaultKeystoreKey); | 151 keystore_keys_.push_back(kDefaultKeystoreKey); |
| 150 CHECK(CreateDefaultPermanentItems()); | 152 CHECK(CreateDefaultPermanentItems()); |
| 151 } | 153 } |
| 152 | 154 |
| 153 FakeServer::~FakeServer() { | 155 FakeServer::~FakeServer() { |
| 154 STLDeleteContainerPairSecondPointers(entities_.begin(), entities_.end()); | 156 STLDeleteContainerPairSecondPointers(entities_.begin(), entities_.end()); |
| 155 } | 157 } |
| 156 | 158 |
| 157 bool FakeServer::CreateDefaultPermanentItems() { | 159 bool FakeServer::CreateDefaultPermanentItems() { |
| 158 ModelTypeSet all_types = syncer::ProtocolTypes(); | 160 ModelTypeSet all_types = syncer::ProtocolTypes(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 sync_pb::ClientToServerMessage message; | 219 sync_pb::ClientToServerMessage message; |
| 218 bool parsed = message.ParseFromString(request); | 220 bool parsed = message.ParseFromString(request); |
| 219 DCHECK(parsed); | 221 DCHECK(parsed); |
| 220 | 222 |
| 221 sync_pb::SyncEnums_ErrorType error_code; | 223 sync_pb::SyncEnums_ErrorType error_code; |
| 222 sync_pb::ClientToServerResponse response_proto; | 224 sync_pb::ClientToServerResponse response_proto; |
| 223 | 225 |
| 224 if (message.has_store_birthday() && | 226 if (message.has_store_birthday() && |
| 225 message.store_birthday() != store_birthday_) { | 227 message.store_birthday() != store_birthday_) { |
| 226 error_code = sync_pb::SyncEnums::NOT_MY_BIRTHDAY; | 228 error_code = sync_pb::SyncEnums::NOT_MY_BIRTHDAY; |
| 229 } else if (error_type_ != sync_pb::SyncEnums::SUCCESS) { |
| 230 error_code = error_type_; |
| 227 } else { | 231 } else { |
| 228 bool success = false; | 232 bool success = false; |
| 229 switch (message.message_contents()) { | 233 switch (message.message_contents()) { |
| 230 case sync_pb::ClientToServerMessage::GET_UPDATES: | 234 case sync_pb::ClientToServerMessage::GET_UPDATES: |
| 231 success = HandleGetUpdatesRequest(message.get_updates(), | 235 success = HandleGetUpdatesRequest(message.get_updates(), |
| 232 response_proto.mutable_get_updates()); | 236 response_proto.mutable_get_updates()); |
| 233 break; | 237 break; |
| 234 case sync_pb::ClientToServerMessage::COMMIT: | 238 case sync_pb::ClientToServerMessage::COMMIT: |
| 235 success = HandleCommitRequest(message.commit(), | 239 success = HandleCommitRequest(message.commit(), |
| 236 message.invalidator_client_id(), | 240 message.invalidator_client_id(), |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 } | 487 } |
| 484 | 488 |
| 485 bool FakeServer::SetNewStoreBirthday(const string& store_birthday) { | 489 bool FakeServer::SetNewStoreBirthday(const string& store_birthday) { |
| 486 if (store_birthday_ == store_birthday) | 490 if (store_birthday_ == store_birthday) |
| 487 return false; | 491 return false; |
| 488 | 492 |
| 489 store_birthday_ = store_birthday; | 493 store_birthday_ = store_birthday; |
| 490 return true; | 494 return true; |
| 491 } | 495 } |
| 492 | 496 |
| 497 // TODO(pvalenzuela): comments from Richard: we should look at |
| 498 // mock_connection_manager.cc and take it as a warning. This style of injecting |
| 499 // errors works when there's one or two conditions we care about, but it can |
| 500 // eventually lead to a hairball once we have many different conditions and |
| 501 // triggering logic. |
| 502 void FakeServer::TriggerError(const sync_pb::SyncEnums::ErrorType& error_type) { |
| 503 error_type_ = error_type; |
| 504 } |
| 505 |
| 493 void FakeServer::AddObserver(Observer* observer) { | 506 void FakeServer::AddObserver(Observer* observer) { |
| 494 observers_.AddObserver(observer); | 507 observers_.AddObserver(observer); |
| 495 } | 508 } |
| 496 | 509 |
| 497 void FakeServer::RemoveObserver(Observer* observer) { | 510 void FakeServer::RemoveObserver(Observer* observer) { |
| 498 observers_.RemoveObserver(observer); | 511 observers_.RemoveObserver(observer); |
| 499 } | 512 } |
| 500 | 513 |
| 501 } // namespace fake_server | 514 } // namespace fake_server |
| OLD | NEW |