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

Side by Side Diff: sync/test/engine/mock_connection_manager.h

Issue 1349783006: Cleanup: Pass std::string as const reference if possible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert third_party changes Created 5 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Mock ServerConnectionManager class for use in client unit tests. 5 // Mock ServerConnectionManager class for use in client unit tests.
6 6
7 #ifndef SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ 7 #ifndef SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
8 #define SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ 8 #define SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
9 9
10 #include <bitset> 10 #include <bitset>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 const std::string& auth_token, 43 const std::string& auth_token,
44 ScopedServerStatusWatcher* watcher) override; 44 ScopedServerStatusWatcher* watcher) override;
45 45
46 // Control of commit response. 46 // Control of commit response.
47 // NOTE: Commit callback is invoked only once then reset. 47 // NOTE: Commit callback is invoked only once then reset.
48 void SetMidCommitCallback(const base::Closure& callback); 48 void SetMidCommitCallback(const base::Closure& callback);
49 void SetMidCommitObserver(MidCommitObserver* observer); 49 void SetMidCommitObserver(MidCommitObserver* observer);
50 50
51 // Set this if you want commit to perform commit time rename. Will request 51 // Set this if you want commit to perform commit time rename. Will request
52 // that the client renames all commited entries, prepending this string. 52 // that the client renames all commited entries, prepending this string.
53 void SetCommitTimeRename(std::string prepend); 53 void SetCommitTimeRename(const std::string& prepend);
54 54
55 // Generic versions of AddUpdate functions. Tests using these function should 55 // Generic versions of AddUpdate functions. Tests using these function should
56 // compile for both the int64 and string id based versions of the server. 56 // compile for both the int64 and string id based versions of the server.
57 // The SyncEntity returned is only valid until the Sync is completed 57 // The SyncEntity returned is only valid until the Sync is completed
58 // (e.g. with SyncShare.) It allows to add further entity properties before 58 // (e.g. with SyncShare.) It allows to add further entity properties before
59 // sync, using SetLastXXX() methods and/or GetMutableLastUpdate(). 59 // sync, using SetLastXXX() methods and/or GetMutableLastUpdate().
60 sync_pb::SyncEntity* AddUpdateDirectory( 60 sync_pb::SyncEntity* AddUpdateDirectory(
61 syncable::Id id, 61 syncable::Id id,
62 syncable::Id parent_id, 62 syncable::Id parent_id,
63 std::string name, 63 const std::string& name,
64 int64 version, 64 int64 version,
65 int64 sync_ts, 65 int64 sync_ts,
66 std::string originator_cache_guid, 66 const std::string& originator_cache_guid,
67 std::string originator_client_item_id); 67 const std::string& originator_client_item_id);
68 sync_pb::SyncEntity* AddUpdateBookmark(syncable::Id id, 68 sync_pb::SyncEntity* AddUpdateBookmark(
69 syncable::Id parent_id, 69 syncable::Id id,
70 std::string name, 70 syncable::Id parent_id,
71 int64 version, 71 const std::string& name,
72 int64 sync_ts, 72 int64 version,
73 std::string originator_cache_guid, 73 int64 sync_ts,
74 std::string originator_client_item_id); 74 const std::string& originator_cache_guid,
75 const std::string& originator_client_item_id);
75 // Versions of the AddUpdate functions that accept integer IDs. 76 // Versions of the AddUpdate functions that accept integer IDs.
76 sync_pb::SyncEntity* AddUpdateDirectory( 77 sync_pb::SyncEntity* AddUpdateDirectory(
77 int id, 78 int id,
78 int parent_id, 79 int parent_id,
79 std::string name, 80 const std::string& name,
80 int64 version, 81 int64 version,
81 int64 sync_ts, 82 int64 sync_ts,
82 std::string originator_cache_guid, 83 const std::string& originator_cache_guid,
83 std::string originator_client_item_id); 84 const std::string& originator_client_item_id);
84 sync_pb::SyncEntity* AddUpdateBookmark(int id, 85 sync_pb::SyncEntity* AddUpdateBookmark(
85 int parent_id, 86 int id,
86 std::string name, 87 int parent_id,
87 int64 version, 88 const std::string& name,
88 int64 sync_ts, 89 int64 version,
89 std::string originator_cache_guid, 90 int64 sync_ts,
90 std::string originator_client_item_id); 91 const std::string& originator_cache_guid,
92 const std::string& originator_client_item_id);
91 // New protocol versions of the AddUpdate functions. 93 // New protocol versions of the AddUpdate functions.
92 sync_pb::SyncEntity* AddUpdateDirectory( 94 sync_pb::SyncEntity* AddUpdateDirectory(
93 std::string id, 95 const std::string& id,
94 std::string parent_id, 96 const std::string& parent_id,
95 std::string name, 97 const std::string& name,
96 int64 version, 98 int64 version,
97 int64 sync_ts, 99 int64 sync_ts,
98 std::string originator_cache_guid, 100 const std::string& originator_cache_guid,
99 std::string originator_client_item_id); 101 const std::string& originator_client_item_id);
100 sync_pb::SyncEntity* AddUpdateBookmark(std::string id, 102 sync_pb::SyncEntity* AddUpdateBookmark(
101 std::string parent_id, 103 const std::string& id,
102 std::string name, 104 const std::string& parent_id,
103 int64 version, 105 const std::string& name,
104 int64 sync_ts, 106 int64 version,
105 std::string originator_cache_guid, 107 int64 sync_ts,
106 std::string originator_client_item_id); 108 const std::string& originator_cache_guid,
109 const std::string& originator_client_item_id);
107 // Versions of the AddUpdate function that accept specifics. 110 // Versions of the AddUpdate function that accept specifics.
108 sync_pb::SyncEntity* AddUpdateSpecifics( 111 sync_pb::SyncEntity* AddUpdateSpecifics(
109 int id, 112 int id,
110 int parent_id, 113 int parent_id,
111 std::string name, 114 const std::string& name,
112 int64 version, 115 int64 version,
113 int64 sync_ts, 116 int64 sync_ts,
114 bool is_dir, 117 bool is_dir,
115 int64 position, 118 int64 position,
116 const sync_pb::EntitySpecifics& specifics); 119 const sync_pb::EntitySpecifics& specifics);
117 sync_pb::SyncEntity* AddUpdateSpecifics( 120 sync_pb::SyncEntity* AddUpdateSpecifics(
118 int id, 121 int id,
119 int parent_id, 122 int parent_id,
120 std::string name, 123 const std::string& name,
121 int64 version, 124 int64 version,
122 int64 sync_ts, 125 int64 sync_ts,
123 bool is_dir, 126 bool is_dir,
124 int64 position, 127 int64 position,
125 const sync_pb::EntitySpecifics& specifics, 128 const sync_pb::EntitySpecifics& specifics,
126 std::string originator_cache_guid, 129 const std::string& originator_cache_guid,
127 std::string originator_client_item_id); 130 const std::string& originator_client_item_id);
128 sync_pb::SyncEntity* SetNigori( 131 sync_pb::SyncEntity* SetNigori(
129 int id, 132 int id,
130 int64 version, 133 int64 version,
131 int64 sync_ts, 134 int64 sync_ts,
132 const sync_pb::EntitySpecifics& specifics); 135 const sync_pb::EntitySpecifics& specifics);
133 // Unique client tag variant for adding items. 136 // Unique client tag variant for adding items.
134 sync_pb::SyncEntity* AddUpdatePref(std::string id, 137 sync_pb::SyncEntity* AddUpdatePref(const std::string& id,
135 std::string parent_id, 138 const std::string& parent_id,
136 std::string client_tag, 139 const std::string& client_tag,
137 int64 version, 140 int64 version,
138 int64 sync_ts); 141 int64 sync_ts);
139 142
140 // Find the last commit sent by the client, and replay it for the next get 143 // Find the last commit sent by the client, and replay it for the next get
141 // updates command. This can be used to simulate the GetUpdates that happens 144 // updates command. This can be used to simulate the GetUpdates that happens
142 // immediately after a successful commit. 145 // immediately after a successful commit.
143 sync_pb::SyncEntity* AddUpdateFromLastCommit(); 146 sync_pb::SyncEntity* AddUpdateFromLastCommit();
144 147
145 // Add a deleted item. Deletion records typically contain no 148 // Add a deleted item. Deletion records typically contain no
146 // additional information beyond the deletion, and no specifics. 149 // additional information beyond the deletion, and no specifics.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 next_new_id_ = value; 208 next_new_id_ = value;
206 } 209 }
207 void set_conflict_n_commits(int value) { 210 void set_conflict_n_commits(int value) {
208 conflict_n_commits_ = value; 211 conflict_n_commits_ = value;
209 } 212 }
210 213
211 void set_use_legacy_bookmarks_protocol(bool value) { 214 void set_use_legacy_bookmarks_protocol(bool value) {
212 use_legacy_bookmarks_protocol_ = value; 215 use_legacy_bookmarks_protocol_ = value;
213 } 216 }
214 217
215 void set_store_birthday(std::string new_birthday) { 218 void set_store_birthday(const std::string& new_birthday) {
216 // Multiple threads can set store_birthday_ in our tests, need to lock it to 219 // Multiple threads can set store_birthday_ in our tests, need to lock it to
217 // ensure atomic read/writes and avoid race conditions. 220 // ensure atomic read/writes and avoid race conditions.
218 base::AutoLock lock(store_birthday_lock_); 221 base::AutoLock lock(store_birthday_lock_);
219 store_birthday_ = new_birthday; 222 store_birthday_ = new_birthday;
220 } 223 }
221 224
222 void set_partial_throttling(bool value) { partialThrottling_ = value; } 225 void set_partial_throttling(bool value) { partialThrottling_ = value; }
223 226
224 // Retrieve the number of GetUpdates requests that the mock server has 227 // Retrieve the number of GetUpdates requests that the mock server has
225 // seen since the last time this function was called. Can be used to 228 // seen since the last time this function was called. Can be used to
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 263
261 // Explicitly indicate that we will not be fetching some updates. 264 // Explicitly indicate that we will not be fetching some updates.
262 void ClearUpdatesQueue() { 265 void ClearUpdatesQueue() {
263 update_queue_.clear(); 266 update_queue_.clear();
264 } 267 }
265 268
266 // Locate the most recent update message for purpose of alteration. 269 // Locate the most recent update message for purpose of alteration.
267 sync_pb::SyncEntity* GetMutableLastUpdate(); 270 sync_pb::SyncEntity* GetMutableLastUpdate();
268 271
269 private: 272 private:
270 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, syncable::Id parentid, 273 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id,
271 std::string name, int64 version, 274 syncable::Id parentid,
275 const std::string& name,
276 int64 version,
272 int64 sync_ts, 277 int64 sync_ts,
273 bool is_dir); 278 bool is_dir);
274 sync_pb::SyncEntity* AddUpdateFull(std::string id, 279 sync_pb::SyncEntity* AddUpdateFull(const std::string& id,
275 std::string parentid, std::string name, 280 const std::string& parentid,
276 int64 version, int64 sync_ts, 281 const std::string& name,
282 int64 version,
283 int64 sync_ts,
277 bool is_dir); 284 bool is_dir);
278 sync_pb::SyncEntity* AddUpdateMeta(std::string id, std::string parentid, 285 sync_pb::SyncEntity* AddUpdateMeta(const std::string& id,
279 std::string name, int64 version, 286 const std::string& parentid,
280 int64 sync_ts); 287 const std::string& name,
288 int64 version,
289 int64 sync_ts);
281 290
282 // Functions to handle the various types of server request. 291 // Functions to handle the various types of server request.
283 void ProcessGetUpdates(sync_pb::ClientToServerMessage* csm, 292 void ProcessGetUpdates(sync_pb::ClientToServerMessage* csm,
284 sync_pb::ClientToServerResponse* response); 293 sync_pb::ClientToServerResponse* response);
285 void ProcessCommit(sync_pb::ClientToServerMessage* csm, 294 void ProcessCommit(sync_pb::ClientToServerMessage* csm,
286 sync_pb::ClientToServerResponse* response_buffer); 295 sync_pb::ClientToServerResponse* response_buffer);
287 void ProcessClearServerData(sync_pb::ClientToServerMessage* csm, 296 void ProcessClearServerData(sync_pb::ClientToServerMessage* csm,
288 sync_pb::ClientToServerResponse* response); 297 sync_pb::ClientToServerResponse* response);
289 void AddDefaultBookmarkData(sync_pb::SyncEntity* entity, bool is_folder); 298 void AddDefaultBookmarkData(sync_pb::SyncEntity* entity, bool is_folder);
290 299
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 std::string next_token_; 417 std::string next_token_;
409 418
410 std::vector<sync_pb::ClientToServerMessage> requests_; 419 std::vector<sync_pb::ClientToServerMessage> requests_;
411 420
412 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); 421 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager);
413 }; 422 };
414 423
415 } // namespace syncer 424 } // namespace syncer
416 425
417 #endif // SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ 426 #endif // SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698