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"
19 SyncSession
* SyncSession::BuildForNudge(SyncSessionContext
* context
,
21 const SyncSourceInfo
& source
,
22 const NudgeTracker
* nudge_tracker
) {
23 return new SyncSession(context
, delegate
, source
, nudge_tracker
);
27 SyncSession
* SyncSession::Build(SyncSessionContext
* context
,
29 const SyncSourceInfo
& source
) {
30 return new SyncSession(context
, delegate
, source
, NULL
);
33 SyncSession::SyncSession(
34 SyncSessionContext
* context
,
36 const SyncSourceInfo
& source
,
37 const NudgeTracker
* nudge_tracker
)
41 nudge_tracker_(nudge_tracker
) {
42 status_controller_
.reset(new StatusController());
45 SyncSession::~SyncSession() {}
47 SyncSessionSnapshot
SyncSession::TakeSnapshot() const {
48 syncable::Directory
* dir
= context_
->directory();
50 ProgressMarkerMap download_progress_markers
;
51 for (int i
= FIRST_REAL_MODEL_TYPE
; i
< MODEL_TYPE_COUNT
; ++i
) {
52 ModelType
type(ModelTypeFromInt(i
));
53 dir
->GetDownloadProgressAsString(type
, &download_progress_markers
[type
]);
56 std::vector
<int> num_entries_by_type(MODEL_TYPE_COUNT
, 0);
57 std::vector
<int> num_to_delete_entries_by_type(MODEL_TYPE_COUNT
, 0);
58 dir
->CollectMetaHandleCounts(&num_entries_by_type
,
59 &num_to_delete_entries_by_type
);
61 SyncSessionSnapshot
snapshot(
62 status_controller_
->model_neutral_state(),
63 download_progress_markers
,
64 delegate_
->IsCurrentlyThrottled(),
65 status_controller_
->num_encryption_conflicts(),
66 status_controller_
->num_hierarchy_conflicts(),
67 status_controller_
->num_server_conflicts(),
69 context_
->notifications_enabled(),
70 dir
->GetEntriesCount(),
71 status_controller_
->sync_start_time(),
73 num_to_delete_entries_by_type
);
78 void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause
) {
79 SyncEngineEvent
event(cause
);
80 event
.snapshot
= TakeSnapshot();
82 DVLOG(1) << "Sending event with snapshot: " << event
.snapshot
.ToString();
83 context()->NotifyListeners(event
);
86 } // namespace sessions