OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/syncer_proto_util.h" | 5 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 9 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
10 #include "chrome/browser/sync/engine/syncer.h" | 10 #include "chrome/browser/sync/engine/syncer.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 if (response.has_client_command()) { | 180 if (response.has_client_command()) { |
181 const sync_pb::ClientCommand& command = response.client_command(); | 181 const sync_pb::ClientCommand& command = response.client_command(); |
182 if (command.has_throttle_delay_seconds()) { | 182 if (command.has_throttle_delay_seconds()) { |
183 throttle_delay = | 183 throttle_delay = |
184 base::TimeDelta::FromSeconds(command.throttle_delay_seconds()); | 184 base::TimeDelta::FromSeconds(command.throttle_delay_seconds()); |
185 } | 185 } |
186 } | 186 } |
187 return throttle_delay; | 187 return throttle_delay; |
188 } | 188 } |
189 | 189 |
190 void SyncerProtoUtil::HandleThrottling( | |
191 const SyncProtocolError& error, | |
192 const base::TimeTicks& throttled_until, | |
193 sessions::SyncSessionContext* context, | |
194 sessions::SyncSession::Delegate* delegate) { | |
195 DCHECK(error.error_type == browser_sync::THROTTLED); | |
akalin
2011/11/21 20:04:26
DCHECK_EQ
lipalani1
2011/11/21 21:55:38
Done.
| |
196 if (error.throttled_types.size() > 0) { | |
197 context->AddUnthrottleTime(error.throttled_types, throttled_until); | |
198 } else { | |
199 delegate->OnSilencedUntil(throttled_until); | |
200 } | |
201 } | |
202 | |
190 namespace { | 203 namespace { |
191 | 204 |
192 // Helper function for an assertion in PostClientToServerMessage. | 205 // Helper function for an assertion in PostClientToServerMessage. |
193 bool IsVeryFirstGetUpdates(const ClientToServerMessage& message) { | 206 bool IsVeryFirstGetUpdates(const ClientToServerMessage& message) { |
194 if (!message.has_get_updates()) | 207 if (!message.has_get_updates()) |
195 return false; | 208 return false; |
196 DCHECK_LT(0, message.get_updates().from_progress_marker_size()); | 209 DCHECK_LT(0, message.get_updates().from_progress_marker_size()); |
197 for (int i = 0; i < message.get_updates().from_progress_marker_size(); ++i) { | 210 for (int i = 0; i < message.get_updates().from_progress_marker_size(); ++i) { |
198 if (!message.get_updates().from_progress_marker(i).token().empty()) | 211 if (!message.get_updates().from_progress_marker(i).token().empty()) |
199 return false; | 212 return false; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 | 264 |
252 browser_sync::SyncProtocolError ConvertErrorPBToLocalType( | 265 browser_sync::SyncProtocolError ConvertErrorPBToLocalType( |
253 const sync_pb::ClientToServerResponse::Error& error) { | 266 const sync_pb::ClientToServerResponse::Error& error) { |
254 browser_sync::SyncProtocolError sync_protocol_error; | 267 browser_sync::SyncProtocolError sync_protocol_error; |
255 sync_protocol_error.error_type = ConvertSyncProtocolErrorTypePBToLocalType( | 268 sync_protocol_error.error_type = ConvertSyncProtocolErrorTypePBToLocalType( |
256 error.error_type()); | 269 error.error_type()); |
257 sync_protocol_error.error_description = error.error_description(); | 270 sync_protocol_error.error_description = error.error_description(); |
258 sync_protocol_error.url = error.url(); | 271 sync_protocol_error.url = error.url(); |
259 sync_protocol_error.action = ConvertClientActionPBToLocalClientAction( | 272 sync_protocol_error.action = ConvertClientActionPBToLocalClientAction( |
260 error.action()); | 273 error.action()); |
274 | |
275 if (error.throttled_data_type_ids_size() > 0) { | |
276 DCHECK(error.error_type() == ClientToServerResponse::THROTTLED); | |
277 for (int i = 0; i < error.throttled_data_type_ids_size(); ++i) { | |
278 sync_protocol_error.throttled_types.insert( | |
279 syncable::GetModelTypeFromExtensionFieldNumber( | |
280 error.throttled_data_type_ids(i))); | |
281 } | |
282 } | |
283 | |
261 return sync_protocol_error; | 284 return sync_protocol_error; |
262 } | 285 } |
263 | 286 |
264 // TODO(lipalani) : Rename these function names as per the CR for issue 7740067. | 287 // TODO(lipalani) : Rename these function names as per the CR for issue 7740067. |
265 browser_sync::SyncProtocolError ConvertLegacyErrorCodeToNewError( | 288 browser_sync::SyncProtocolError ConvertLegacyErrorCodeToNewError( |
266 const sync_pb::ClientToServerResponse::ErrorType& error_type) { | 289 const sync_pb::ClientToServerResponse::ErrorType& error_type) { |
267 browser_sync::SyncProtocolError error; | 290 browser_sync::SyncProtocolError error; |
268 error.error_type = ConvertSyncProtocolErrorTypePBToLocalType(error_type); | 291 error.error_type = ConvertSyncProtocolErrorTypePBToLocalType(error_type); |
269 if (error_type == ClientToServerResponse::CLEAR_PENDING || | 292 if (error_type == ClientToServerResponse::CLEAR_PENDING || |
270 error_type == ClientToServerResponse::NOT_MY_BIRTHDAY) { | 293 error_type == ClientToServerResponse::NOT_MY_BIRTHDAY) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 switch (sync_protocol_error.error_type) { | 347 switch (sync_protocol_error.error_type) { |
325 case browser_sync::UNKNOWN_ERROR: | 348 case browser_sync::UNKNOWN_ERROR: |
326 LOG(WARNING) << "Sync protocol out-of-date. The server is using a more " | 349 LOG(WARNING) << "Sync protocol out-of-date. The server is using a more " |
327 << "recent version."; | 350 << "recent version."; |
328 return false; | 351 return false; |
329 case browser_sync::SYNC_SUCCESS: | 352 case browser_sync::SYNC_SUCCESS: |
330 LogResponseProfilingData(*response); | 353 LogResponseProfilingData(*response); |
331 return true; | 354 return true; |
332 case browser_sync::THROTTLED: | 355 case browser_sync::THROTTLED: |
333 LOG(WARNING) << "Client silenced by server."; | 356 LOG(WARNING) << "Client silenced by server."; |
334 session->delegate()->OnSilencedUntil(base::TimeTicks::Now() + | 357 HandleThrottling(sync_protocol_error, |
335 GetThrottleDelay(*response)); | 358 base::TimeTicks::Now() + GetThrottleDelay(*response), |
359 session->context(), | |
360 session->delegate()); | |
336 return false; | 361 return false; |
337 case browser_sync::TRANSIENT_ERROR: | 362 case browser_sync::TRANSIENT_ERROR: |
338 return false; | 363 return false; |
339 case browser_sync::MIGRATION_DONE: | 364 case browser_sync::MIGRATION_DONE: |
340 HandleMigrationDoneResponse(response, session); | 365 HandleMigrationDoneResponse(response, session); |
341 return false; | 366 return false; |
342 case browser_sync::CLEAR_PENDING: | 367 case browser_sync::CLEAR_PENDING: |
343 case browser_sync::NOT_MY_BIRTHDAY: | 368 case browser_sync::NOT_MY_BIRTHDAY: |
344 return false; | 369 return false; |
345 default: | 370 default: |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
471 std::string SyncerProtoUtil::ClientToServerResponseDebugString( | 496 std::string SyncerProtoUtil::ClientToServerResponseDebugString( |
472 const sync_pb::ClientToServerResponse& response) { | 497 const sync_pb::ClientToServerResponse& response) { |
473 // Add more handlers as needed. | 498 // Add more handlers as needed. |
474 std::string output; | 499 std::string output; |
475 if (response.has_get_updates()) | 500 if (response.has_get_updates()) |
476 output.append(GetUpdatesResponseString(response.get_updates())); | 501 output.append(GetUpdatesResponseString(response.get_updates())); |
477 return output; | 502 return output; |
478 } | 503 } |
479 | 504 |
480 } // namespace browser_sync | 505 } // namespace browser_sync |
OLD | NEW |