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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // Helper macros to log with the syncer thread name; useful when there | 128 // Helper macros to log with the syncer thread name; useful when there |
129 // are multiple syncer threads involved. | 129 // are multiple syncer threads involved. |
130 | 130 |
131 #define SLOG(severity) LOG(severity) << name_ << ": " | 131 #define SLOG(severity) LOG(severity) << name_ << ": " |
132 | 132 |
133 #define SVLOG(verbose_level) VLOG(verbose_level) << name_ << ": " | 133 #define SVLOG(verbose_level) VLOG(verbose_level) << name_ << ": " |
134 | 134 |
135 #define SVLOG_LOC(from_here, verbose_level) \ | 135 #define SVLOG_LOC(from_here, verbose_level) \ |
136 VLOG_LOC(from_here, verbose_level) << name_ << ": " | 136 VLOG_LOC(from_here, verbose_level) << name_ << ": " |
137 | 137 |
138 namespace { | |
139 | |
140 const int kDefaultSessionsCommitDelaySeconds = 10; | |
tim (not reviewing)
2011/08/10 18:42:11
I was hoping to keep consts like this in one place
akalin
2011/08/10 20:10:36
I think it's okay for now since it's temp code. I
| |
141 | |
142 } // namespace | |
143 | |
138 SyncScheduler::SyncScheduler(const std::string& name, | 144 SyncScheduler::SyncScheduler(const std::string& name, |
139 sessions::SyncSessionContext* context, | 145 sessions::SyncSessionContext* context, |
140 Syncer* syncer) | 146 Syncer* syncer) |
141 : method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 147 : method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
142 name_(name), | 148 name_(name), |
143 sync_loop_(MessageLoop::current()), | 149 sync_loop_(MessageLoop::current()), |
144 started_(false), | 150 started_(false), |
145 syncer_short_poll_interval_seconds_( | 151 syncer_short_poll_interval_seconds_( |
146 TimeDelta::FromSeconds(kDefaultShortPollIntervalSeconds)), | 152 TimeDelta::FromSeconds(kDefaultShortPollIntervalSeconds)), |
147 syncer_long_poll_interval_seconds_( | 153 syncer_long_poll_interval_seconds_( |
148 TimeDelta::FromSeconds(kDefaultLongPollIntervalSeconds)), | 154 TimeDelta::FromSeconds(kDefaultLongPollIntervalSeconds)), |
155 sessions_commit_delay_( | |
156 TimeDelta::FromSeconds(kDefaultSessionsCommitDelaySeconds)), | |
149 mode_(NORMAL_MODE), | 157 mode_(NORMAL_MODE), |
150 server_connection_ok_(false), | 158 server_connection_ok_(false), |
151 delay_provider_(new DelayProvider()), | 159 delay_provider_(new DelayProvider()), |
152 syncer_(syncer), | 160 syncer_(syncer), |
153 session_context_(context) { | 161 session_context_(context) { |
154 DCHECK(sync_loop_); | 162 DCHECK(sync_loop_); |
155 } | 163 } |
156 | 164 |
157 SyncScheduler::~SyncScheduler() { | 165 SyncScheduler::~SyncScheduler() { |
158 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 166 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1056 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1064 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1057 syncer_short_poll_interval_seconds_ = new_interval; | 1065 syncer_short_poll_interval_seconds_ = new_interval; |
1058 } | 1066 } |
1059 | 1067 |
1060 void SyncScheduler::OnReceivedLongPollIntervalUpdate( | 1068 void SyncScheduler::OnReceivedLongPollIntervalUpdate( |
1061 const base::TimeDelta& new_interval) { | 1069 const base::TimeDelta& new_interval) { |
1062 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1070 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1063 syncer_long_poll_interval_seconds_ = new_interval; | 1071 syncer_long_poll_interval_seconds_ = new_interval; |
1064 } | 1072 } |
1065 | 1073 |
1074 void SyncScheduler::OnReceivedSessionsCommitDelay( | |
1075 const base::TimeDelta& new_delay) { | |
1076 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
1077 sessions_commit_delay_ = new_delay; | |
1078 } | |
1079 | |
1066 void SyncScheduler::OnShouldStopSyncingPermanently() { | 1080 void SyncScheduler::OnShouldStopSyncingPermanently() { |
1067 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1081 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1068 SVLOG(2) << "OnShouldStopSyncingPermanently"; | 1082 SVLOG(2) << "OnShouldStopSyncingPermanently"; |
1069 syncer_->RequestEarlyExit(); // Thread-safe. | 1083 syncer_->RequestEarlyExit(); // Thread-safe. |
1070 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); | 1084 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); |
1071 } | 1085 } |
1072 | 1086 |
1073 void SyncScheduler::OnServerConnectionEvent( | 1087 void SyncScheduler::OnServerConnectionEvent( |
1074 const ServerConnectionEvent& event) { | 1088 const ServerConnectionEvent& event) { |
1075 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1089 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1076 PostTask(FROM_HERE, "CheckServerConnectionManagerStatus", | 1090 PostTask(FROM_HERE, "CheckServerConnectionManagerStatus", |
1077 method_factory_.NewRunnableMethod( | 1091 method_factory_.NewRunnableMethod( |
1078 &SyncScheduler::CheckServerConnectionManagerStatus, | 1092 &SyncScheduler::CheckServerConnectionManagerStatus, |
1079 event.connection_code)); | 1093 event.connection_code)); |
1080 } | 1094 } |
1081 | 1095 |
1082 void SyncScheduler::set_notifications_enabled(bool notifications_enabled) { | 1096 void SyncScheduler::set_notifications_enabled(bool notifications_enabled) { |
1083 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1097 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1084 session_context_->set_notifications_enabled(notifications_enabled); | 1098 session_context_->set_notifications_enabled(notifications_enabled); |
1085 } | 1099 } |
1086 | 1100 |
1101 base::TimeDelta SyncScheduler::GetSessionsCommitDelay() const { | |
1102 return sessions_commit_delay_; | |
tim (not reviewing)
2011/08/10 18:42:11
The style guide would recommend calling this metho
akalin
2011/08/10 20:10:36
Done.
| |
1103 } | |
1104 | |
1087 #undef SVLOG_LOC | 1105 #undef SVLOG_LOC |
1088 | 1106 |
1089 #undef SVLOG | 1107 #undef SVLOG |
1090 | 1108 |
1091 #undef SLOG | 1109 #undef SLOG |
1092 | 1110 |
1093 #undef VLOG_LOC | |
1094 | |
1095 #undef VLOG_LOC_STREAM | |
1096 | |
1097 #undef ENUM_CASE | 1111 #undef ENUM_CASE |
1098 | 1112 |
1099 } // browser_sync | 1113 } // browser_sync |
OLD | NEW |