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::HandleThrottleError( |
| 191 const SyncProtocolError& error, |
| 192 const base::TimeTicks& throttled_until, |
| 193 sessions::SyncSessionContext* context, |
| 194 sessions::SyncSession::Delegate* delegate) { |
| 195 DCHECK_EQ(error.error_type, browser_sync::THROTTLED); |
| 196 if (error.error_data_types.size() > 0) { |
| 197 context->SetUnthrottleTime(error.error_data_types, throttled_until); |
| 198 } else { |
| 199 // No datatypes indicates the client should be completely throttled. |
| 200 delegate->OnSilencedUntil(throttled_until); |
| 201 } |
| 202 } |
| 203 |
190 namespace { | 204 namespace { |
191 | 205 |
192 // Helper function for an assertion in PostClientToServerMessage. | 206 // Helper function for an assertion in PostClientToServerMessage. |
193 bool IsVeryFirstGetUpdates(const ClientToServerMessage& message) { | 207 bool IsVeryFirstGetUpdates(const ClientToServerMessage& message) { |
194 if (!message.has_get_updates()) | 208 if (!message.has_get_updates()) |
195 return false; | 209 return false; |
196 DCHECK_LT(0, message.get_updates().from_progress_marker_size()); | 210 DCHECK_LT(0, message.get_updates().from_progress_marker_size()); |
197 for (int i = 0; i < message.get_updates().from_progress_marker_size(); ++i) { | 211 for (int i = 0; i < message.get_updates().from_progress_marker_size(); ++i) { |
198 if (!message.get_updates().from_progress_marker(i).token().empty()) | 212 if (!message.get_updates().from_progress_marker(i).token().empty()) |
199 return false; | 213 return false; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 265 |
252 browser_sync::SyncProtocolError ConvertErrorPBToLocalType( | 266 browser_sync::SyncProtocolError ConvertErrorPBToLocalType( |
253 const sync_pb::ClientToServerResponse::Error& error) { | 267 const sync_pb::ClientToServerResponse::Error& error) { |
254 browser_sync::SyncProtocolError sync_protocol_error; | 268 browser_sync::SyncProtocolError sync_protocol_error; |
255 sync_protocol_error.error_type = ConvertSyncProtocolErrorTypePBToLocalType( | 269 sync_protocol_error.error_type = ConvertSyncProtocolErrorTypePBToLocalType( |
256 error.error_type()); | 270 error.error_type()); |
257 sync_protocol_error.error_description = error.error_description(); | 271 sync_protocol_error.error_description = error.error_description(); |
258 sync_protocol_error.url = error.url(); | 272 sync_protocol_error.url = error.url(); |
259 sync_protocol_error.action = ConvertClientActionPBToLocalClientAction( | 273 sync_protocol_error.action = ConvertClientActionPBToLocalClientAction( |
260 error.action()); | 274 error.action()); |
| 275 |
| 276 if (error.error_data_type_ids_size() > 0) { |
| 277 // THROTTLED is currently the only error code that uses |error_data_types|. |
| 278 DCHECK_EQ(error.error_type(), ClientToServerResponse::THROTTLED); |
| 279 for (int i = 0; i < error.error_data_type_ids_size(); ++i) { |
| 280 sync_protocol_error.error_data_types.insert( |
| 281 syncable::GetModelTypeFromExtensionFieldNumber( |
| 282 error.error_data_type_ids(i))); |
| 283 } |
| 284 } |
| 285 |
261 return sync_protocol_error; | 286 return sync_protocol_error; |
262 } | 287 } |
263 | 288 |
264 // TODO(lipalani) : Rename these function names as per the CR for issue 7740067. | 289 // TODO(lipalani) : Rename these function names as per the CR for issue 7740067. |
265 browser_sync::SyncProtocolError ConvertLegacyErrorCodeToNewError( | 290 browser_sync::SyncProtocolError ConvertLegacyErrorCodeToNewError( |
266 const sync_pb::ClientToServerResponse::ErrorType& error_type) { | 291 const sync_pb::ClientToServerResponse::ErrorType& error_type) { |
267 browser_sync::SyncProtocolError error; | 292 browser_sync::SyncProtocolError error; |
268 error.error_type = ConvertSyncProtocolErrorTypePBToLocalType(error_type); | 293 error.error_type = ConvertSyncProtocolErrorTypePBToLocalType(error_type); |
269 if (error_type == ClientToServerResponse::CLEAR_PENDING || | 294 if (error_type == ClientToServerResponse::CLEAR_PENDING || |
270 error_type == ClientToServerResponse::NOT_MY_BIRTHDAY) { | 295 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) { | 349 switch (sync_protocol_error.error_type) { |
325 case browser_sync::UNKNOWN_ERROR: | 350 case browser_sync::UNKNOWN_ERROR: |
326 LOG(WARNING) << "Sync protocol out-of-date. The server is using a more " | 351 LOG(WARNING) << "Sync protocol out-of-date. The server is using a more " |
327 << "recent version."; | 352 << "recent version."; |
328 return false; | 353 return false; |
329 case browser_sync::SYNC_SUCCESS: | 354 case browser_sync::SYNC_SUCCESS: |
330 LogResponseProfilingData(*response); | 355 LogResponseProfilingData(*response); |
331 return true; | 356 return true; |
332 case browser_sync::THROTTLED: | 357 case browser_sync::THROTTLED: |
333 LOG(WARNING) << "Client silenced by server."; | 358 LOG(WARNING) << "Client silenced by server."; |
334 session->delegate()->OnSilencedUntil(base::TimeTicks::Now() + | 359 HandleThrottleError(sync_protocol_error, |
335 GetThrottleDelay(*response)); | 360 base::TimeTicks::Now() + GetThrottleDelay(*response), |
| 361 session->context(), |
| 362 session->delegate()); |
336 return false; | 363 return false; |
337 case browser_sync::TRANSIENT_ERROR: | 364 case browser_sync::TRANSIENT_ERROR: |
338 return false; | 365 return false; |
339 case browser_sync::MIGRATION_DONE: | 366 case browser_sync::MIGRATION_DONE: |
340 HandleMigrationDoneResponse(response, session); | 367 HandleMigrationDoneResponse(response, session); |
341 return false; | 368 return false; |
342 case browser_sync::CLEAR_PENDING: | 369 case browser_sync::CLEAR_PENDING: |
343 case browser_sync::NOT_MY_BIRTHDAY: | 370 case browser_sync::NOT_MY_BIRTHDAY: |
344 return false; | 371 return false; |
345 default: | 372 default: |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 std::string SyncerProtoUtil::ClientToServerResponseDebugString( | 498 std::string SyncerProtoUtil::ClientToServerResponseDebugString( |
472 const sync_pb::ClientToServerResponse& response) { | 499 const sync_pb::ClientToServerResponse& response) { |
473 // Add more handlers as needed. | 500 // Add more handlers as needed. |
474 std::string output; | 501 std::string output; |
475 if (response.has_get_updates()) | 502 if (response.has_get_updates()) |
476 output.append(GetUpdatesResponseString(response.get_updates())); | 503 output.append(GetUpdatesResponseString(response.get_updates())); |
477 return output; | 504 return output; |
478 } | 505 } |
479 | 506 |
480 } // namespace browser_sync | 507 } // namespace browser_sync |
OLD | NEW |