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