| 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 <cstddef> | 5 #include <cstddef> |
| 6 #include <cstdio> | 6 #include <cstdio> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 class MyTestURLRequestContext : public net::TestURLRequestContext { | 72 class MyTestURLRequestContext : public net::TestURLRequestContext { |
| 73 public: | 73 public: |
| 74 MyTestURLRequestContext() : TestURLRequestContext(true) { | 74 MyTestURLRequestContext() : TestURLRequestContext(true) { |
| 75 context_storage_.set_host_resolver( | 75 context_storage_.set_host_resolver( |
| 76 net::HostResolver::CreateDefaultResolver(NULL)); | 76 net::HostResolver::CreateDefaultResolver(NULL)); |
| 77 context_storage_.set_transport_security_state( | 77 context_storage_.set_transport_security_state( |
| 78 new net::TransportSecurityState()); | 78 new net::TransportSecurityState()); |
| 79 Init(); | 79 Init(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 virtual ~MyTestURLRequestContext() {} | 82 ~MyTestURLRequestContext() override {} |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 class MyTestURLRequestContextGetter : public net::TestURLRequestContextGetter { | 85 class MyTestURLRequestContextGetter : public net::TestURLRequestContextGetter { |
| 86 public: | 86 public: |
| 87 explicit MyTestURLRequestContextGetter( | 87 explicit MyTestURLRequestContextGetter( |
| 88 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 88 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
| 89 : TestURLRequestContextGetter(io_task_runner) {} | 89 : TestURLRequestContextGetter(io_task_runner) {} |
| 90 | 90 |
| 91 virtual net::TestURLRequestContext* GetURLRequestContext() override { | 91 net::TestURLRequestContext* GetURLRequestContext() override { |
| 92 // Construct |context_| lazily so it gets constructed on the right | 92 // Construct |context_| lazily so it gets constructed on the right |
| 93 // thread (the IO thread). | 93 // thread (the IO thread). |
| 94 if (!context_) | 94 if (!context_) |
| 95 context_.reset(new MyTestURLRequestContext()); | 95 context_.reset(new MyTestURLRequestContext()); |
| 96 return context_.get(); | 96 return context_.get(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 virtual ~MyTestURLRequestContextGetter() {} | 100 ~MyTestURLRequestContextGetter() override {} |
| 101 | 101 |
| 102 scoped_ptr<MyTestURLRequestContext> context_; | 102 scoped_ptr<MyTestURLRequestContext> context_; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 // TODO(akalin): Use system encryptor once it's moved to sync/. | 105 // TODO(akalin): Use system encryptor once it's moved to sync/. |
| 106 class NullEncryptor : public Encryptor { | 106 class NullEncryptor : public Encryptor { |
| 107 public: | 107 public: |
| 108 virtual ~NullEncryptor() {} | 108 ~NullEncryptor() override {} |
| 109 | 109 |
| 110 virtual bool EncryptString(const std::string& plaintext, | 110 bool EncryptString(const std::string& plaintext, |
| 111 std::string* ciphertext) override { | 111 std::string* ciphertext) override { |
| 112 *ciphertext = plaintext; | 112 *ciphertext = plaintext; |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 virtual bool DecryptString(const std::string& ciphertext, | 116 bool DecryptString(const std::string& ciphertext, |
| 117 std::string* plaintext) override { | 117 std::string* plaintext) override { |
| 118 *plaintext = ciphertext; | 118 *plaintext = ciphertext; |
| 119 return true; | 119 return true; |
| 120 } | 120 } |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 std::string ValueToString(const base::Value& value) { | 123 std::string ValueToString(const base::Value& value) { |
| 124 std::string str; | 124 std::string str; |
| 125 base::JSONWriter::Write(&value, &str); | 125 base::JSONWriter::Write(&value, &str); |
| 126 return str; | 126 return str; |
| 127 } | 127 } |
| 128 | 128 |
| 129 class LoggingChangeDelegate : public SyncManager::ChangeDelegate { | 129 class LoggingChangeDelegate : public SyncManager::ChangeDelegate { |
| 130 public: | 130 public: |
| 131 virtual ~LoggingChangeDelegate() {} | 131 ~LoggingChangeDelegate() override {} |
| 132 | 132 |
| 133 virtual void OnChangesApplied( | 133 void OnChangesApplied(ModelType model_type, |
| 134 ModelType model_type, | 134 int64 model_version, |
| 135 int64 model_version, | 135 const BaseTransaction* trans, |
| 136 const BaseTransaction* trans, | 136 const ImmutableChangeRecordList& changes) override { |
| 137 const ImmutableChangeRecordList& changes) override { | |
| 138 LOG(INFO) << "Changes applied for " | 137 LOG(INFO) << "Changes applied for " |
| 139 << ModelTypeToString(model_type); | 138 << ModelTypeToString(model_type); |
| 140 size_t i = 1; | 139 size_t i = 1; |
| 141 size_t change_count = changes.Get().size(); | 140 size_t change_count = changes.Get().size(); |
| 142 for (ChangeRecordList::const_iterator it = | 141 for (ChangeRecordList::const_iterator it = |
| 143 changes.Get().begin(); it != changes.Get().end(); ++it) { | 142 changes.Get().begin(); it != changes.Get().end(); ++it) { |
| 144 scoped_ptr<base::DictionaryValue> change_value(it->ToValue()); | 143 scoped_ptr<base::DictionaryValue> change_value(it->ToValue()); |
| 145 LOG(INFO) << "Change (" << i << "/" << change_count << "): " | 144 LOG(INFO) << "Change (" << i << "/" << change_count << "): " |
| 146 << ValueToString(*change_value); | 145 << ValueToString(*change_value); |
| 147 if (it->action != ChangeRecord::ACTION_DELETE) { | 146 if (it->action != ChangeRecord::ACTION_DELETE) { |
| 148 ReadNode node(trans); | 147 ReadNode node(trans); |
| 149 CHECK_EQ(node.InitByIdLookup(it->id), BaseNode::INIT_OK); | 148 CHECK_EQ(node.InitByIdLookup(it->id), BaseNode::INIT_OK); |
| 150 scoped_ptr<base::DictionaryValue> details(node.ToValue()); | 149 scoped_ptr<base::DictionaryValue> details(node.ToValue()); |
| 151 VLOG(1) << "Details: " << ValueToString(*details); | 150 VLOG(1) << "Details: " << ValueToString(*details); |
| 152 } | 151 } |
| 153 ++i; | 152 ++i; |
| 154 } | 153 } |
| 155 } | 154 } |
| 156 | 155 |
| 157 virtual void OnChangesComplete(ModelType model_type) override { | 156 void OnChangesComplete(ModelType model_type) override { |
| 158 LOG(INFO) << "Changes complete for " | 157 LOG(INFO) << "Changes complete for " |
| 159 << ModelTypeToString(model_type); | 158 << ModelTypeToString(model_type); |
| 160 } | 159 } |
| 161 }; | 160 }; |
| 162 | 161 |
| 163 class LoggingUnrecoverableErrorHandler | 162 class LoggingUnrecoverableErrorHandler |
| 164 : public UnrecoverableErrorHandler { | 163 : public UnrecoverableErrorHandler { |
| 165 public: | 164 public: |
| 166 virtual ~LoggingUnrecoverableErrorHandler() {} | 165 ~LoggingUnrecoverableErrorHandler() override {} |
| 167 | 166 |
| 168 virtual void OnUnrecoverableError(const tracked_objects::Location& from_here, | 167 void OnUnrecoverableError(const tracked_objects::Location& from_here, |
| 169 const std::string& message) override { | 168 const std::string& message) override { |
| 170 if (LOG_IS_ON(ERROR)) { | 169 if (LOG_IS_ON(ERROR)) { |
| 171 logging::LogMessage(from_here.file_name(), from_here.line_number(), | 170 logging::LogMessage(from_here.file_name(), from_here.line_number(), |
| 172 logging::LOG_ERROR).stream() | 171 logging::LOG_ERROR).stream() |
| 173 << message; | 172 << message; |
| 174 } | 173 } |
| 175 } | 174 } |
| 176 }; | 175 }; |
| 177 | 176 |
| 178 class LoggingJsEventHandler | 177 class LoggingJsEventHandler |
| 179 : public JsEventHandler, | 178 : public JsEventHandler, |
| 180 public base::SupportsWeakPtr<LoggingJsEventHandler> { | 179 public base::SupportsWeakPtr<LoggingJsEventHandler> { |
| 181 public: | 180 public: |
| 182 virtual ~LoggingJsEventHandler() {} | 181 ~LoggingJsEventHandler() override {} |
| 183 | 182 |
| 184 virtual void HandleJsEvent( | 183 void HandleJsEvent(const std::string& name, |
| 185 const std::string& name, | 184 const JsEventDetails& details) override { |
| 186 const JsEventDetails& details) override { | |
| 187 VLOG(1) << name << ": " << details.ToString(); | 185 VLOG(1) << name << ": " << details.ToString(); |
| 188 } | 186 } |
| 189 }; | 187 }; |
| 190 | 188 |
| 191 class InvalidationAdapter : public syncer::InvalidationInterface { | 189 class InvalidationAdapter : public syncer::InvalidationInterface { |
| 192 public: | 190 public: |
| 193 explicit InvalidationAdapter(const syncer::Invalidation& invalidation) | 191 explicit InvalidationAdapter(const syncer::Invalidation& invalidation) |
| 194 : invalidation_(invalidation) {} | 192 : invalidation_(invalidation) {} |
| 195 virtual ~InvalidationAdapter() {} | 193 ~InvalidationAdapter() override {} |
| 196 | 194 |
| 197 virtual bool IsUnknownVersion() const override { | 195 bool IsUnknownVersion() const override { |
| 198 return invalidation_.is_unknown_version(); | 196 return invalidation_.is_unknown_version(); |
| 199 } | 197 } |
| 200 | 198 |
| 201 virtual const std::string& GetPayload() const override { | 199 const std::string& GetPayload() const override { |
| 202 return invalidation_.payload(); | 200 return invalidation_.payload(); |
| 203 } | 201 } |
| 204 | 202 |
| 205 virtual int64 GetVersion() const override { | 203 int64 GetVersion() const override { return invalidation_.version(); } |
| 206 return invalidation_.version(); | |
| 207 } | |
| 208 | 204 |
| 209 virtual void Acknowledge() override { | 205 void Acknowledge() override { invalidation_.Acknowledge(); } |
| 210 invalidation_.Acknowledge(); | |
| 211 } | |
| 212 | 206 |
| 213 virtual void Drop() override { | 207 void Drop() override { invalidation_.Drop(); } |
| 214 invalidation_.Drop(); | |
| 215 } | |
| 216 | 208 |
| 217 private: | 209 private: |
| 218 syncer::Invalidation invalidation_; | 210 syncer::Invalidation invalidation_; |
| 219 }; | 211 }; |
| 220 | 212 |
| 221 class InvalidatorShim : public InvalidationHandler { | 213 class InvalidatorShim : public InvalidationHandler { |
| 222 public: | 214 public: |
| 223 explicit InvalidatorShim(SyncManager* sync_manager) | 215 explicit InvalidatorShim(SyncManager* sync_manager) |
| 224 : sync_manager_(sync_manager) {} | 216 : sync_manager_(sync_manager) {} |
| 225 | 217 |
| 226 virtual void OnInvalidatorStateChange(InvalidatorState state) override { | 218 void OnInvalidatorStateChange(InvalidatorState state) override { |
| 227 sync_manager_->SetInvalidatorEnabled(state == INVALIDATIONS_ENABLED); | 219 sync_manager_->SetInvalidatorEnabled(state == INVALIDATIONS_ENABLED); |
| 228 } | 220 } |
| 229 | 221 |
| 230 virtual void OnIncomingInvalidation( | 222 void OnIncomingInvalidation( |
| 231 const ObjectIdInvalidationMap& invalidation_map) override { | 223 const ObjectIdInvalidationMap& invalidation_map) override { |
| 232 syncer::ObjectIdSet ids = invalidation_map.GetObjectIds(); | 224 syncer::ObjectIdSet ids = invalidation_map.GetObjectIds(); |
| 233 for (syncer::ObjectIdSet::const_iterator ids_it = ids.begin(); | 225 for (syncer::ObjectIdSet::const_iterator ids_it = ids.begin(); |
| 234 ids_it != ids.end(); | 226 ids_it != ids.end(); |
| 235 ++ids_it) { | 227 ++ids_it) { |
| 236 syncer::ModelType type; | 228 syncer::ModelType type; |
| 237 if (!NotificationTypeToRealModelType(ids_it->name(), &type)) { | 229 if (!NotificationTypeToRealModelType(ids_it->name(), &type)) { |
| 238 DLOG(WARNING) << "Notification has invalid id: " | 230 DLOG(WARNING) << "Notification has invalid id: " |
| 239 << syncer::ObjectIdToString(*ids_it); | 231 << syncer::ObjectIdToString(*ids_it); |
| 240 } else { | 232 } else { |
| 241 syncer::SingleObjectInvalidationSet invalidation_set = | 233 syncer::SingleObjectInvalidationSet invalidation_set = |
| 242 invalidation_map.ForObject(*ids_it); | 234 invalidation_map.ForObject(*ids_it); |
| 243 for (syncer::SingleObjectInvalidationSet::const_iterator inv_it = | 235 for (syncer::SingleObjectInvalidationSet::const_iterator inv_it = |
| 244 invalidation_set.begin(); | 236 invalidation_set.begin(); |
| 245 inv_it != invalidation_set.end(); | 237 inv_it != invalidation_set.end(); |
| 246 ++inv_it) { | 238 ++inv_it) { |
| 247 scoped_ptr<syncer::InvalidationInterface> inv_adapter( | 239 scoped_ptr<syncer::InvalidationInterface> inv_adapter( |
| 248 new InvalidationAdapter(*inv_it)); | 240 new InvalidationAdapter(*inv_it)); |
| 249 sync_manager_->OnIncomingInvalidation(type, inv_adapter.Pass()); | 241 sync_manager_->OnIncomingInvalidation(type, inv_adapter.Pass()); |
| 250 } | 242 } |
| 251 } | 243 } |
| 252 } | 244 } |
| 253 } | 245 } |
| 254 | 246 |
| 255 virtual std::string GetOwnerName() const override { | 247 std::string GetOwnerName() const override { return "InvalidatorShim"; } |
| 256 return "InvalidatorShim"; | |
| 257 } | |
| 258 | 248 |
| 259 private: | 249 private: |
| 260 SyncManager* sync_manager_; | 250 SyncManager* sync_manager_; |
| 261 }; | 251 }; |
| 262 | 252 |
| 263 void LogUnrecoverableErrorContext() { | 253 void LogUnrecoverableErrorContext() { |
| 264 base::debug::StackTrace().Print(); | 254 base::debug::StackTrace().Print(); |
| 265 } | 255 } |
| 266 | 256 |
| 267 notifier::NotifierOptions ParseNotifierOptions( | 257 notifier::NotifierOptions ParseNotifierOptions( |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 io_thread.Stop(); | 454 io_thread.Stop(); |
| 465 return 0; | 455 return 0; |
| 466 } | 456 } |
| 467 | 457 |
| 468 } // namespace | 458 } // namespace |
| 469 } // namespace syncer | 459 } // namespace syncer |
| 470 | 460 |
| 471 int main(int argc, char* argv[]) { | 461 int main(int argc, char* argv[]) { |
| 472 return syncer::SyncClientMain(argc, argv); | 462 return syncer::SyncClientMain(argc, argv); |
| 473 } | 463 } |
| OLD | NEW |