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

Side by Side Diff: components/sync/test/engine/mock_connection_manager.cc

Issue 2475043002: [Sync] Sync client should to exponential backoff when receive partial failure (Closed)
Patch Set: rebase Created 4 years, 1 month 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
« no previous file with comments | « components/sync/test/engine/mock_connection_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "components/sync/test/engine/mock_connection_manager.h" 5 #include "components/sync/test/engine/mock_connection_manager.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 27 matching lines...) Expand all
38 conflict_all_commits_(false), 38 conflict_all_commits_(false),
39 conflict_n_commits_(0), 39 conflict_n_commits_(0),
40 next_new_id_(10000), 40 next_new_id_(10000),
41 store_birthday_("Store BDay!"), 41 store_birthday_("Store BDay!"),
42 store_birthday_sent_(false), 42 store_birthday_sent_(false),
43 client_stuck_(false), 43 client_stuck_(false),
44 countdown_to_postbuffer_fail_(0), 44 countdown_to_postbuffer_fail_(0),
45 directory_(directory), 45 directory_(directory),
46 mid_commit_observer_(nullptr), 46 mid_commit_observer_(nullptr),
47 throttling_(false), 47 throttling_(false),
48 partialThrottling_(false), 48 partial_failure_(false),
49 fail_non_periodic_get_updates_(false), 49 fail_non_periodic_get_updates_(false),
50 next_position_in_parent_(2), 50 next_position_in_parent_(2),
51 use_legacy_bookmarks_protocol_(false), 51 use_legacy_bookmarks_protocol_(false),
52 num_get_updates_requests_(0) { 52 num_get_updates_requests_(0) {
53 SetNewTimestamp(0); 53 SetNewTimestamp(0);
54 SetAuthToken(kValidAuthToken); 54 SetAuthToken(kValidAuthToken);
55 } 55 }
56 56
57 MockConnectionManager::~MockConnectionManager() { 57 MockConnectionManager::~MockConnectionManager() {
58 EXPECT_TRUE(update_queue_.empty()) << "Unfetched updates."; 58 EXPECT_TRUE(update_queue_.empty()) << "Unfetched updates.";
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 ClientToServerMessage::CLEAR_SERVER_DATA) { 145 ClientToServerMessage::CLEAR_SERVER_DATA) {
146 ProcessClearServerData(&post, &response); 146 ProcessClearServerData(&post, &response);
147 } else { 147 } else {
148 EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage"; 148 EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage";
149 return false; 149 return false;
150 } 150 }
151 151
152 { 152 {
153 base::AutoLock lock(response_code_override_lock_); 153 base::AutoLock lock(response_code_override_lock_);
154 if (throttling_) { 154 if (throttling_) {
155 response.set_error_code(SyncEnums::THROTTLED);
156 throttling_ = false;
157 }
158
159 if (partialThrottling_) {
160 sync_pb::ClientToServerResponse_Error* response_error = 155 sync_pb::ClientToServerResponse_Error* response_error =
161 response.mutable_error(); 156 response.mutable_error();
162 response_error->set_error_type(SyncEnums::PARTIAL_FAILURE); 157 response_error->set_error_type(SyncEnums::THROTTLED);
163 for (ModelTypeSet::Iterator it = throttled_type_.First(); it.Good(); 158 for (ModelTypeSet::Iterator it = partial_failure_type_.First(); it.Good();
164 it.Inc()) { 159 it.Inc()) {
165 response_error->add_error_data_type_ids( 160 response_error->add_error_data_type_ids(
166 GetSpecificsFieldNumberFromModelType(it.Get())); 161 GetSpecificsFieldNumberFromModelType(it.Get()));
167 } 162 }
168 partialThrottling_ = false; 163 throttling_ = false;
164 }
165
166 if (partial_failure_) {
167 sync_pb::ClientToServerResponse_Error* response_error =
168 response.mutable_error();
169 response_error->set_error_type(SyncEnums::PARTIAL_FAILURE);
170 for (ModelTypeSet::Iterator it = partial_failure_type_.First(); it.Good();
171 it.Inc()) {
172 response_error->add_error_data_type_ids(
173 GetSpecificsFieldNumberFromModelType(it.Get()));
174 }
175 partial_failure_ = false;
169 } 176 }
170 } 177 }
171 178
172 response.SerializeToString(&params->buffer_out); 179 response.SerializeToString(&params->buffer_out);
173 if (post.message_contents() == ClientToServerMessage::COMMIT && 180 if (post.message_contents() == ClientToServerMessage::COMMIT &&
174 !mid_commit_callback_.is_null()) { 181 !mid_commit_callback_.is_null()) {
175 mid_commit_callback_.Run(); 182 mid_commit_callback_.Run();
176 mid_commit_callback_.Reset(); 183 mid_commit_callback_.Reset();
177 } 184 }
178 if (mid_commit_observer_) { 185 if (mid_commit_observer_) {
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 server_status_ = HttpResponse::SERVER_CONNECTION_OK; 762 server_status_ = HttpResponse::SERVER_CONNECTION_OK;
756 } 763 }
757 } 764 }
758 765
759 void MockConnectionManager::SetServerStatus( 766 void MockConnectionManager::SetServerStatus(
760 HttpResponse::ServerConnectionCode server_status) { 767 HttpResponse::ServerConnectionCode server_status) {
761 server_status_ = server_status; 768 server_status_ = server_status;
762 } 769 }
763 770
764 } // namespace syncer 771 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/test/engine/mock_connection_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698