| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <cstdio> | 8 #include <cstdio> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 public base::SupportsWeakPtr<LoggingJsEventHandler> { | 183 public base::SupportsWeakPtr<LoggingJsEventHandler> { |
| 184 public: | 184 public: |
| 185 ~LoggingJsEventHandler() override {} | 185 ~LoggingJsEventHandler() override {} |
| 186 | 186 |
| 187 void HandleJsEvent(const std::string& name, | 187 void HandleJsEvent(const std::string& name, |
| 188 const JsEventDetails& details) override { | 188 const JsEventDetails& details) override { |
| 189 VLOG(1) << name << ": " << details.ToString(); | 189 VLOG(1) << name << ": " << details.ToString(); |
| 190 } | 190 } |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 class InvalidationAdapter : public syncer::InvalidationInterface { | 193 class InvalidationAdapter : public InvalidationInterface { |
| 194 public: | 194 public: |
| 195 explicit InvalidationAdapter(const syncer::Invalidation& invalidation) | 195 explicit InvalidationAdapter(const Invalidation& invalidation) |
| 196 : invalidation_(invalidation) {} | 196 : invalidation_(invalidation) {} |
| 197 ~InvalidationAdapter() override {} | 197 ~InvalidationAdapter() override {} |
| 198 | 198 |
| 199 bool IsUnknownVersion() const override { | 199 bool IsUnknownVersion() const override { |
| 200 return invalidation_.is_unknown_version(); | 200 return invalidation_.is_unknown_version(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 const std::string& GetPayload() const override { | 203 const std::string& GetPayload() const override { |
| 204 return invalidation_.payload(); | 204 return invalidation_.payload(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 int64_t GetVersion() const override { return invalidation_.version(); } | 207 int64_t GetVersion() const override { return invalidation_.version(); } |
| 208 | 208 |
| 209 void Acknowledge() override { invalidation_.Acknowledge(); } | 209 void Acknowledge() override { invalidation_.Acknowledge(); } |
| 210 | 210 |
| 211 void Drop() override { invalidation_.Drop(); } | 211 void Drop() override { invalidation_.Drop(); } |
| 212 | 212 |
| 213 private: | 213 private: |
| 214 syncer::Invalidation invalidation_; | 214 Invalidation invalidation_; |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 class InvalidatorShim : public InvalidationHandler { | 217 class InvalidatorShim : public InvalidationHandler { |
| 218 public: | 218 public: |
| 219 explicit InvalidatorShim(SyncManager* sync_manager) | 219 explicit InvalidatorShim(SyncManager* sync_manager) |
| 220 : sync_manager_(sync_manager) {} | 220 : sync_manager_(sync_manager) {} |
| 221 | 221 |
| 222 void OnInvalidatorStateChange(InvalidatorState state) override { | 222 void OnInvalidatorStateChange(InvalidatorState state) override { |
| 223 sync_manager_->SetInvalidatorEnabled(state == INVALIDATIONS_ENABLED); | 223 sync_manager_->SetInvalidatorEnabled(state == INVALIDATIONS_ENABLED); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void OnIncomingInvalidation( | 226 void OnIncomingInvalidation( |
| 227 const ObjectIdInvalidationMap& invalidation_map) override { | 227 const ObjectIdInvalidationMap& invalidation_map) override { |
| 228 syncer::ObjectIdSet ids = invalidation_map.GetObjectIds(); | 228 ObjectIdSet ids = invalidation_map.GetObjectIds(); |
| 229 for (syncer::ObjectIdSet::const_iterator ids_it = ids.begin(); | 229 for (ObjectIdSet::const_iterator ids_it = ids.begin(); ids_it != ids.end(); |
| 230 ids_it != ids.end(); ++ids_it) { | 230 ++ids_it) { |
| 231 syncer::ModelType type; | 231 ModelType type; |
| 232 if (!NotificationTypeToRealModelType(ids_it->name(), &type)) { | 232 if (!NotificationTypeToRealModelType(ids_it->name(), &type)) { |
| 233 DLOG(WARNING) << "Notification has invalid id: " | 233 DLOG(WARNING) << "Notification has invalid id: " |
| 234 << syncer::ObjectIdToString(*ids_it); | 234 << ObjectIdToString(*ids_it); |
| 235 } else { | 235 } else { |
| 236 syncer::SingleObjectInvalidationSet invalidation_set = | 236 SingleObjectInvalidationSet invalidation_set = |
| 237 invalidation_map.ForObject(*ids_it); | 237 invalidation_map.ForObject(*ids_it); |
| 238 for (syncer::SingleObjectInvalidationSet::const_iterator inv_it = | 238 for (SingleObjectInvalidationSet::const_iterator inv_it = |
| 239 invalidation_set.begin(); | 239 invalidation_set.begin(); |
| 240 inv_it != invalidation_set.end(); ++inv_it) { | 240 inv_it != invalidation_set.end(); ++inv_it) { |
| 241 std::unique_ptr<syncer::InvalidationInterface> inv_adapter( | 241 std::unique_ptr<InvalidationInterface> inv_adapter( |
| 242 new InvalidationAdapter(*inv_it)); | 242 new InvalidationAdapter(*inv_it)); |
| 243 sync_manager_->OnIncomingInvalidation(type, std::move(inv_adapter)); | 243 sync_manager_->OnIncomingInvalidation(type, std::move(inv_adapter)); |
| 244 } | 244 } |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 | 248 |
| 249 std::string GetOwnerName() const override { return "InvalidatorShim"; } | 249 std::string GetOwnerName() const override { return "InvalidatorShim"; } |
| 250 | 250 |
| 251 private: | 251 private: |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 credentials.account_id = command_line.GetSwitchValueASCII(kEmailSwitch); | 310 credentials.account_id = command_line.GetSwitchValueASCII(kEmailSwitch); |
| 311 credentials.email = command_line.GetSwitchValueASCII(kEmailSwitch); | 311 credentials.email = command_line.GetSwitchValueASCII(kEmailSwitch); |
| 312 credentials.sync_token = command_line.GetSwitchValueASCII(kTokenSwitch); | 312 credentials.sync_token = command_line.GetSwitchValueASCII(kTokenSwitch); |
| 313 // TODO(akalin): Write a wrapper script that gets a token for an | 313 // TODO(akalin): Write a wrapper script that gets a token for an |
| 314 // email and password and passes that in to this utility. | 314 // email and password and passes that in to this utility. |
| 315 if (credentials.email.empty() || credentials.sync_token.empty()) { | 315 if (credentials.email.empty() || credentials.sync_token.empty()) { |
| 316 std::printf( | 316 std::printf( |
| 317 "Usage: %s --%s=foo@bar.com --%s=token\n" | 317 "Usage: %s --%s=foo@bar.com --%s=token\n" |
| 318 "[--%s=host:port] [--%s] [--%s]\n" | 318 "[--%s=host:port] [--%s] [--%s]\n" |
| 319 "Run chrome and set a breakpoint on\n" | 319 "Run chrome and set a breakpoint on\n" |
| 320 "syncer::SyncManagerImpl::UpdateCredentials() " | 320 "SyncManagerImpl::UpdateCredentials() " |
| 321 "after logging into\n" | 321 "after logging into\n" |
| 322 "sync to get the token to pass into this utility.\n", | 322 "sync to get the token to pass into this utility.\n", |
| 323 argv[0], kEmailSwitch, kTokenSwitch, kXmppHostPortSwitch, | 323 argv[0], kEmailSwitch, kTokenSwitch, kXmppHostPortSwitch, |
| 324 kXmppTrySslTcpFirstSwitch, kXmppAllowInsecureConnectionSwitch); | 324 kXmppTrySslTcpFirstSwitch, kXmppAllowInsecureConnectionSwitch); |
| 325 return -1; | 325 return -1; |
| 326 } | 326 } |
| 327 | 327 |
| 328 // Set up objects that monitor the network. | 328 // Set up objects that monitor the network. |
| 329 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier( | 329 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier( |
| 330 net::NetworkChangeNotifier::Create()); | 330 net::NetworkChangeNotifier::Create()); |
| 331 | 331 |
| 332 // Set up sync notifier factory. | 332 // Set up sync notifier factory. |
| 333 const scoped_refptr<MyTestURLRequestContextGetter> context_getter = | 333 const scoped_refptr<MyTestURLRequestContextGetter> context_getter = |
| 334 new MyTestURLRequestContextGetter(io_thread.task_runner()); | 334 new MyTestURLRequestContextGetter(io_thread.task_runner()); |
| 335 const notifier::NotifierOptions& notifier_options = | 335 const notifier::NotifierOptions& notifier_options = |
| 336 ParseNotifierOptions(command_line, context_getter); | 336 ParseNotifierOptions(command_line, context_getter); |
| 337 syncer::NetworkChannelCreator network_channel_creator = | 337 NetworkChannelCreator network_channel_creator = |
| 338 syncer::NonBlockingInvalidator::MakePushClientChannelCreator( | 338 NonBlockingInvalidator::MakePushClientChannelCreator(notifier_options); |
| 339 notifier_options); | |
| 340 const char kClientInfo[] = "standalone_sync_client"; | 339 const char kClientInfo[] = "standalone_sync_client"; |
| 341 std::string invalidator_id = base::RandBytesAsString(8); | 340 std::string invalidator_id = base::RandBytesAsString(8); |
| 342 NullInvalidationStateTracker null_invalidation_state_tracker; | 341 NullInvalidationStateTracker null_invalidation_state_tracker; |
| 343 std::unique_ptr<Invalidator> invalidator(new NonBlockingInvalidator( | 342 std::unique_ptr<Invalidator> invalidator(new NonBlockingInvalidator( |
| 344 network_channel_creator, invalidator_id, | 343 network_channel_creator, invalidator_id, |
| 345 null_invalidation_state_tracker.GetSavedInvalidations(), | 344 null_invalidation_state_tracker.GetSavedInvalidations(), |
| 346 null_invalidation_state_tracker.GetBootstrapData(), | 345 null_invalidation_state_tracker.GetBootstrapData(), |
| 347 &null_invalidation_state_tracker, kClientInfo, | 346 &null_invalidation_state_tracker, kClientInfo, |
| 348 notifier_options.request_context_getter)); | 347 notifier_options.request_context_getter)); |
| 349 | 348 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 io_thread.Stop(); | 450 io_thread.Stop(); |
| 452 return 0; | 451 return 0; |
| 453 } | 452 } |
| 454 | 453 |
| 455 } // namespace | 454 } // namespace |
| 456 } // namespace syncer | 455 } // namespace syncer |
| 457 | 456 |
| 458 int main(int argc, char* argv[]) { | 457 int main(int argc, char* argv[]) { |
| 459 return syncer::SyncClientMain(argc, argv); | 458 return syncer::SyncClientMain(argc, argv); |
| 460 } | 459 } |
| OLD | NEW |