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(const browser_sync::sessions::SyncError& error) { | |
| 34 switch (error.error_type) { | |
| 35 case browser_sync::sessions::SUCCESS: | |
| 36 case browser_sync::sessions::MIGRATION_DONE: | |
| 37 case browser_sync::sessions::THROTTLED: | |
| 38 case browser_sync::sessions::TRANSIENT_ERROR: | |
| 39 return false; | |
| 40 case browser_sync::sessions::NOT_MY_BIRTHDAY: | |
| 41 case browser_sync::sessions::CLEAR_PENDING: | |
| 42 // If we send terminate sync early then |sync_cycle_ended| notification | |
| 43 // would not be sent. If there were no actions then |ACTIONABLE_ERROR| | |
| 44 // notification wouldnt be sent either. Then the UI layer would be left | |
| 45 // waiting forever. So assert we would send something. | |
| 46 DCHECK(error.action != browser_sync::sessions::UNKNOWN_ACTION); | |
| 47 return true; | |
| 48 case browser_sync::sessions::INVALID_CREDENTIAL: | |
| 49 // The notification for this is handled by PostAndProcessHeaders|. | |
| 50 // Server does no have to send any action for this. | |
| 51 return true; | |
| 52 // Make the default a NOTREACHED. So if a new error is introduced we | |
| 53 // think about its expected functionality. | |
| 54 default: | |
| 55 NOTREACHED(); | |
| 56 return false; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 bool IsActionableError(const browser_sync::sessions::SyncError& error) { | |
| 61 return (error.action != browser_sync::sessions::UNKNOWN_ACTION); | |
| 62 } | |
| 63 } // namespace | |
| 64 | |
| 32 SyncScheduler::DelayProvider::DelayProvider() {} | 65 SyncScheduler::DelayProvider::DelayProvider() {} |
| 33 SyncScheduler::DelayProvider::~DelayProvider() {} | 66 SyncScheduler::DelayProvider::~DelayProvider() {} |
| 34 | 67 |
| 35 SyncScheduler::WaitInterval::WaitInterval() | 68 SyncScheduler::WaitInterval::WaitInterval() |
| 36 : mode(UNKNOWN), | 69 : mode(UNKNOWN), |
| 37 had_nudge(false) { | 70 had_nudge(false) { |
| 38 } | 71 } |
| 39 | 72 |
| 40 SyncScheduler::WaitInterval::~WaitInterval() {} | 73 SyncScheduler::WaitInterval::~WaitInterval() {} |
| 41 | 74 |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1077 sessions_commit_delay_ = new_delay; | 1110 sessions_commit_delay_ = new_delay; |
| 1078 } | 1111 } |
| 1079 | 1112 |
| 1080 void SyncScheduler::OnShouldStopSyncingPermanently() { | 1113 void SyncScheduler::OnShouldStopSyncingPermanently() { |
| 1081 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1114 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1082 SVLOG(2) << "OnShouldStopSyncingPermanently"; | 1115 SVLOG(2) << "OnShouldStopSyncingPermanently"; |
| 1083 syncer_->RequestEarlyExit(); // Thread-safe. | 1116 syncer_->RequestEarlyExit(); // Thread-safe. |
| 1084 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); | 1117 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); |
| 1085 } | 1118 } |
| 1086 | 1119 |
| 1120 void SyncScheduler::OnRequestEarlyExit() { | |
|
tim (not reviewing)
2011/08/24 14:47:51
I think we should inline this method for now, and
lipalani1
2011/08/25 06:14:06
Done.
| |
| 1121 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 1122 SVLOG(2) << "OnRequestEarlyExit"; | |
| 1123 syncer_->RequestEarlyExit(); // Thread-safe. | |
| 1124 } | |
| 1125 | |
| 1126 void SyncScheduler::OnActionableError(sessions::SyncSession* session) { | |
| 1127 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 1128 SVLOG(2) << "OnActionableError"; | |
| 1129 SyncEngineEvent event(SyncEngineEvent::ACTIONABLE_ERROR); | |
| 1130 sessions::SyncSessionSnapshot snapshot(session->TakeSnapshot()); | |
| 1131 event.snapshot = &snapshot; | |
| 1132 session->context()->NotifyListeners(event); | |
| 1133 } | |
| 1134 | |
| 1135 void SyncScheduler::OnSyncError(sessions::SyncSession* session) { | |
|
tim (not reviewing)
2011/08/24 14:47:51
We should just pass the error here, and / or just
lipalani1
2011/08/25 06:14:06
The problem is we need the snapshot/error and the
tim (not reviewing)
2011/08/25 15:58:54
The scheduler owns the context, so there's no need
| |
| 1136 if (ShouldRequestEarlyExit(session->status_controller()->sync_error())) { | |
| 1137 OnRequestEarlyExit(); | |
| 1138 } | |
| 1139 if (IsActionableError(session->status_controller()->sync_error())) { | |
| 1140 OnActionableError(session); | |
| 1141 } | |
|
tim (not reviewing)
2011/08/24 14:47:51
file doesn't have braces on single line ifs
lipalani1
2011/08/25 06:14:06
Done.
| |
| 1142 } | |
| 1143 | |
| 1144 | |
| 1087 void SyncScheduler::OnServerConnectionEvent( | 1145 void SyncScheduler::OnServerConnectionEvent( |
| 1088 const ServerConnectionEvent& event) { | 1146 const ServerConnectionEvent& event) { |
| 1089 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1147 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1090 PostTask(FROM_HERE, "CheckServerConnectionManagerStatus", | 1148 PostTask(FROM_HERE, "CheckServerConnectionManagerStatus", |
| 1091 method_factory_.NewRunnableMethod( | 1149 method_factory_.NewRunnableMethod( |
| 1092 &SyncScheduler::CheckServerConnectionManagerStatus, | 1150 &SyncScheduler::CheckServerConnectionManagerStatus, |
| 1093 event.connection_code)); | 1151 event.connection_code)); |
| 1094 } | 1152 } |
| 1095 | 1153 |
| 1096 void SyncScheduler::set_notifications_enabled(bool notifications_enabled) { | 1154 void SyncScheduler::set_notifications_enabled(bool notifications_enabled) { |
| 1097 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1155 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1098 session_context_->set_notifications_enabled(notifications_enabled); | 1156 session_context_->set_notifications_enabled(notifications_enabled); |
| 1099 } | 1157 } |
| 1100 | 1158 |
| 1101 base::TimeDelta SyncScheduler::sessions_commit_delay() const { | 1159 base::TimeDelta SyncScheduler::sessions_commit_delay() const { |
| 1102 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1160 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1103 return sessions_commit_delay_; | 1161 return sessions_commit_delay_; |
| 1104 } | 1162 } |
| 1105 | 1163 |
| 1106 #undef SVLOG_LOC | 1164 #undef SVLOG_LOC |
| 1107 | 1165 |
| 1108 #undef SVLOG | 1166 #undef SVLOG |
| 1109 | 1167 |
| 1110 #undef SLOG | 1168 #undef SLOG |
| 1111 | 1169 |
| 1112 #undef ENUM_CASE | 1170 #undef ENUM_CASE |
| 1113 | 1171 |
| 1114 } // browser_sync | 1172 } // browser_sync |
| OLD | NEW |