Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: components/sync/sessions_impl/sync_session.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/sync/sessions_impl/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 "components/sync/base/model_type.h"
12 #include "sync/internal_api/public/engine/model_safe_worker.h" 12 #include "components/sync/engine/model_safe_worker.h"
13 #include "sync/syncable/directory.h" 13 #include "components/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 return new SyncSession(context, delegate); 21 return new SyncSession(context, delegate);
22 } 22 }
23 23
24 SyncSession::SyncSession( 24 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate)
25 SyncSessionContext* context, 25 : context_(context), delegate_(delegate) {
26 Delegate* delegate)
27 : context_(context),
28 delegate_(delegate) {
29 status_controller_.reset(new StatusController()); 26 status_controller_.reset(new StatusController());
30 } 27 }
31 28
32 SyncSession::~SyncSession() {} 29 SyncSession::~SyncSession() {}
33 30
34 SyncSessionSnapshot SyncSession::TakeSnapshot() const { 31 SyncSessionSnapshot SyncSession::TakeSnapshot() const {
35 return TakeSnapshotWithSource(sync_pb::GetUpdatesCallerInfo::UNKNOWN); 32 return TakeSnapshotWithSource(sync_pb::GetUpdatesCallerInfo::UNKNOWN);
36 } 33 }
37 34
38 SyncSessionSnapshot SyncSession::TakeSnapshotWithSource( 35 SyncSessionSnapshot SyncSession::TakeSnapshotWithSource(
39 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source) const { 36 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source)
37 const {
40 syncable::Directory* dir = context_->directory(); 38 syncable::Directory* dir = context_->directory();
41 39
42 ProgressMarkerMap download_progress_markers; 40 ProgressMarkerMap download_progress_markers;
43 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 41 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
44 ModelType type(ModelTypeFromInt(i)); 42 ModelType type(ModelTypeFromInt(i));
45 dir->GetDownloadProgressAsString(type, &download_progress_markers[type]); 43 dir->GetDownloadProgressAsString(type, &download_progress_markers[type]);
46 } 44 }
47 45
48 std::vector<int> num_entries_by_type(MODEL_TYPE_COUNT, 0); 46 std::vector<int> num_entries_by_type(MODEL_TYPE_COUNT, 0);
49 std::vector<int> num_to_delete_entries_by_type(MODEL_TYPE_COUNT, 0); 47 std::vector<int> num_to_delete_entries_by_type(MODEL_TYPE_COUNT, 0);
50 dir->CollectMetaHandleCounts(&num_entries_by_type, 48 dir->CollectMetaHandleCounts(&num_entries_by_type,
51 &num_to_delete_entries_by_type); 49 &num_to_delete_entries_by_type);
52 50
53 SyncSessionSnapshot snapshot( 51 SyncSessionSnapshot snapshot(
54 status_controller_->model_neutral_state(), 52 status_controller_->model_neutral_state(), download_progress_markers,
55 download_progress_markers,
56 delegate_->IsCurrentlyThrottled(), 53 delegate_->IsCurrentlyThrottled(),
57 status_controller_->num_encryption_conflicts(), 54 status_controller_->num_encryption_conflicts(),
58 status_controller_->num_hierarchy_conflicts(), 55 status_controller_->num_hierarchy_conflicts(),
59 status_controller_->num_server_conflicts(), 56 status_controller_->num_server_conflicts(),
60 context_->notifications_enabled(), 57 context_->notifications_enabled(), dir->GetEntriesCount(),
61 dir->GetEntriesCount(),
62 status_controller_->sync_start_time(), 58 status_controller_->sync_start_time(),
63 status_controller_->poll_finish_time(), 59 status_controller_->poll_finish_time(), num_entries_by_type,
64 num_entries_by_type, 60 num_to_delete_entries_by_type, legacy_updates_source);
65 num_to_delete_entries_by_type,
66 legacy_updates_source);
67 61
68 return snapshot; 62 return snapshot;
69 } 63 }
70 64
71 void SyncSession::SendSyncCycleEndEventNotification( 65 void SyncSession::SendSyncCycleEndEventNotification(
72 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { 66 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) {
73 SyncCycleEvent event(SyncCycleEvent::SYNC_CYCLE_ENDED); 67 SyncCycleEvent event(SyncCycleEvent::SYNC_CYCLE_ENDED);
74 event.snapshot = TakeSnapshotWithSource(source); 68 event.snapshot = TakeSnapshotWithSource(source);
75 69
76 DVLOG(1) << "Sending cycle end event with snapshot: " 70 DVLOG(1) << "Sending cycle end event with snapshot: "
77 << event.snapshot.ToString(); 71 << event.snapshot.ToString();
78 FOR_EACH_OBSERVER(SyncEngineEventListener, 72 FOR_EACH_OBSERVER(SyncEngineEventListener, *(context_->listeners()),
79 *(context_->listeners()),
80 OnSyncCycleEvent(event)); 73 OnSyncCycleEvent(event));
81 } 74 }
82 75
83 void SyncSession::SendEventNotification(SyncCycleEvent::EventCause cause) { 76 void SyncSession::SendEventNotification(SyncCycleEvent::EventCause cause) {
84 SyncCycleEvent event(cause); 77 SyncCycleEvent event(cause);
85 event.snapshot = TakeSnapshot(); 78 event.snapshot = TakeSnapshot();
86 79
87 DVLOG(1) << "Sending event with snapshot: " << event.snapshot.ToString(); 80 DVLOG(1) << "Sending event with snapshot: " << event.snapshot.ToString();
88 FOR_EACH_OBSERVER(SyncEngineEventListener, 81 FOR_EACH_OBSERVER(SyncEngineEventListener, *(context_->listeners()),
89 *(context_->listeners()),
90 OnSyncCycleEvent(event)); 82 OnSyncCycleEvent(event));
91 } 83 }
92 84
93 void SyncSession::SendProtocolEvent(const ProtocolEvent& event) { 85 void SyncSession::SendProtocolEvent(const ProtocolEvent& event) {
94 FOR_EACH_OBSERVER(SyncEngineEventListener, 86 FOR_EACH_OBSERVER(SyncEngineEventListener, *(context_->listeners()),
95 *(context_->listeners()),
96 OnProtocolEvent(event)); 87 OnProtocolEvent(event));
97 } 88 }
98 89
99 } // namespace sessions 90 } // namespace sessions
100 } // namespace syncer 91 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/sessions_impl/sync_session.h ('k') | components/sync/sessions_impl/sync_session_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698