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