Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: sync/tools/sync_client.cc

Issue 322333004: sync: Inject sync/'s dependency on invalidations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/test/trackable_mock_invalidation.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 24 matching lines...) Expand all
35 #include "sync/internal_api/public/http_bridge.h" 35 #include "sync/internal_api/public/http_bridge.h"
36 #include "sync/internal_api/public/internal_components_factory_impl.h" 36 #include "sync/internal_api/public/internal_components_factory_impl.h"
37 #include "sync/internal_api/public/read_node.h" 37 #include "sync/internal_api/public/read_node.h"
38 #include "sync/internal_api/public/sync_manager.h" 38 #include "sync/internal_api/public/sync_manager.h"
39 #include "sync/internal_api/public/sync_manager_factory.h" 39 #include "sync/internal_api/public/sync_manager_factory.h"
40 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" 40 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h"
41 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" 41 #include "sync/internal_api/public/util/unrecoverable_error_handler.h"
42 #include "sync/internal_api/public/util/weak_handle.h" 42 #include "sync/internal_api/public/util/weak_handle.h"
43 #include "sync/js/js_event_details.h" 43 #include "sync/js/js_event_details.h"
44 #include "sync/js/js_event_handler.h" 44 #include "sync/js/js_event_handler.h"
45 #include "sync/notifier/object_id_invalidation_map.h"
45 #include "sync/test/fake_encryptor.h" 46 #include "sync/test/fake_encryptor.h"
46 #include "sync/tools/null_invalidation_state_tracker.h" 47 #include "sync/tools/null_invalidation_state_tracker.h"
47 48
48 #if defined(OS_MACOSX) 49 #if defined(OS_MACOSX)
49 #include "base/mac/scoped_nsautorelease_pool.h" 50 #include "base/mac/scoped_nsautorelease_pool.h"
50 #endif 51 #endif
51 52
52 // This is a simple utility that initializes a sync client and 53 // This is a simple utility that initializes a sync client and
53 // prints out any events. 54 // prints out any events.
54 55
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 public: 178 public:
178 virtual ~LoggingJsEventHandler() {} 179 virtual ~LoggingJsEventHandler() {}
179 180
180 virtual void HandleJsEvent( 181 virtual void HandleJsEvent(
181 const std::string& name, 182 const std::string& name,
182 const JsEventDetails& details) OVERRIDE { 183 const JsEventDetails& details) OVERRIDE {
183 VLOG(1) << name << ": " << details.ToString(); 184 VLOG(1) << name << ": " << details.ToString();
184 } 185 }
185 }; 186 };
186 187
188 class InvalidationAdapter : public syncer::InvalidationInterface {
189 public:
190 explicit InvalidationAdapter(const syncer::Invalidation& invalidation)
191 : invalidation_(invalidation) {}
192 virtual ~InvalidationAdapter() {}
193
194 virtual bool IsUnknownVersion() const OVERRIDE {
195 return invalidation_.is_unknown_version();
196 }
197
198 virtual const std::string& GetPayload() const OVERRIDE {
199 return invalidation_.payload();
200 }
201
202 virtual int64 GetVersion() const OVERRIDE {
203 return invalidation_.version();
204 }
205
206 virtual void Acknowledge() OVERRIDE {
207 invalidation_.Acknowledge();
208 }
209
210 virtual void Drop() OVERRIDE {
211 invalidation_.Drop();
212 }
213
214 private:
215 syncer::Invalidation invalidation_;
216 };
217
218 class InvalidatorShim : public InvalidationHandler {
219 public:
220 explicit InvalidatorShim(SyncManager* sync_manager)
221 : sync_manager_(sync_manager) {}
222
223 virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE {
224 sync_manager_->OnInvalidatorStateChange(state);
225 }
226
227 virtual void OnIncomingInvalidation(
228 const ObjectIdInvalidationMap& invalidation_map) OVERRIDE {
229 syncer::ObjectIdSet ids = invalidation_map.GetObjectIds();
230 for (syncer::ObjectIdSet::const_iterator ids_it = ids.begin();
231 ids_it != ids.end();
232 ++ids_it) {
233 syncer::ModelType type;
234 if (!NotificationTypeToRealModelType(ids_it->name(), &type)) {
235 DLOG(WARNING) << "Notification has invalid id: "
236 << syncer::ObjectIdToString(*ids_it);
237 } else {
238 syncer::SingleObjectInvalidationSet invalidation_set =
239 invalidation_map.ForObject(*ids_it);
240 for (syncer::SingleObjectInvalidationSet::const_iterator inv_it =
241 invalidation_set.begin();
242 inv_it != invalidation_set.end();
243 ++inv_it) {
244 scoped_ptr<syncer::InvalidationInterface> inv_adapter(
245 new InvalidationAdapter(*inv_it));
246 sync_manager_->OnIncomingInvalidation(type, inv_adapter.Pass());
247 }
248 }
249 }
250 }
251
252 virtual std::string GetOwnerName() const OVERRIDE {
253 return "InvalidatorShim";
254 }
255
256 private:
257 SyncManager* sync_manager_;
258 };
259
187 void LogUnrecoverableErrorContext() { 260 void LogUnrecoverableErrorContext() {
188 base::debug::StackTrace().Print(); 261 base::debug::StackTrace().Print();
189 } 262 }
190 263
191 notifier::NotifierOptions ParseNotifierOptions( 264 notifier::NotifierOptions ParseNotifierOptions(
192 const CommandLine& command_line, 265 const CommandLine& command_line,
193 const scoped_refptr<net::URLRequestContextGetter>& 266 const scoped_refptr<net::URLRequestContextGetter>&
194 request_context_getter) { 267 request_context_getter) {
195 notifier::NotifierOptions notifier_options; 268 notifier::NotifierOptions notifier_options;
196 notifier_options.request_context_getter = request_context_getter; 269 notifier_options.request_context_getter = request_context_getter;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 kRestoredKeystoreKeyForBootstrapping, 446 kRestoredKeystoreKeyForBootstrapping,
374 new InternalComponentsFactoryImpl(factory_switches), 447 new InternalComponentsFactoryImpl(factory_switches),
375 &null_encryptor, 448 &null_encryptor,
376 scoped_ptr<UnrecoverableErrorHandler>( 449 scoped_ptr<UnrecoverableErrorHandler>(
377 new LoggingUnrecoverableErrorHandler).Pass(), 450 new LoggingUnrecoverableErrorHandler).Pass(),
378 &LogUnrecoverableErrorContext, 451 &LogUnrecoverableErrorContext,
379 &scm_cancelation_signal); 452 &scm_cancelation_signal);
380 // TODO(akalin): Avoid passing in model parameters multiple times by 453 // TODO(akalin): Avoid passing in model parameters multiple times by
381 // organizing handling of model types. 454 // organizing handling of model types.
382 invalidator->UpdateCredentials(credentials.email, credentials.sync_token); 455 invalidator->UpdateCredentials(credentials.email, credentials.sync_token);
383 invalidator->RegisterHandler(sync_manager.get()); 456 scoped_ptr<InvalidatorShim> shim(new InvalidatorShim(sync_manager.get()));
457 invalidator->RegisterHandler(shim.get());
384 invalidator->UpdateRegisteredIds( 458 invalidator->UpdateRegisteredIds(
385 sync_manager.get(), ModelTypeSetToObjectIdSet(model_types)); 459 shim.get(), ModelTypeSetToObjectIdSet(model_types));
386 sync_manager->StartSyncingNormally(routing_info); 460 sync_manager->StartSyncingNormally(routing_info);
387 461
388 sync_loop.Run(); 462 sync_loop.Run();
389 463
390 io_thread.Stop(); 464 io_thread.Stop();
391 return 0; 465 return 0;
392 } 466 }
393 467
394 } // namespace 468 } // namespace
395 } // namespace syncer 469 } // namespace syncer
396 470
397 int main(int argc, char* argv[]) { 471 int main(int argc, char* argv[]) {
398 return syncer::SyncClientMain(argc, argv); 472 return syncer::SyncClientMain(argc, argv);
399 } 473 }
OLDNEW
« no previous file with comments | « sync/test/trackable_mock_invalidation.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698