[email protected] | 24c9ee5 | 2014-06-02 22:17:50 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 8516471 | 2010-06-23 01:13:56 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 5 | #include "components/invalidation/sync_system_resources.h" |
[email protected] | 8516471 | 2010-06-23 01:13:56 | [diff] [blame] | 6 | |
| 7 | #include <cstdlib> |
[email protected] | c16e90e | 2010-10-06 18:17:05 | [diff] [blame] | 8 | #include <cstring> |
[email protected] | 8516471 | 2010-06-23 01:13:56 | [diff] [blame] | 9 | #include <string> |
| 10 | |
[email protected] | d9d3153 | 2011-12-23 00:07:20 | [diff] [blame] | 11 | #include "base/bind.h" |
[email protected] | 8516471 | 2010-06-23 01:13:56 | [diff] [blame] | 12 | #include "base/logging.h" |
[email protected] | a7629597 | 2013-07-18 00:42:32 | [diff] [blame] | 13 | #include "base/message_loop/message_loop.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 14 | #include "base/stl_util.h" |
[email protected] | a4bbc1f9 | 2013-06-11 07:28:19 | [diff] [blame] | 15 | #include "base/strings/string_util.h" |
| 16 | #include "base/strings/stringprintf.h" |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 17 | #include "components/invalidation/gcm_network_channel.h" |
| 18 | #include "components/invalidation/gcm_network_channel_delegate.h" |
[email protected] | 51766bf | 2014-07-24 01:13:47 | [diff] [blame] | 19 | #include "components/invalidation/invalidation_util.h" |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 20 | #include "components/invalidation/push_client_channel.h" |
[email protected] | 739cee3 | 2012-06-20 20:37:28 | [diff] [blame] | 21 | #include "google/cacheinvalidation/deps/callback.h" |
[email protected] | b0e1c13 | 2012-03-14 06:10:13 | [diff] [blame] | 22 | #include "google/cacheinvalidation/include/types.h" |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 23 | #include "jingle/notifier/listener/push_client.h" |
[email protected] | 8516471 | 2010-06-23 01:13:56 | [diff] [blame] | 24 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 25 | namespace syncer { |
[email protected] | 8516471 | 2010-06-23 01:13:56 | [diff] [blame] | 26 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 27 | SyncLogger::SyncLogger() {} |
| 28 | SyncLogger::~SyncLogger() {} |
[email protected] | 8516471 | 2010-06-23 01:13:56 | [diff] [blame] | 29 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 30 | void SyncLogger::Log(LogLevel level, const char* file, int line, |
| 31 | const char* format, ...) { |
[email protected] | 890de9027 | 2011-07-22 08:20:52 | [diff] [blame] | 32 | logging::LogSeverity log_severity = -2; // VLOG(2) |
| 33 | bool emit_log = false; |
[email protected] | c16e90e | 2010-10-06 18:17:05 | [diff] [blame] | 34 | switch (level) { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 35 | case FINE_LEVEL: |
[email protected] | 890de9027 | 2011-07-22 08:20:52 | [diff] [blame] | 36 | log_severity = -2; // VLOG(2) |
| 37 | emit_log = VLOG_IS_ON(2); |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 38 | break; |
[email protected] | c16e90e | 2010-10-06 18:17:05 | [diff] [blame] | 39 | case INFO_LEVEL: |
[email protected] | 890de9027 | 2011-07-22 08:20:52 | [diff] [blame] | 40 | log_severity = -1; // VLOG(1) |
| 41 | emit_log = VLOG_IS_ON(1); |
[email protected] | c16e90e | 2010-10-06 18:17:05 | [diff] [blame] | 42 | break; |
| 43 | case WARNING_LEVEL: |
| 44 | log_severity = logging::LOG_WARNING; |
[email protected] | 890de9027 | 2011-07-22 08:20:52 | [diff] [blame] | 45 | emit_log = LOG_IS_ON(WARNING); |
[email protected] | c16e90e | 2010-10-06 18:17:05 | [diff] [blame] | 46 | break; |
[email protected] | 5bfa256 | 2010-10-13 02:04:22 | [diff] [blame] | 47 | case SEVERE_LEVEL: |
[email protected] | c16e90e | 2010-10-06 18:17:05 | [diff] [blame] | 48 | log_severity = logging::LOG_ERROR; |
[email protected] | 890de9027 | 2011-07-22 08:20:52 | [diff] [blame] | 49 | emit_log = LOG_IS_ON(ERROR); |
[email protected] | c16e90e | 2010-10-06 18:17:05 | [diff] [blame] | 50 | break; |
| 51 | } |
[email protected] | 890de9027 | 2011-07-22 08:20:52 | [diff] [blame] | 52 | if (emit_log) { |
| 53 | va_list ap; |
| 54 | va_start(ap, format); |
| 55 | std::string result; |
| 56 | base::StringAppendV(&result, format, ap); |
| 57 | logging::LogMessage(file, line, log_severity).stream() << result; |
| 58 | va_end(ap); |
| 59 | } |
[email protected] | 8516471 | 2010-06-23 01:13:56 | [diff] [blame] | 60 | } |
| 61 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 62 | void SyncLogger::SetSystemResources(invalidation::SystemResources* resources) { |
[email protected] | b5d1f3f32 | 2012-01-20 09:51:42 | [diff] [blame] | 63 | // Do nothing. |
| 64 | } |
| 65 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 66 | SyncInvalidationScheduler::SyncInvalidationScheduler() |
[email protected] | 37d5b347 | 2013-10-10 16:20:36 | [diff] [blame] | 67 | : created_on_loop_(base::MessageLoop::current()), |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 68 | is_started_(false), |
[email protected] | 37d5b347 | 2013-10-10 16:20:36 | [diff] [blame] | 69 | is_stopped_(false), |
| 70 | weak_factory_(this) { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 71 | CHECK(created_on_loop_); |
[email protected] | 538f58d | 2010-10-12 18:04:15 | [diff] [blame] | 72 | } |
| 73 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 74 | SyncInvalidationScheduler::~SyncInvalidationScheduler() { |
[email protected] | 21cb28a | 2013-05-07 03:52:45 | [diff] [blame] | 75 | CHECK_EQ(created_on_loop_, base::MessageLoop::current()); |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 76 | CHECK(is_stopped_); |
[email protected] | 6c85292 | 2010-10-07 21:45:02 | [diff] [blame] | 77 | } |
| 78 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 79 | void SyncInvalidationScheduler::Start() { |
[email protected] | 21cb28a | 2013-05-07 03:52:45 | [diff] [blame] | 80 | CHECK_EQ(created_on_loop_, base::MessageLoop::current()); |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 81 | CHECK(!is_started_); |
| 82 | is_started_ = true; |
| 83 | is_stopped_ = false; |
[email protected] | ab1e57e | 2011-12-21 23:21:50 | [diff] [blame] | 84 | weak_factory_.InvalidateWeakPtrs(); |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 85 | } |
| 86 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 87 | void SyncInvalidationScheduler::Stop() { |
[email protected] | 21cb28a | 2013-05-07 03:52:45 | [diff] [blame] | 88 | CHECK_EQ(created_on_loop_, base::MessageLoop::current()); |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 89 | is_stopped_ = true; |
| 90 | is_started_ = false; |
[email protected] | ab1e57e | 2011-12-21 23:21:50 | [diff] [blame] | 91 | weak_factory_.InvalidateWeakPtrs(); |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 92 | STLDeleteElements(&posted_tasks_); |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 93 | } |
| 94 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 95 | void SyncInvalidationScheduler::Schedule(invalidation::TimeDelta delay, |
| 96 | invalidation::Closure* task) { |
[email protected] | ab1e57e | 2011-12-21 23:21:50 | [diff] [blame] | 97 | DCHECK(invalidation::IsCallbackRepeatable(task)); |
[email protected] | 21cb28a | 2013-05-07 03:52:45 | [diff] [blame] | 98 | CHECK_EQ(created_on_loop_, base::MessageLoop::current()); |
[email protected] | ab1e57e | 2011-12-21 23:21:50 | [diff] [blame] | 99 | |
| 100 | if (!is_started_) { |
| 101 | delete task; |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 102 | return; |
| 103 | } |
[email protected] | ab1e57e | 2011-12-21 23:21:50 | [diff] [blame] | 104 | |
| 105 | posted_tasks_.insert(task); |
[email protected] | 21cb28a | 2013-05-07 03:52:45 | [diff] [blame] | 106 | base::MessageLoop::current()->PostDelayedTask( |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 107 | FROM_HERE, base::Bind(&SyncInvalidationScheduler::RunPostedTask, |
[email protected] | ab1e57e | 2011-12-21 23:21:50 | [diff] [blame] | 108 | weak_factory_.GetWeakPtr(), task), |
[email protected] | d88fdb3 | 2012-01-12 21:32:44 | [diff] [blame] | 109 | delay); |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 110 | } |
| 111 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 112 | bool SyncInvalidationScheduler::IsRunningOnThread() const { |
[email protected] | 21cb28a | 2013-05-07 03:52:45 | [diff] [blame] | 113 | return created_on_loop_ == base::MessageLoop::current(); |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 114 | } |
| 115 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 116 | invalidation::Time SyncInvalidationScheduler::GetCurrentTime() const { |
[email protected] | 21cb28a | 2013-05-07 03:52:45 | [diff] [blame] | 117 | CHECK_EQ(created_on_loop_, base::MessageLoop::current()); |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 118 | return base::Time::Now(); |
| 119 | } |
| 120 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 121 | void SyncInvalidationScheduler::SetSystemResources( |
[email protected] | b5d1f3f32 | 2012-01-20 09:51:42 | [diff] [blame] | 122 | invalidation::SystemResources* resources) { |
| 123 | // Do nothing. |
| 124 | } |
| 125 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 126 | void SyncInvalidationScheduler::RunPostedTask(invalidation::Closure* task) { |
[email protected] | 21cb28a | 2013-05-07 03:52:45 | [diff] [blame] | 127 | CHECK_EQ(created_on_loop_, base::MessageLoop::current()); |
[email protected] | 739cee3 | 2012-06-20 20:37:28 | [diff] [blame] | 128 | task->Run(); |
[email protected] | cbea2bd | 2010-07-13 19:26:24 | [diff] [blame] | 129 | posted_tasks_.erase(task); |
[email protected] | 739cee3 | 2012-06-20 20:37:28 | [diff] [blame] | 130 | delete task; |
[email protected] | cbea2bd | 2010-07-13 19:26:24 | [diff] [blame] | 131 | } |
| 132 | |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 133 | SyncNetworkChannel::SyncNetworkChannel() |
[email protected] | afff175 | 2014-06-20 04:42:10 | [diff] [blame] | 134 | : last_network_status_(false), |
[email protected] | edfe19f | 2014-03-21 01:38:12 | [diff] [blame] | 135 | received_messages_count_(0) {} |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 136 | |
| 137 | SyncNetworkChannel::~SyncNetworkChannel() { |
| 138 | STLDeleteElements(&network_status_receivers_); |
| 139 | } |
| 140 | |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 141 | void SyncNetworkChannel::SetMessageReceiver( |
| 142 | invalidation::MessageCallback* incoming_receiver) { |
| 143 | incoming_receiver_.reset(incoming_receiver); |
| 144 | } |
| 145 | |
| 146 | void SyncNetworkChannel::AddNetworkStatusReceiver( |
| 147 | invalidation::NetworkStatusCallback* network_status_receiver) { |
[email protected] | afff175 | 2014-06-20 04:42:10 | [diff] [blame] | 148 | network_status_receiver->Run(last_network_status_); |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 149 | network_status_receivers_.push_back(network_status_receiver); |
| 150 | } |
| 151 | |
| 152 | void SyncNetworkChannel::SetSystemResources( |
| 153 | invalidation::SystemResources* resources) { |
| 154 | // Do nothing. |
| 155 | } |
| 156 | |
| 157 | void SyncNetworkChannel::AddObserver(Observer* observer) { |
| 158 | observers_.AddObserver(observer); |
| 159 | } |
| 160 | |
| 161 | void SyncNetworkChannel::RemoveObserver(Observer* observer) { |
| 162 | observers_.RemoveObserver(observer); |
| 163 | } |
| 164 | |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 165 | scoped_ptr<SyncNetworkChannel> SyncNetworkChannel::CreatePushClientChannel( |
| 166 | const notifier::NotifierOptions& notifier_options) { |
| 167 | scoped_ptr<notifier::PushClient> push_client( |
| 168 | notifier::PushClient::CreateDefaultOnIOThread(notifier_options)); |
| 169 | return scoped_ptr<SyncNetworkChannel>( |
| 170 | new PushClientChannel(push_client.Pass())); |
| 171 | } |
| 172 | |
[email protected] | df006cbc | 2014-01-22 18:36:20 | [diff] [blame] | 173 | scoped_ptr<SyncNetworkChannel> SyncNetworkChannel::CreateGCMNetworkChannel( |
| 174 | scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 175 | scoped_ptr<GCMNetworkChannelDelegate> delegate) { |
| 176 | return scoped_ptr<SyncNetworkChannel>(new GCMNetworkChannel( |
| 177 | request_context_getter, delegate.Pass())); |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 178 | } |
| 179 | |
[email protected] | afff175 | 2014-06-20 04:42:10 | [diff] [blame] | 180 | void SyncNetworkChannel::NotifyNetworkStatusChange(bool online) { |
| 181 | // Remember network state for future NetworkStatusReceivers. |
| 182 | last_network_status_ = online; |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 183 | // Notify NetworkStatusReceivers in cacheinvalidation. |
| 184 | for (NetworkStatusReceiverList::const_iterator it = |
| 185 | network_status_receivers_.begin(); |
| 186 | it != network_status_receivers_.end(); ++it) { |
[email protected] | afff175 | 2014-06-20 04:42:10 | [diff] [blame] | 187 | (*it)->Run(online); |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 188 | } |
[email protected] | afff175 | 2014-06-20 04:42:10 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | void SyncNetworkChannel::NotifyChannelStateChange( |
| 192 | InvalidatorState invalidator_state) { |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 193 | FOR_EACH_OBSERVER(Observer, observers_, |
[email protected] | afff175 | 2014-06-20 04:42:10 | [diff] [blame] | 194 | OnNetworkChannelStateChanged(invalidator_state)); |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 195 | } |
| 196 | |
[email protected] | 3b73b25 | 2014-03-01 00:18:54 | [diff] [blame] | 197 | bool SyncNetworkChannel::DeliverIncomingMessage(const std::string& message) { |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 198 | if (!incoming_receiver_) { |
| 199 | DLOG(ERROR) << "No receiver for incoming notification"; |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 200 | return false; |
| 201 | } |
[email protected] | edfe19f | 2014-03-21 01:38:12 | [diff] [blame] | 202 | received_messages_count_++; |
[email protected] | 3b73b25 | 2014-03-01 00:18:54 | [diff] [blame] | 203 | incoming_receiver_->Run(message); |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 204 | return true; |
| 205 | } |
| 206 | |
[email protected] | edfe19f | 2014-03-21 01:38:12 | [diff] [blame] | 207 | int SyncNetworkChannel::GetReceivedMessagesCount() const { |
| 208 | return received_messages_count_; |
| 209 | } |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 210 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 211 | SyncStorage::SyncStorage(StateWriter* state_writer, |
| 212 | invalidation::Scheduler* scheduler) |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 213 | : state_writer_(state_writer), |
| 214 | scheduler_(scheduler) { |
| 215 | DCHECK(state_writer_); |
| 216 | DCHECK(scheduler_); |
| 217 | } |
| 218 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 219 | SyncStorage::~SyncStorage() {} |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 220 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 221 | void SyncStorage::WriteKey(const std::string& key, const std::string& value, |
| 222 | invalidation::WriteKeyCallback* done) { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 223 | CHECK(state_writer_); |
| 224 | // TODO(ghc): actually write key,value associations, and don't invoke the |
| 225 | // callback until the operation completes. |
| 226 | state_writer_->WriteState(value); |
| 227 | cached_state_ = value; |
| 228 | // According to the cache invalidation API folks, we can do this as |
| 229 | // long as we make sure to clear the persistent state that we start |
| 230 | // up the cache invalidation client with. However, we musn't do it |
| 231 | // right away, as we may be called under a lock that the callback |
| 232 | // uses. |
| 233 | scheduler_->Schedule( |
| 234 | invalidation::Scheduler::NoDelay(), |
| 235 | invalidation::NewPermanentCallback( |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 236 | this, &SyncStorage::RunAndDeleteWriteKeyCallback, |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 237 | done)); |
| 238 | } |
| 239 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 240 | void SyncStorage::ReadKey(const std::string& key, |
| 241 | invalidation::ReadKeyCallback* done) { |
[email protected] | 8b2a7f60 | 2011-07-26 21:01:10 | [diff] [blame] | 242 | DCHECK(scheduler_->IsRunningOnThread()) << "not running on scheduler thread"; |
| 243 | RunAndDeleteReadKeyCallback(done, cached_state_); |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 244 | } |
| 245 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 246 | void SyncStorage::DeleteKey(const std::string& key, |
| 247 | invalidation::DeleteKeyCallback* done) { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 248 | // TODO(ghc): Implement. |
| 249 | LOG(WARNING) << "ignoring call to DeleteKey(" << key << ", callback)"; |
| 250 | } |
| 251 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 252 | void SyncStorage::ReadAllKeys(invalidation::ReadAllKeysCallback* done) { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 253 | // TODO(ghc): Implement. |
| 254 | LOG(WARNING) << "ignoring call to ReadAllKeys(callback)"; |
| 255 | } |
| 256 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 257 | void SyncStorage::SetSystemResources( |
[email protected] | b5d1f3f32 | 2012-01-20 09:51:42 | [diff] [blame] | 258 | invalidation::SystemResources* resources) { |
| 259 | // Do nothing. |
| 260 | } |
| 261 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 262 | void SyncStorage::RunAndDeleteWriteKeyCallback( |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 263 | invalidation::WriteKeyCallback* callback) { |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 264 | callback->Run( |
| 265 | invalidation::Status(invalidation::Status::SUCCESS, std::string())); |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 266 | delete callback; |
| 267 | } |
| 268 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 269 | void SyncStorage::RunAndDeleteReadKeyCallback( |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 270 | invalidation::ReadKeyCallback* callback, const std::string& value) { |
| 271 | callback->Run(std::make_pair( |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 272 | invalidation::Status(invalidation::Status::SUCCESS, std::string()), |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 273 | value)); |
| 274 | delete callback; |
| 275 | } |
| 276 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 277 | SyncSystemResources::SyncSystemResources( |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 278 | SyncNetworkChannel* sync_network_channel, |
[email protected] | 1f7eba7 | 2012-05-30 09:10:17 | [diff] [blame] | 279 | StateWriter* state_writer) |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 280 | : is_started_(false), |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 281 | logger_(new SyncLogger()), |
| 282 | internal_scheduler_(new SyncInvalidationScheduler()), |
| 283 | listener_scheduler_(new SyncInvalidationScheduler()), |
| 284 | storage_(new SyncStorage(state_writer, internal_scheduler_.get())), |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 285 | sync_network_channel_(sync_network_channel) { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 286 | } |
| 287 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 288 | SyncSystemResources::~SyncSystemResources() { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 289 | Stop(); |
| 290 | } |
| 291 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 292 | void SyncSystemResources::Start() { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 293 | internal_scheduler_->Start(); |
| 294 | listener_scheduler_->Start(); |
[email protected] | b5d1f3f32 | 2012-01-20 09:51:42 | [diff] [blame] | 295 | is_started_ = true; |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 296 | } |
| 297 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 298 | void SyncSystemResources::Stop() { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 299 | internal_scheduler_->Stop(); |
| 300 | listener_scheduler_->Stop(); |
| 301 | } |
| 302 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 303 | bool SyncSystemResources::IsStarted() const { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 304 | return is_started_; |
| 305 | } |
| 306 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 307 | void SyncSystemResources::set_platform(const std::string& platform) { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 308 | platform_ = platform; |
| 309 | } |
| 310 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 311 | std::string SyncSystemResources::platform() const { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 312 | return platform_; |
| 313 | } |
| 314 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 315 | SyncLogger* SyncSystemResources::logger() { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 316 | return logger_.get(); |
| 317 | } |
| 318 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 319 | SyncStorage* SyncSystemResources::storage() { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 320 | return storage_.get(); |
| 321 | } |
| 322 | |
[email protected] | 28935deb | 2013-12-06 12:45:18 | [diff] [blame] | 323 | SyncNetworkChannel* SyncSystemResources::network() { |
| 324 | return sync_network_channel_; |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 325 | } |
| 326 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 327 | SyncInvalidationScheduler* SyncSystemResources::internal_scheduler() { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 328 | return internal_scheduler_.get(); |
| 329 | } |
| 330 | |
[email protected] | 1f7893fa | 2012-09-06 03:06:13 | [diff] [blame] | 331 | SyncInvalidationScheduler* SyncSystemResources::listener_scheduler() { |
[email protected] | 1bfd03f | 2011-07-02 19:04:18 | [diff] [blame] | 332 | return listener_scheduler_.get(); |
| 333 | } |
| 334 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 335 | } // namespace syncer |