Remove define of defunct SK_DEBUG_PATH_REF from skia.gyp
[chromium-blink-merge.git] / sync / sessions / sync_session.cc
blobe526954b48a76bc2be19c9f48371c5cf120f4a7e
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"
7 #include <algorithm>
8 #include <iterator>
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"
15 namespace syncer {
16 namespace sessions {
18 // static
19 SyncSession* SyncSession::BuildForNudge(SyncSessionContext* context,
20 Delegate* delegate,
21 const SyncSourceInfo& source,
22 const NudgeTracker* nudge_tracker) {
23 return new SyncSession(context, delegate, source, nudge_tracker);
26 // static
27 SyncSession* SyncSession::Build(SyncSessionContext* context,
28 Delegate* delegate,
29 const SyncSourceInfo& source) {
30 return new SyncSession(context, delegate, source, NULL);
33 SyncSession::SyncSession(
34 SyncSessionContext* context,
35 Delegate* delegate,
36 const SyncSourceInfo& source,
37 const NudgeTracker* nudge_tracker)
38 : context_(context),
39 source_(source),
40 delegate_(delegate),
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(),
68 source_,
69 context_->notifications_enabled(),
70 dir->GetEntriesCount(),
71 status_controller_->sync_start_time(),
72 num_entries_by_type,
73 num_to_delete_entries_by_type);
75 return snapshot;
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
87 } // namespace syncer