OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/sync/glue/sync_backend_host_core.h" | 5 #include "chrome/browser/sync/glue/sync_backend_host_core.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "chrome/browser/sync/glue/device_info.h" | 10 #include "chrome/browser/sync/glue/device_info.h" |
| 11 #include "chrome/browser/sync/glue/invalidation_wrapper.h" |
11 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 12 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
12 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 13 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
13 #include "chrome/common/chrome_version_info.h" | 14 #include "chrome/common/chrome_version_info.h" |
14 #include "sync/internal_api/public/events/protocol_event.h" | 15 #include "sync/internal_api/public/events/protocol_event.h" |
15 #include "sync/internal_api/public/http_post_provider_factory.h" | 16 #include "sync/internal_api/public/http_post_provider_factory.h" |
16 #include "sync/internal_api/public/internal_components_factory.h" | 17 #include "sync/internal_api/public/internal_components_factory.h" |
17 #include "sync/internal_api/public/sessions/commit_counters.h" | 18 #include "sync/internal_api/public/sessions/commit_counters.h" |
18 #include "sync/internal_api/public/sessions/status_counters.h" | 19 #include "sync/internal_api/public/sessions/status_counters.h" |
19 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 20 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
20 #include "sync/internal_api/public/sessions/update_counters.h" | 21 #include "sync/internal_api/public/sessions/update_counters.h" |
21 #include "sync/internal_api/public/sync_core_proxy.h" | 22 #include "sync/internal_api/public/sync_core_proxy.h" |
22 #include "sync/internal_api/public/sync_manager.h" | 23 #include "sync/internal_api/public/sync_manager.h" |
23 #include "sync/internal_api/public/sync_manager_factory.h" | 24 #include "sync/internal_api/public/sync_manager_factory.h" |
| 25 #include "sync/notifier/invalidation_util.h" |
| 26 #include "sync/notifier/object_id_invalidation_map.h" |
24 | 27 |
25 // Helper macros to log with the syncer thread name; useful when there | 28 // Helper macros to log with the syncer thread name; useful when there |
26 // are multiple syncers involved. | 29 // are multiple syncers involved. |
27 | 30 |
28 #define SLOG(severity) LOG(severity) << name_ << ": " | 31 #define SLOG(severity) LOG(severity) << name_ << ": " |
29 | 32 |
30 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " | 33 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " |
31 | 34 |
32 static const int kSaveChangesIntervalSeconds = 10; | 35 static const int kSaveChangesIntervalSeconds = 10; |
33 | 36 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 | 366 |
364 void SyncBackendHostCore::DoOnInvalidatorStateChange( | 367 void SyncBackendHostCore::DoOnInvalidatorStateChange( |
365 syncer::InvalidatorState state) { | 368 syncer::InvalidatorState state) { |
366 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 369 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
367 sync_manager_->OnInvalidatorStateChange(state); | 370 sync_manager_->OnInvalidatorStateChange(state); |
368 } | 371 } |
369 | 372 |
370 void SyncBackendHostCore::DoOnIncomingInvalidation( | 373 void SyncBackendHostCore::DoOnIncomingInvalidation( |
371 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 374 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
372 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 375 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
373 sync_manager_->OnIncomingInvalidation(invalidation_map); | 376 |
| 377 syncer::ObjectIdSet ids = invalidation_map.GetObjectIds(); |
| 378 for (syncer::ObjectIdSet::const_iterator ids_it = ids.begin(); |
| 379 ids_it != ids.end(); |
| 380 ++ids_it) { |
| 381 syncer::ModelType type; |
| 382 if (!NotificationTypeToRealModelType(ids_it->name(), &type)) { |
| 383 DLOG(WARNING) << "Notification has invalid id: " |
| 384 << syncer::ObjectIdToString(*ids_it); |
| 385 } else { |
| 386 syncer::SingleObjectInvalidationSet invalidation_set = |
| 387 invalidation_map.ForObject(*ids_it); |
| 388 for (syncer::SingleObjectInvalidationSet::const_iterator inv_it = |
| 389 invalidation_set.begin(); |
| 390 inv_it != invalidation_set.end(); |
| 391 ++inv_it) { |
| 392 scoped_ptr<syncer::InvalidationInterface> inv_wrapper( |
| 393 new InvalidationWrapper(*inv_it)); |
| 394 sync_manager_->OnIncomingInvalidation(type, inv_wrapper.Pass()); |
| 395 } |
| 396 } |
| 397 } |
374 } | 398 } |
375 | 399 |
376 void SyncBackendHostCore::DoInitialize( | 400 void SyncBackendHostCore::DoInitialize( |
377 scoped_ptr<DoInitializeOptions> options) { | 401 scoped_ptr<DoInitializeOptions> options) { |
378 DCHECK(!sync_loop_); | 402 DCHECK(!sync_loop_); |
379 sync_loop_ = options->sync_loop; | 403 sync_loop_ = options->sync_loop; |
380 DCHECK(sync_loop_); | 404 DCHECK(sync_loop_); |
381 | 405 |
382 // Finish initializing the HttpBridgeFactory. We do this here because | 406 // Finish initializing the HttpBridgeFactory. We do this here because |
383 // building the user agent may block on some platforms. | 407 // building the user agent may block on some platforms. |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 this, &SyncBackendHostCore::SaveChanges); | 743 this, &SyncBackendHostCore::SaveChanges); |
720 } | 744 } |
721 | 745 |
722 void SyncBackendHostCore::SaveChanges() { | 746 void SyncBackendHostCore::SaveChanges() { |
723 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 747 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
724 sync_manager_->SaveChanges(); | 748 sync_manager_->SaveChanges(); |
725 } | 749 } |
726 | 750 |
727 } // namespace browser_sync | 751 } // namespace browser_sync |
728 | 752 |
OLD | NEW |