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

Side by Side Diff: sync/test/fake_server/fake_server.h

Issue 1866243002: Convert //sync from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
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 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ 5 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_
6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ 6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory>
11 #include <string> 12 #include <string>
12 #include <vector> 13 #include <vector>
13 14
14 #include "base/callback.h" 15 #include "base/callback.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "base/threading/thread_checker.h" 17 #include "base/threading/thread_checker.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "sync/internal_api/public/base/model_type.h" 19 #include "sync/internal_api/public/base/model_type.h"
20 #include "sync/protocol/sync.pb.h" 20 #include "sync/protocol/sync.pb.h"
21 #include "sync/test/fake_server/fake_server_entity.h" 21 #include "sync/test/fake_server/fake_server_entity.h"
22 22
23 namespace fake_server { 23 namespace fake_server {
24 24
25 // A fake version of the Sync server used for testing. This class is not thread 25 // A fake version of the Sync server used for testing. This class is not thread
(...skipping 28 matching lines...) Expand all
54 // Helpers for fetching the last Commit or GetUpdates messages, respectively. 54 // Helpers for fetching the last Commit or GetUpdates messages, respectively.
55 // Returns true if the specified message existed, and false if no message has 55 // Returns true if the specified message existed, and false if no message has
56 // been received. 56 // been received.
57 bool GetLastCommitMessage(sync_pb::ClientToServerMessage* message); 57 bool GetLastCommitMessage(sync_pb::ClientToServerMessage* message);
58 bool GetLastGetUpdatesMessage(sync_pb::ClientToServerMessage* message); 58 bool GetLastGetUpdatesMessage(sync_pb::ClientToServerMessage* message);
59 59
60 // Creates a DicionaryValue representation of all entities present in the 60 // Creates a DicionaryValue representation of all entities present in the
61 // server. The dictionary keys are the strings generated by ModelTypeToString 61 // server. The dictionary keys are the strings generated by ModelTypeToString
62 // and the values are ListValues containing StringValue versions of entity 62 // and the values are ListValues containing StringValue versions of entity
63 // names. 63 // names.
64 scoped_ptr<base::DictionaryValue> GetEntitiesAsDictionaryValue(); 64 std::unique_ptr<base::DictionaryValue> GetEntitiesAsDictionaryValue();
65 65
66 // Returns all entities stored by the server of the given |model_type|. 66 // Returns all entities stored by the server of the given |model_type|.
67 // This method returns SyncEntity protocol buffer objects (instead of 67 // This method returns SyncEntity protocol buffer objects (instead of
68 // FakeServerEntity) so that callers can inspect datatype-specific data 68 // FakeServerEntity) so that callers can inspect datatype-specific data
69 // (e.g., the URL of a session tab). 69 // (e.g., the URL of a session tab).
70 std::vector<sync_pb::SyncEntity> GetSyncEntitiesByModelType( 70 std::vector<sync_pb::SyncEntity> GetSyncEntitiesByModelType(
71 syncer::ModelType model_type); 71 syncer::ModelType model_type);
72 72
73 // Adds |entity| to the server's collection of entities. This method makes no 73 // Adds |entity| to the server's collection of entities. This method makes no
74 // guarantees that the added entity will result in successful server 74 // guarantees that the added entity will result in successful server
75 // operations. 75 // operations.
76 void InjectEntity(scoped_ptr<FakeServerEntity> entity); 76 void InjectEntity(std::unique_ptr<FakeServerEntity> entity);
77 77
78 // Modifies the entity on the server with the given |id|. The entity's 78 // Modifies the entity on the server with the given |id|. The entity's
79 // EntitySpecifics are replaced with |updated_specifics| and its version is 79 // EntitySpecifics are replaced with |updated_specifics| and its version is
80 // updated. If the given |id| does not exist or the ModelType of 80 // updated. If the given |id| does not exist or the ModelType of
81 // |updated_specifics| does not match the entity, false is returned. 81 // |updated_specifics| does not match the entity, false is returned.
82 // Otherwise, true is returned to represent a successful modification. 82 // Otherwise, true is returned to represent a successful modification.
83 // 83 //
84 // This method sometimes updates entity data beyond EntitySpecifics. For 84 // This method sometimes updates entity data beyond EntitySpecifics. For
85 // example, in the case of a bookmark, changing the BookmarkSpecifics title 85 // example, in the case of a bookmark, changing the BookmarkSpecifics title
86 // field will modify the top-level entity's name field. 86 // field will modify the top-level entity's name field.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // This can be used to trigger exponential backoff in the client. 142 // This can be used to trigger exponential backoff in the client.
143 void DisableNetwork(); 143 void DisableNetwork();
144 144
145 // Returns the entity ID of the Bookmark Bar folder. 145 // Returns the entity ID of the Bookmark Bar folder.
146 std::string GetBookmarkBarFolderId() const; 146 std::string GetBookmarkBarFolderId() const;
147 147
148 // Returns the current FakeServer as a WeakPtr. 148 // Returns the current FakeServer as a WeakPtr.
149 base::WeakPtr<FakeServer> AsWeakPtr(); 149 base::WeakPtr<FakeServer> AsWeakPtr();
150 150
151 private: 151 private:
152 using EntityMap = std::map<std::string, scoped_ptr<FakeServerEntity>>; 152 using EntityMap = std::map<std::string, std::unique_ptr<FakeServerEntity>>;
153 153
154 // Gets FakeServer ready for syncing. 154 // Gets FakeServer ready for syncing.
155 void Init(); 155 void Init();
156 156
157 // Processes a GetUpdates call. 157 // Processes a GetUpdates call.
158 bool HandleGetUpdatesRequest(const sync_pb::GetUpdatesMessage& get_updates, 158 bool HandleGetUpdatesRequest(const sync_pb::GetUpdatesMessage& get_updates,
159 sync_pb::GetUpdatesResponse* response); 159 sync_pb::GetUpdatesResponse* response);
160 160
161 // Processes a Commit call. 161 // Processes a Commit call.
162 bool HandleCommitRequest(const sync_pb::CommitMessage& message, 162 bool HandleCommitRequest(const sync_pb::CommitMessage& message,
163 const std::string& invalidator_client_id, 163 const std::string& invalidator_client_id,
164 sync_pb::CommitResponse* response); 164 sync_pb::CommitResponse* response);
165 165
166 // Creates and saves a permanent folder for Bookmarks (e.g., Bookmark Bar). 166 // Creates and saves a permanent folder for Bookmarks (e.g., Bookmark Bar).
167 bool CreatePermanentBookmarkFolder(const std::string& server_tag, 167 bool CreatePermanentBookmarkFolder(const std::string& server_tag,
168 const std::string& name); 168 const std::string& name);
169 169
170 // Inserts the default permanent items in |entities_|. 170 // Inserts the default permanent items in |entities_|.
171 bool CreateDefaultPermanentItems(); 171 bool CreateDefaultPermanentItems();
172 172
173 // Saves a |entity| to |entities_|. 173 // Saves a |entity| to |entities_|.
174 void SaveEntity(scoped_ptr<FakeServerEntity> entity); 174 void SaveEntity(std::unique_ptr<FakeServerEntity> entity);
175 175
176 // Commits a client-side SyncEntity to the server as a FakeServerEntity. 176 // Commits a client-side SyncEntity to the server as a FakeServerEntity.
177 // The client that sent the commit is identified via |client_guid|. The 177 // The client that sent the commit is identified via |client_guid|. The
178 // parent ID string present in |client_entity| should be ignored in favor 178 // parent ID string present in |client_entity| should be ignored in favor
179 // of |parent_id|. If the commit is successful, the entity's server ID string 179 // of |parent_id|. If the commit is successful, the entity's server ID string
180 // is returned and a new FakeServerEntity is saved in |entities_|. 180 // is returned and a new FakeServerEntity is saved in |entities_|.
181 std::string CommitEntity( 181 std::string CommitEntity(
182 const sync_pb::SyncEntity& client_entity, 182 const sync_pb::SyncEntity& client_entity,
183 sync_pb::CommitResponse_EntryResponse* entry_response, 183 sync_pb::CommitResponse_EntryResponse* entry_response,
184 const std::string& client_guid, 184 const std::string& client_guid,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 226
227 // All Keystore keys known to the server. 227 // All Keystore keys known to the server.
228 std::vector<std::string> keystore_keys_; 228 std::vector<std::string> keystore_keys_;
229 229
230 // Used as the error_code field of ClientToServerResponse on all responses 230 // Used as the error_code field of ClientToServerResponse on all responses
231 // except when |triggered_actionable_error_| is set. 231 // except when |triggered_actionable_error_| is set.
232 sync_pb::SyncEnums::ErrorType error_type_; 232 sync_pb::SyncEnums::ErrorType error_type_;
233 233
234 // Used as the error field of ClientToServerResponse when its pointer is not 234 // Used as the error field of ClientToServerResponse when its pointer is not
235 // NULL. 235 // NULL.
236 scoped_ptr<sync_pb::ClientToServerResponse_Error> triggered_actionable_error_; 236 std::unique_ptr<sync_pb::ClientToServerResponse_Error>
237 triggered_actionable_error_;
237 238
238 // These values are used in tandem to return a triggered error (either 239 // These values are used in tandem to return a triggered error (either
239 // |error_type_| or |triggered_actionable_error_|) on every other request. 240 // |error_type_| or |triggered_actionable_error_|) on every other request.
240 // |alternate_triggered_errors_| is set if this feature is enabled and 241 // |alternate_triggered_errors_| is set if this feature is enabled and
241 // |request_counter_| is used to send triggered errors on odd-numbered 242 // |request_counter_| is used to send triggered errors on odd-numbered
242 // requests. Note that |request_counter_| can be reset and is not necessarily 243 // requests. Note that |request_counter_| can be reset and is not necessarily
243 // indicative of the total number of requests handled during the object's 244 // indicative of the total number of requests handled during the object's
244 // lifetime. 245 // lifetime.
245 bool alternate_triggered_errors_; 246 bool alternate_triggered_errors_;
246 int request_counter_; 247 int request_counter_;
(...skipping 13 matching lines...) Expand all
260 base::ThreadChecker thread_checker_; 261 base::ThreadChecker thread_checker_;
261 262
262 // Creates WeakPtr versions of the current FakeServer. This must be the last 263 // Creates WeakPtr versions of the current FakeServer. This must be the last
263 // data member! 264 // data member!
264 base::WeakPtrFactory<FakeServer> weak_ptr_factory_; 265 base::WeakPtrFactory<FakeServer> weak_ptr_factory_;
265 }; 266 };
266 267
267 } // namespace fake_server 268 } // namespace fake_server
268 269
269 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ 270 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698