| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/notifier/chrome_system_resources.h" | 5 #include "sync/notifier/chrome_system_resources.h" |
| 6 | 6 |
| 7 #include <cstdlib> | 7 #include <cstdlib> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "google/cacheinvalidation/include/types.h" | 17 #include "google/cacheinvalidation/include/types.h" |
| 18 #include "sync/notifier/cache_invalidation_packet_handler.h" | 18 #include "jingle/notifier/listener/push_client.h" |
| 19 #include "sync/notifier/invalidation_util.h" | 19 #include "sync/notifier/invalidation_util.h" |
| 20 | 20 |
| 21 namespace sync_notifier { | 21 namespace sync_notifier { |
| 22 | 22 |
| 23 ChromeLogger::ChromeLogger() {} | 23 ChromeLogger::ChromeLogger() {} |
| 24 ChromeLogger::~ChromeLogger() {} | 24 ChromeLogger::~ChromeLogger() {} |
| 25 | 25 |
| 26 void ChromeLogger::Log(LogLevel level, const char* file, int line, | 26 void ChromeLogger::Log(LogLevel level, const char* file, int line, |
| 27 const char* format, ...) { | 27 const char* format, ...) { |
| 28 logging::LogSeverity log_severity = -2; // VLOG(2) | 28 logging::LogSeverity log_severity = -2; // VLOG(2) |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 185 } |
| 186 | 186 |
| 187 void ChromeStorage::RunAndDeleteReadKeyCallback( | 187 void ChromeStorage::RunAndDeleteReadKeyCallback( |
| 188 invalidation::ReadKeyCallback* callback, const std::string& value) { | 188 invalidation::ReadKeyCallback* callback, const std::string& value) { |
| 189 callback->Run(std::make_pair( | 189 callback->Run(std::make_pair( |
| 190 invalidation::Status(invalidation::Status::SUCCESS, ""), | 190 invalidation::Status(invalidation::Status::SUCCESS, ""), |
| 191 value)); | 191 value)); |
| 192 delete callback; | 192 delete callback; |
| 193 } | 193 } |
| 194 | 194 |
| 195 ChromeNetwork::ChromeNetwork() | 195 ChromeSystemResources::ChromeSystemResources( |
| 196 : packet_handler_(NULL), | 196 scoped_ptr<notifier::PushClient> push_client, |
| 197 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {} | 197 StateWriter* state_writer) |
| 198 | |
| 199 ChromeNetwork::~ChromeNetwork() { | |
| 200 STLDeleteElements(&network_status_receivers_); | |
| 201 } | |
| 202 | |
| 203 void ChromeNetwork::SendMessage(const std::string& outgoing_message) { | |
| 204 if (packet_handler_) { | |
| 205 packet_handler_->SendMessage(outgoing_message); | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 void ChromeNetwork::SetMessageReceiver( | |
| 210 invalidation::MessageCallback* incoming_receiver) { | |
| 211 incoming_receiver_.reset(incoming_receiver); | |
| 212 } | |
| 213 | |
| 214 void ChromeNetwork::AddNetworkStatusReceiver( | |
| 215 invalidation::NetworkStatusCallback* network_status_receiver) { | |
| 216 network_status_receivers_.push_back(network_status_receiver); | |
| 217 } | |
| 218 | |
| 219 void ChromeNetwork::SetSystemResources( | |
| 220 invalidation::SystemResources* resources) { | |
| 221 // Do nothing. | |
| 222 } | |
| 223 | |
| 224 void ChromeNetwork::UpdatePacketHandler( | |
| 225 CacheInvalidationPacketHandler* packet_handler) { | |
| 226 packet_handler_ = packet_handler; | |
| 227 if (packet_handler_ != NULL) { | |
| 228 packet_handler_->SetMessageReceiver( | |
| 229 new invalidation::MessageCallback( | |
| 230 base::Bind(&ChromeNetwork::HandleInboundMessage, | |
| 231 weak_factory_.GetWeakPtr()))); | |
| 232 } | |
| 233 packet_handler_->SendSubscriptionRequest(); | |
| 234 } | |
| 235 | |
| 236 void ChromeNetwork::HandleInboundMessage(const std::string& incoming_message) { | |
| 237 if (incoming_receiver_.get()) { | |
| 238 incoming_receiver_->Run(incoming_message); | |
| 239 } | |
| 240 } | |
| 241 | |
| 242 ChromeSystemResources::ChromeSystemResources(StateWriter* state_writer) | |
| 243 : is_started_(false), | 198 : is_started_(false), |
| 244 logger_(new ChromeLogger()), | 199 logger_(new ChromeLogger()), |
| 245 internal_scheduler_(new ChromeScheduler()), | 200 internal_scheduler_(new ChromeScheduler()), |
| 246 listener_scheduler_(new ChromeScheduler()), | 201 listener_scheduler_(new ChromeScheduler()), |
| 247 storage_(new ChromeStorage(state_writer, internal_scheduler_.get())), | 202 storage_(new ChromeStorage(state_writer, internal_scheduler_.get())), |
| 248 network_(new ChromeNetwork()) { | 203 push_client_channel_(push_client.Pass()) { |
| 249 } | 204 } |
| 250 | 205 |
| 251 ChromeSystemResources::~ChromeSystemResources() { | 206 ChromeSystemResources::~ChromeSystemResources() { |
| 252 Stop(); | 207 Stop(); |
| 253 } | 208 } |
| 254 | 209 |
| 255 void ChromeSystemResources::Start() { | 210 void ChromeSystemResources::Start() { |
| 256 internal_scheduler_->Start(); | 211 internal_scheduler_->Start(); |
| 257 listener_scheduler_->Start(); | 212 listener_scheduler_->Start(); |
| 258 is_started_ = true; | 213 is_started_ = true; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 276 } | 231 } |
| 277 | 232 |
| 278 ChromeLogger* ChromeSystemResources::logger() { | 233 ChromeLogger* ChromeSystemResources::logger() { |
| 279 return logger_.get(); | 234 return logger_.get(); |
| 280 } | 235 } |
| 281 | 236 |
| 282 ChromeStorage* ChromeSystemResources::storage() { | 237 ChromeStorage* ChromeSystemResources::storage() { |
| 283 return storage_.get(); | 238 return storage_.get(); |
| 284 } | 239 } |
| 285 | 240 |
| 286 ChromeNetwork* ChromeSystemResources::network() { | 241 PushClientChannel* ChromeSystemResources::network() { |
| 287 return network_.get(); | 242 return &push_client_channel_; |
| 288 } | 243 } |
| 289 | 244 |
| 290 ChromeScheduler* ChromeSystemResources::internal_scheduler() { | 245 ChromeScheduler* ChromeSystemResources::internal_scheduler() { |
| 291 return internal_scheduler_.get(); | 246 return internal_scheduler_.get(); |
| 292 } | 247 } |
| 293 | 248 |
| 294 ChromeScheduler* ChromeSystemResources::listener_scheduler() { | 249 ChromeScheduler* ChromeSystemResources::listener_scheduler() { |
| 295 return listener_scheduler_.get(); | 250 return listener_scheduler_.get(); |
| 296 } | 251 } |
| 297 | 252 |
| 298 } // namespace sync_notifier | 253 } // namespace sync_notifier |
| OLD | NEW |