| 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/sync_scheduler.h" | 5 #include "chrome/browser/sync/engine/sync_scheduler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace browser_sync { | 23 namespace browser_sync { |
| 24 | 24 |
| 25 using sessions::SyncSession; | 25 using sessions::SyncSession; |
| 26 using sessions::SyncSessionSnapshot; | 26 using sessions::SyncSessionSnapshot; |
| 27 using sessions::SyncSourceInfo; | 27 using sessions::SyncSourceInfo; |
| 28 using syncable::ModelTypePayloadMap; | 28 using syncable::ModelTypePayloadMap; |
| 29 using syncable::ModelTypeBitSet; | 29 using syncable::ModelTypeBitSet; |
| 30 using sync_pb::GetUpdatesCallerInfo; | 30 using sync_pb::GetUpdatesCallerInfo; |
| 31 | 31 |
| 32 namespace { |
| 33 bool ShouldRequestEarlyExit( |
| 34 const browser_sync::SyncProtocolError& error) { |
| 35 switch (error.error_type) { |
| 36 case browser_sync::SYNC_SUCCESS: |
| 37 case browser_sync::MIGRATION_DONE: |
| 38 case browser_sync::THROTTLED: |
| 39 case browser_sync::TRANSIENT_ERROR: |
| 40 return false; |
| 41 case browser_sync::NOT_MY_BIRTHDAY: |
| 42 case browser_sync::CLEAR_PENDING: |
| 43 // If we send terminate sync early then |sync_cycle_ended| notification |
| 44 // would not be sent. If there were no actions then |ACTIONABLE_ERROR| |
| 45 // notification wouldnt be sent either. Then the UI layer would be left |
| 46 // waiting forever. So assert we would send something. |
| 47 DCHECK(error.action != browser_sync::UNKNOWN_ACTION); |
| 48 return true; |
| 49 case browser_sync::INVALID_CREDENTIAL: |
| 50 // The notification for this is handled by PostAndProcessHeaders|. |
| 51 // Server does no have to send any action for this. |
| 52 return true; |
| 53 // Make the default a NOTREACHED. So if a new error is introduced we |
| 54 // think about its expected functionality. |
| 55 default: |
| 56 NOTREACHED(); |
| 57 return false; |
| 58 } |
| 59 } |
| 60 |
| 61 bool IsActionableError( |
| 62 const browser_sync::SyncProtocolError& error) { |
| 63 return (error.action != browser_sync::UNKNOWN_ACTION); |
| 64 } |
| 65 } // namespace |
| 66 |
| 32 SyncScheduler::DelayProvider::DelayProvider() {} | 67 SyncScheduler::DelayProvider::DelayProvider() {} |
| 33 SyncScheduler::DelayProvider::~DelayProvider() {} | 68 SyncScheduler::DelayProvider::~DelayProvider() {} |
| 34 | 69 |
| 35 SyncScheduler::WaitInterval::WaitInterval() | 70 SyncScheduler::WaitInterval::WaitInterval() |
| 36 : mode(UNKNOWN), | 71 : mode(UNKNOWN), |
| 37 had_nudge(false) { | 72 had_nudge(false) { |
| 38 } | 73 } |
| 39 | 74 |
| 40 SyncScheduler::WaitInterval::~WaitInterval() {} | 75 SyncScheduler::WaitInterval::~WaitInterval() {} |
| 41 | 76 |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 sessions_commit_delay_ = new_delay; | 1108 sessions_commit_delay_ = new_delay; |
| 1074 } | 1109 } |
| 1075 | 1110 |
| 1076 void SyncScheduler::OnShouldStopSyncingPermanently() { | 1111 void SyncScheduler::OnShouldStopSyncingPermanently() { |
| 1077 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1112 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1078 SVLOG(2) << "OnShouldStopSyncingPermanently"; | 1113 SVLOG(2) << "OnShouldStopSyncingPermanently"; |
| 1079 syncer_->RequestEarlyExit(); // Thread-safe. | 1114 syncer_->RequestEarlyExit(); // Thread-safe. |
| 1080 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); | 1115 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); |
| 1081 } | 1116 } |
| 1082 | 1117 |
| 1118 void SyncScheduler::OnActionableError( |
| 1119 const sessions::SyncSessionSnapshot& snap) { |
| 1120 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1121 SVLOG(2) << "OnActionableError"; |
| 1122 SyncEngineEvent event(SyncEngineEvent::ACTIONABLE_ERROR); |
| 1123 sessions::SyncSessionSnapshot snapshot(snap); |
| 1124 event.snapshot = &snapshot; |
| 1125 session_context_->NotifyListeners(event); |
| 1126 } |
| 1127 |
| 1128 void SyncScheduler::OnSyncProtocolError( |
| 1129 const sessions::SyncSessionSnapshot& snapshot) { |
| 1130 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1131 if (ShouldRequestEarlyExit(snapshot.errors.sync_protocol_error)) { |
| 1132 SVLOG(2) << "Sync Scheduler requesting early exit."; |
| 1133 syncer_->RequestEarlyExit(); // Thread-safe. |
| 1134 } |
| 1135 if (IsActionableError(snapshot.errors.sync_protocol_error)) |
| 1136 OnActionableError(snapshot); |
| 1137 } |
| 1138 |
| 1139 |
| 1083 void SyncScheduler::OnServerConnectionEvent( | 1140 void SyncScheduler::OnServerConnectionEvent( |
| 1084 const ServerConnectionEvent& event) { | 1141 const ServerConnectionEvent& event) { |
| 1085 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1142 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1086 PostTask(FROM_HERE, "CheckServerConnectionManagerStatus", | 1143 PostTask(FROM_HERE, "CheckServerConnectionManagerStatus", |
| 1087 method_factory_.NewRunnableMethod( | 1144 method_factory_.NewRunnableMethod( |
| 1088 &SyncScheduler::CheckServerConnectionManagerStatus, | 1145 &SyncScheduler::CheckServerConnectionManagerStatus, |
| 1089 event.connection_code)); | 1146 event.connection_code)); |
| 1090 } | 1147 } |
| 1091 | 1148 |
| 1092 void SyncScheduler::set_notifications_enabled(bool notifications_enabled) { | 1149 void SyncScheduler::set_notifications_enabled(bool notifications_enabled) { |
| 1093 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1150 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1094 session_context_->set_notifications_enabled(notifications_enabled); | 1151 session_context_->set_notifications_enabled(notifications_enabled); |
| 1095 } | 1152 } |
| 1096 | 1153 |
| 1097 base::TimeDelta SyncScheduler::sessions_commit_delay() const { | 1154 base::TimeDelta SyncScheduler::sessions_commit_delay() const { |
| 1098 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1155 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1099 return sessions_commit_delay_; | 1156 return sessions_commit_delay_; |
| 1100 } | 1157 } |
| 1101 | 1158 |
| 1102 #undef SVLOG_LOC | 1159 #undef SVLOG_LOC |
| 1103 | 1160 |
| 1104 #undef SVLOG | 1161 #undef SVLOG |
| 1105 | 1162 |
| 1106 #undef SLOG | 1163 #undef SLOG |
| 1107 | 1164 |
| 1108 #undef ENUM_CASE | 1165 #undef ENUM_CASE |
| 1109 | 1166 |
| 1110 } // browser_sync | 1167 } // browser_sync |
| OLD | NEW |