| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 request_counter_(0), | 154 request_counter_(0), |
| 155 network_enabled_(true) { | 155 network_enabled_(true) { |
| 156 keystore_keys_.push_back(kDefaultKeystoreKey); | 156 keystore_keys_.push_back(kDefaultKeystoreKey); |
| 157 CHECK(CreateDefaultPermanentItems()); | 157 CHECK(CreateDefaultPermanentItems()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 FakeServer::~FakeServer() { | 160 FakeServer::~FakeServer() { |
| 161 STLDeleteContainerPairSecondPointers(entities_.begin(), entities_.end()); | 161 STLDeleteContainerPairSecondPointers(entities_.begin(), entities_.end()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 bool FakeServer::CreatePermanentBookmarkFolder(const char* server_tag, |
| 165 const char* name) { |
| 166 FakeServerEntity* entity = |
| 167 PermanentEntity::Create(syncer::BOOKMARKS, server_tag, name, |
| 168 ModelTypeToRootTag(syncer::BOOKMARKS)); |
| 169 if (entity == NULL) |
| 170 return false; |
| 171 |
| 172 SaveEntity(entity); |
| 173 return true; |
| 174 } |
| 175 |
| 164 bool FakeServer::CreateDefaultPermanentItems() { | 176 bool FakeServer::CreateDefaultPermanentItems() { |
| 165 ModelTypeSet all_types = syncer::ProtocolTypes(); | 177 ModelTypeSet all_types = syncer::ProtocolTypes(); |
| 166 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) { | 178 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) { |
| 167 ModelType model_type = it.Get(); | 179 ModelType model_type = it.Get(); |
| 168 FakeServerEntity* top_level_entity = | 180 FakeServerEntity* top_level_entity = |
| 169 PermanentEntity::CreateTopLevel(model_type); | 181 PermanentEntity::CreateTopLevel(model_type); |
| 170 if (top_level_entity == NULL) { | 182 if (top_level_entity == NULL) { |
| 171 return false; | 183 return false; |
| 172 } | 184 } |
| 173 SaveEntity(top_level_entity); | 185 SaveEntity(top_level_entity); |
| 174 | 186 |
| 175 if (model_type == syncer::BOOKMARKS) { | 187 if (model_type == syncer::BOOKMARKS) { |
| 176 FakeServerEntity* bookmark_bar_entity = | 188 if (!CreatePermanentBookmarkFolder("bookmark_bar", "Bookmark Bar")) |
| 177 PermanentEntity::Create(syncer::BOOKMARKS, | |
| 178 "bookmark_bar", | |
| 179 "Bookmark Bar", | |
| 180 ModelTypeToRootTag(syncer::BOOKMARKS)); | |
| 181 if (bookmark_bar_entity == NULL) { | |
| 182 return false; | 189 return false; |
| 183 } | 190 if (!CreatePermanentBookmarkFolder("other_bookmarks", "Other Bookmarks")) |
| 184 SaveEntity(bookmark_bar_entity); | |
| 185 | |
| 186 FakeServerEntity* other_bookmarks_entity = | |
| 187 PermanentEntity::Create(syncer::BOOKMARKS, | |
| 188 "other_bookmarks", | |
| 189 "Other Bookmarks", | |
| 190 ModelTypeToRootTag(syncer::BOOKMARKS)); | |
| 191 if (other_bookmarks_entity == NULL) { | |
| 192 return false; | 191 return false; |
| 193 } | |
| 194 SaveEntity(other_bookmarks_entity); | |
| 195 } | 192 } |
| 196 } | 193 } |
| 197 | 194 |
| 198 return true; | 195 return true; |
| 199 } | 196 } |
| 200 | 197 |
| 201 bool FakeServer::CreateMobileBookmarksPermanentItem() { | 198 bool FakeServer::CreateMobileBookmarksPermanentItem() { |
| 202 // This folder is called "Synced Bookmarks" by sync and is renamed | 199 // This folder is called "Synced Bookmarks" by sync and is renamed |
| 203 // "Mobile Bookmarks" by the mobile client UIs. | 200 // "Mobile Bookmarks" by the mobile client UIs. |
| 204 FakeServerEntity* mobile_bookmarks_entity = | 201 FakeServerEntity* mobile_bookmarks_entity = |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 | 574 |
| 578 void FakeServer::EnableNetwork() { | 575 void FakeServer::EnableNetwork() { |
| 579 network_enabled_ = true; | 576 network_enabled_ = true; |
| 580 } | 577 } |
| 581 | 578 |
| 582 void FakeServer::DisableNetwork() { | 579 void FakeServer::DisableNetwork() { |
| 583 network_enabled_ = false; | 580 network_enabled_ = false; |
| 584 } | 581 } |
| 585 | 582 |
| 586 } // namespace fake_server | 583 } // namespace fake_server |
| OLD | NEW |