Chromium Code Reviews| 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::sessions::SyncProtocolError& error) { | |
| 35 switch (error.error_type) { | |
| 36 case browser_sync::sessions::SUCCESS: | |
| 37 case browser_sync::sessions::MIGRATION_DONE: | |
| 38 case browser_sync::sessions::THROTTLED: | |
| 39 case browser_sync::sessions::TRANSIENT_ERROR: | |
| 40 return false; | |
| 41 case browser_sync::sessions::NOT_MY_BIRTHDAY: | |
| 42 case browser_sync::sessions::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::sessions::UNKNOWN_ACTION); | |
| 48 return true; | |
| 49 case browser_sync::sessions::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(const browser_sync::sessions::SyncProtocolError& error) { | |
| 62 return (error.action != browser_sync::sessions::UNKNOWN_ACTION); | |
| 63 } | |
| 64 } // namespace | |
| 65 | |
| 32 SyncScheduler::DelayProvider::DelayProvider() {} | 66 SyncScheduler::DelayProvider::DelayProvider() {} |
| 33 SyncScheduler::DelayProvider::~DelayProvider() {} | 67 SyncScheduler::DelayProvider::~DelayProvider() {} |
| 34 | 68 |
| 35 SyncScheduler::WaitInterval::WaitInterval() | 69 SyncScheduler::WaitInterval::WaitInterval() |
| 36 : mode(UNKNOWN), | 70 : mode(UNKNOWN), |
| 37 had_nudge(false) { | 71 had_nudge(false) { |
| 38 } | 72 } |
| 39 | 73 |
| 40 SyncScheduler::WaitInterval::~WaitInterval() {} | 74 SyncScheduler::WaitInterval::~WaitInterval() {} |
| 41 | 75 |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1077 sessions_commit_delay_ = new_delay; | 1111 sessions_commit_delay_ = new_delay; |
| 1078 } | 1112 } |
| 1079 | 1113 |
| 1080 void SyncScheduler::OnShouldStopSyncingPermanently() { | 1114 void SyncScheduler::OnShouldStopSyncingPermanently() { |
| 1081 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1115 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1082 SVLOG(2) << "OnShouldStopSyncingPermanently"; | 1116 SVLOG(2) << "OnShouldStopSyncingPermanently"; |
| 1083 syncer_->RequestEarlyExit(); // Thread-safe. | 1117 syncer_->RequestEarlyExit(); // Thread-safe. |
| 1084 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); | 1118 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); |
| 1085 } | 1119 } |
| 1086 | 1120 |
| 1121 void SyncScheduler::OnActionableError(sessions::SyncSession* session) { | |
| 1122 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 1123 SVLOG(2) << "OnActionableError"; | |
| 1124 SyncEngineEvent event(SyncEngineEvent::ACTIONABLE_ERROR); | |
| 1125 sessions::SyncSessionSnapshot snapshot(session->TakeSnapshot()); | |
| 1126 event.snapshot = &snapshot; | |
| 1127 session->context()->NotifyListeners(event); | |
| 1128 } | |
| 1129 | |
| 1130 void SyncScheduler::OnSyncProtocolError(sessions::SyncSession* session) { | |
| 1131 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 1132 if (ShouldRequestEarlyExit( | |
| 1133 session->status_controller()->sync_protocol_error())) { | |
| 1134 SVLOG(2) << "OnRequestEarlyExit"; | |
|
tim (not reviewing)
2011/08/25 15:58:55
nit - log should be updated "SyncScheduler request
lipalani1
2011/08/26 20:07:19
Done.
| |
| 1135 syncer_->RequestEarlyExit(); // Thread-safe. | |
| 1136 | |
|
tim (not reviewing)
2011/08/25 15:58:55
nit - extra newline
lipalani1
2011/08/26 20:07:19
Done.
| |
| 1137 } | |
| 1138 if (IsActionableError(session->status_controller()->sync_protocol_error())) | |
| 1139 OnActionableError(session); | |
| 1140 | |
|
tim (not reviewing)
2011/08/25 15:58:55
nit - extra newline.
lipalani1
2011/08/26 20:07:19
Done.
| |
| 1141 } | |
| 1142 | |
| 1143 | |
| 1087 void SyncScheduler::OnServerConnectionEvent( | 1144 void SyncScheduler::OnServerConnectionEvent( |
| 1088 const ServerConnectionEvent& event) { | 1145 const ServerConnectionEvent& event) { |
| 1089 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1146 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1090 PostTask(FROM_HERE, "CheckServerConnectionManagerStatus", | 1147 PostTask(FROM_HERE, "CheckServerConnectionManagerStatus", |
| 1091 method_factory_.NewRunnableMethod( | 1148 method_factory_.NewRunnableMethod( |
| 1092 &SyncScheduler::CheckServerConnectionManagerStatus, | 1149 &SyncScheduler::CheckServerConnectionManagerStatus, |
| 1093 event.connection_code)); | 1150 event.connection_code)); |
| 1094 } | 1151 } |
| 1095 | 1152 |
| 1096 void SyncScheduler::set_notifications_enabled(bool notifications_enabled) { | 1153 void SyncScheduler::set_notifications_enabled(bool notifications_enabled) { |
| 1097 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1154 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1098 session_context_->set_notifications_enabled(notifications_enabled); | 1155 session_context_->set_notifications_enabled(notifications_enabled); |
| 1099 } | 1156 } |
| 1100 | 1157 |
| 1101 base::TimeDelta SyncScheduler::sessions_commit_delay() const { | 1158 base::TimeDelta SyncScheduler::sessions_commit_delay() const { |
| 1102 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1159 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1103 return sessions_commit_delay_; | 1160 return sessions_commit_delay_; |
| 1104 } | 1161 } |
| 1105 | 1162 |
| 1106 #undef SVLOG_LOC | 1163 #undef SVLOG_LOC |
| 1107 | 1164 |
| 1108 #undef SVLOG | 1165 #undef SVLOG |
| 1109 | 1166 |
| 1110 #undef SLOG | 1167 #undef SLOG |
| 1111 | 1168 |
| 1112 #undef ENUM_CASE | 1169 #undef ENUM_CASE |
| 1113 | 1170 |
| 1114 } // browser_sync | 1171 } // browser_sync |
| OLD | NEW |