| 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 "components/sync/sessions_impl/sync_session.h" | 5 #include "components/sync/engine_impl/cycle/sync_cycle.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "components/sync/base/model_type.h" | 11 #include "components/sync/base/model_type.h" |
| 12 #include "components/sync/engine/model_safe_worker.h" | 12 #include "components/sync/engine/model_safe_worker.h" |
| 13 #include "components/sync/syncable/directory.h" | 13 #include "components/sync/syncable/directory.h" |
| 14 | 14 |
| 15 namespace syncer { | 15 namespace syncer { |
| 16 namespace sessions { | |
| 17 | 16 |
| 18 // static | 17 // static |
| 19 SyncSession* SyncSession::Build(SyncSessionContext* context, | 18 SyncCycle* SyncCycle::Build(SyncCycleContext* context, Delegate* delegate) { |
| 20 Delegate* delegate) { | 19 return new SyncCycle(context, delegate); |
| 21 return new SyncSession(context, delegate); | |
| 22 } | 20 } |
| 23 | 21 |
| 24 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate) | 22 SyncCycle::SyncCycle(SyncCycleContext* context, Delegate* delegate) |
| 25 : context_(context), delegate_(delegate) { | 23 : context_(context), delegate_(delegate) { |
| 26 status_controller_.reset(new StatusController()); | 24 status_controller_.reset(new StatusController()); |
| 27 } | 25 } |
| 28 | 26 |
| 29 SyncSession::~SyncSession() {} | 27 SyncCycle::~SyncCycle() {} |
| 30 | 28 |
| 31 SyncSessionSnapshot SyncSession::TakeSnapshot() const { | 29 SyncCycleSnapshot SyncCycle::TakeSnapshot() const { |
| 32 return TakeSnapshotWithSource(sync_pb::GetUpdatesCallerInfo::UNKNOWN); | 30 return TakeSnapshotWithSource(sync_pb::GetUpdatesCallerInfo::UNKNOWN); |
| 33 } | 31 } |
| 34 | 32 |
| 35 SyncSessionSnapshot SyncSession::TakeSnapshotWithSource( | 33 SyncCycleSnapshot SyncCycle::TakeSnapshotWithSource( |
| 36 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source) | 34 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source) |
| 37 const { | 35 const { |
| 38 syncable::Directory* dir = context_->directory(); | 36 syncable::Directory* dir = context_->directory(); |
| 39 | 37 |
| 40 ProgressMarkerMap download_progress_markers; | 38 ProgressMarkerMap download_progress_markers; |
| 41 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 39 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 42 ModelType type(ModelTypeFromInt(i)); | 40 ModelType type(ModelTypeFromInt(i)); |
| 43 dir->GetDownloadProgressAsString(type, &download_progress_markers[type]); | 41 dir->GetDownloadProgressAsString(type, &download_progress_markers[type]); |
| 44 } | 42 } |
| 45 | 43 |
| 46 std::vector<int> num_entries_by_type(MODEL_TYPE_COUNT, 0); | 44 std::vector<int> num_entries_by_type(MODEL_TYPE_COUNT, 0); |
| 47 std::vector<int> num_to_delete_entries_by_type(MODEL_TYPE_COUNT, 0); | 45 std::vector<int> num_to_delete_entries_by_type(MODEL_TYPE_COUNT, 0); |
| 48 dir->CollectMetaHandleCounts(&num_entries_by_type, | 46 dir->CollectMetaHandleCounts(&num_entries_by_type, |
| 49 &num_to_delete_entries_by_type); | 47 &num_to_delete_entries_by_type); |
| 50 | 48 |
| 51 SyncSessionSnapshot snapshot( | 49 SyncCycleSnapshot snapshot( |
| 52 status_controller_->model_neutral_state(), download_progress_markers, | 50 status_controller_->model_neutral_state(), download_progress_markers, |
| 53 delegate_->IsCurrentlyThrottled(), | 51 delegate_->IsCurrentlyThrottled(), |
| 54 status_controller_->num_encryption_conflicts(), | 52 status_controller_->num_encryption_conflicts(), |
| 55 status_controller_->num_hierarchy_conflicts(), | 53 status_controller_->num_hierarchy_conflicts(), |
| 56 status_controller_->num_server_conflicts(), | 54 status_controller_->num_server_conflicts(), |
| 57 context_->notifications_enabled(), dir->GetEntriesCount(), | 55 context_->notifications_enabled(), dir->GetEntriesCount(), |
| 58 status_controller_->sync_start_time(), | 56 status_controller_->sync_start_time(), |
| 59 status_controller_->poll_finish_time(), num_entries_by_type, | 57 status_controller_->poll_finish_time(), num_entries_by_type, |
| 60 num_to_delete_entries_by_type, legacy_updates_source); | 58 num_to_delete_entries_by_type, legacy_updates_source); |
| 61 | 59 |
| 62 return snapshot; | 60 return snapshot; |
| 63 } | 61 } |
| 64 | 62 |
| 65 void SyncSession::SendSyncCycleEndEventNotification( | 63 void SyncCycle::SendSyncCycleEndEventNotification( |
| 66 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { | 64 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { |
| 67 SyncCycleEvent event(SyncCycleEvent::SYNC_CYCLE_ENDED); | 65 SyncCycleEvent event(SyncCycleEvent::SYNC_CYCLE_ENDED); |
| 68 event.snapshot = TakeSnapshotWithSource(source); | 66 event.snapshot = TakeSnapshotWithSource(source); |
| 69 | 67 |
| 70 DVLOG(1) << "Sending cycle end event with snapshot: " | 68 DVLOG(1) << "Sending cycle end event with snapshot: " |
| 71 << event.snapshot.ToString(); | 69 << event.snapshot.ToString(); |
| 72 FOR_EACH_OBSERVER(SyncEngineEventListener, *(context_->listeners()), | 70 FOR_EACH_OBSERVER(SyncEngineEventListener, *(context_->listeners()), |
| 73 OnSyncCycleEvent(event)); | 71 OnSyncCycleEvent(event)); |
| 74 } | 72 } |
| 75 | 73 |
| 76 void SyncSession::SendEventNotification(SyncCycleEvent::EventCause cause) { | 74 void SyncCycle::SendEventNotification(SyncCycleEvent::EventCause cause) { |
| 77 SyncCycleEvent event(cause); | 75 SyncCycleEvent event(cause); |
| 78 event.snapshot = TakeSnapshot(); | 76 event.snapshot = TakeSnapshot(); |
| 79 | 77 |
| 80 DVLOG(1) << "Sending event with snapshot: " << event.snapshot.ToString(); | 78 DVLOG(1) << "Sending event with snapshot: " << event.snapshot.ToString(); |
| 81 FOR_EACH_OBSERVER(SyncEngineEventListener, *(context_->listeners()), | 79 FOR_EACH_OBSERVER(SyncEngineEventListener, *(context_->listeners()), |
| 82 OnSyncCycleEvent(event)); | 80 OnSyncCycleEvent(event)); |
| 83 } | 81 } |
| 84 | 82 |
| 85 void SyncSession::SendProtocolEvent(const ProtocolEvent& event) { | 83 void SyncCycle::SendProtocolEvent(const ProtocolEvent& event) { |
| 86 FOR_EACH_OBSERVER(SyncEngineEventListener, *(context_->listeners()), | 84 FOR_EACH_OBSERVER(SyncEngineEventListener, *(context_->listeners()), |
| 87 OnProtocolEvent(event)); | 85 OnProtocolEvent(event)); |
| 88 } | 86 } |
| 89 | 87 |
| 90 } // namespace sessions | |
| 91 } // namespace syncer | 88 } // namespace syncer |
| OLD | NEW |