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/engine/mock_model_type_processor.h" | 5 #include "components/sync/test/engine/mock_model_type_processor.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/sha1.h" | 12 #include "base/sha1.h" |
13 #include "sync/engine/commit_queue.h" | 13 #include "components/sync/engine_impl/commit_queue.h" |
14 | 14 |
15 namespace syncer_v2 { | 15 namespace syncer_v2 { |
16 | 16 |
17 MockModelTypeProcessor::MockModelTypeProcessor() : is_synchronous_(true) {} | 17 MockModelTypeProcessor::MockModelTypeProcessor() : is_synchronous_(true) {} |
18 | 18 |
19 MockModelTypeProcessor::~MockModelTypeProcessor() {} | 19 MockModelTypeProcessor::~MockModelTypeProcessor() {} |
20 | 20 |
21 void MockModelTypeProcessor::ConnectSync( | 21 void MockModelTypeProcessor::ConnectSync( |
22 std::unique_ptr<CommitQueue> commit_queue) { | 22 std::unique_ptr<CommitQueue> commit_queue) { |
23 NOTREACHED(); | 23 NOTREACHED(); |
24 } | 24 } |
25 | 25 |
26 void MockModelTypeProcessor::DisconnectSync() { | 26 void MockModelTypeProcessor::DisconnectSync() { |
27 if (!disconnect_callback_.is_null()) { | 27 if (!disconnect_callback_.is_null()) { |
28 disconnect_callback_.Run(); | 28 disconnect_callback_.Run(); |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 void MockModelTypeProcessor::OnCommitCompleted( | 32 void MockModelTypeProcessor::OnCommitCompleted( |
33 const sync_pb::DataTypeState& type_state, | 33 const sync_pb::DataTypeState& type_state, |
34 const CommitResponseDataList& response_list) { | 34 const CommitResponseDataList& response_list) { |
35 base::Closure task = | 35 base::Closure task = |
36 base::Bind(&MockModelTypeProcessor::OnCommitCompletedImpl, | 36 base::Bind(&MockModelTypeProcessor::OnCommitCompletedImpl, |
37 base::Unretained(this), | 37 base::Unretained(this), type_state, response_list); |
38 type_state, | |
39 response_list); | |
40 pending_tasks_.push_back(task); | 38 pending_tasks_.push_back(task); |
41 if (is_synchronous_) | 39 if (is_synchronous_) |
42 RunQueuedTasks(); | 40 RunQueuedTasks(); |
43 } | 41 } |
44 | 42 |
45 void MockModelTypeProcessor::OnUpdateReceived( | 43 void MockModelTypeProcessor::OnUpdateReceived( |
46 const sync_pb::DataTypeState& type_state, | 44 const sync_pb::DataTypeState& type_state, |
47 const UpdateResponseDataList& response_list) { | 45 const UpdateResponseDataList& response_list) { |
48 base::Closure task = base::Bind(&MockModelTypeProcessor::OnUpdateReceivedImpl, | 46 base::Closure task = |
49 base::Unretained(this), | 47 base::Bind(&MockModelTypeProcessor::OnUpdateReceivedImpl, |
50 type_state, | 48 base::Unretained(this), type_state, response_list); |
51 response_list); | |
52 pending_tasks_.push_back(task); | 49 pending_tasks_.push_back(task); |
53 if (is_synchronous_) | 50 if (is_synchronous_) |
54 RunQueuedTasks(); | 51 RunQueuedTasks(); |
55 } | 52 } |
56 | 53 |
57 void MockModelTypeProcessor::SetSynchronousExecution(bool is_synchronous) { | 54 void MockModelTypeProcessor::SetSynchronousExecution(bool is_synchronous) { |
58 is_synchronous_ = is_synchronous; | 55 is_synchronous_ = is_synchronous; |
59 } | 56 } |
60 | 57 |
61 void MockModelTypeProcessor::RunQueuedTasks() { | 58 void MockModelTypeProcessor::RunQueuedTasks() { |
62 for (std::vector<base::Closure>::iterator it = pending_tasks_.begin(); | 59 for (std::vector<base::Closure>::iterator it = pending_tasks_.begin(); |
63 it != pending_tasks_.end(); | 60 it != pending_tasks_.end(); ++it) { |
64 ++it) { | |
65 it->Run(); | 61 it->Run(); |
66 } | 62 } |
67 pending_tasks_.clear(); | 63 pending_tasks_.clear(); |
68 } | 64 } |
69 | 65 |
70 CommitRequestData MockModelTypeProcessor::CommitRequest( | 66 CommitRequestData MockModelTypeProcessor::CommitRequest( |
71 const std::string& tag_hash, | 67 const std::string& tag_hash, |
72 const sync_pb::EntitySpecifics& specifics) { | 68 const sync_pb::EntitySpecifics& specifics) { |
73 const int64_t base_version = GetBaseVersion(tag_hash); | 69 const int64_t base_version = GetBaseVersion(tag_hash); |
74 | 70 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 DCHECK(HasServerAssignedId(tag_hash)); | 270 DCHECK(HasServerAssignedId(tag_hash)); |
275 return assigned_ids_.find(tag_hash)->second; | 271 return assigned_ids_.find(tag_hash)->second; |
276 } | 272 } |
277 | 273 |
278 void MockModelTypeProcessor::SetServerAssignedId(const std::string& tag_hash, | 274 void MockModelTypeProcessor::SetServerAssignedId(const std::string& tag_hash, |
279 const std::string& id) { | 275 const std::string& id) { |
280 assigned_ids_[tag_hash] = id; | 276 assigned_ids_[tag_hash] = id; |
281 } | 277 } |
282 | 278 |
283 } // namespace syncer_v2 | 279 } // namespace syncer_v2 |
OLD | NEW |