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.
5 #include "sync/sessions/sync_session.h"
10 #include "base/logging.h"
11 #include "sync/internal_api/public/base/model_type.h"
12 #include "sync/internal_api/public/engine/model_safe_worker.h"
13 #include "sync/syncable/directory.h"
18 SyncSession::SyncSession(
19 SyncSessionContext
* context
,
21 const SyncSourceInfo
& source
)
25 status_controller_
.reset(new StatusController());
28 SyncSession::~SyncSession() {}
30 SyncSessionSnapshot
SyncSession::TakeSnapshot() const {
31 syncable::Directory
* dir
= context_
->directory();
33 ProgressMarkerMap download_progress_markers
;
34 for (int i
= FIRST_REAL_MODEL_TYPE
; i
< MODEL_TYPE_COUNT
; ++i
) {
35 ModelType
type(ModelTypeFromInt(i
));
36 dir
->GetDownloadProgressAsString(type
, &download_progress_markers
[type
]);
39 std::vector
<int> num_entries_by_type(MODEL_TYPE_COUNT
, 0);
40 std::vector
<int> num_to_delete_entries_by_type(MODEL_TYPE_COUNT
, 0);
41 dir
->CollectMetaHandleCounts(&num_entries_by_type
,
42 &num_to_delete_entries_by_type
);
44 SyncSessionSnapshot
snapshot(
45 status_controller_
->model_neutral_state(),
46 download_progress_markers
,
47 delegate_
->IsSyncingCurrentlySilenced(),
48 status_controller_
->num_encryption_conflicts(),
49 status_controller_
->num_hierarchy_conflicts(),
50 status_controller_
->num_server_conflicts(),
52 context_
->notifications_enabled(),
53 dir
->GetEntriesCount(),
54 status_controller_
->sync_start_time(),
56 num_to_delete_entries_by_type
);
61 void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause
) {
62 SyncEngineEvent
event(cause
);
63 event
.snapshot
= TakeSnapshot();
65 DVLOG(1) << "Sending event with snapshot: " << event
.snapshot
.ToString();
66 context()->NotifyListeners(event
);
69 } // namespace sessions