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/engine/syncer.h" | 5 #include "sync/engine/syncer.h" |
6 | 6 |
7 #include "base/auto_reset.h" | |
8 #include "base/location.h" | 7 #include "base/location.h" |
9 #include "base/logging.h" | 8 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
11 #include "base/time/time.h" | 10 #include "base/time/time.h" |
12 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
13 #include "build/build_config.h" | 12 #include "build/build_config.h" |
14 #include "sync/engine/apply_control_data_updates.h" | 13 #include "sync/engine/apply_control_data_updates.h" |
15 #include "sync/engine/commit.h" | 14 #include "sync/engine/commit.h" |
16 #include "sync/engine/commit_processor.h" | 15 #include "sync/engine/commit_processor.h" |
17 #include "sync/engine/conflict_resolver.h" | 16 #include "sync/engine/conflict_resolver.h" |
(...skipping 21 matching lines...) Expand all Loading... |
39 static const bool kCreateMobileBookmarksFolder = true; | 38 static const bool kCreateMobileBookmarksFolder = true; |
40 #else | 39 #else |
41 static const bool kCreateMobileBookmarksFolder = false; | 40 static const bool kCreateMobileBookmarksFolder = false; |
42 #endif | 41 #endif |
43 | 42 |
44 using sessions::StatusController; | 43 using sessions::StatusController; |
45 using sessions::SyncSession; | 44 using sessions::SyncSession; |
46 using sessions::NudgeTracker; | 45 using sessions::NudgeTracker; |
47 | 46 |
48 Syncer::Syncer(syncer::CancelationSignal* cancelation_signal) | 47 Syncer::Syncer(syncer::CancelationSignal* cancelation_signal) |
49 : cancelation_signal_(cancelation_signal), | 48 : cancelation_signal_(cancelation_signal) { |
50 is_syncing_(false) { | |
51 } | 49 } |
52 | 50 |
53 Syncer::~Syncer() {} | 51 Syncer::~Syncer() {} |
54 | 52 |
55 bool Syncer::ExitRequested() { | 53 bool Syncer::ExitRequested() { |
56 return cancelation_signal_->IsSignalled(); | 54 return cancelation_signal_->IsSignalled(); |
57 } | 55 } |
58 | 56 |
59 bool Syncer::IsSyncing() const { | |
60 return is_syncing_; | |
61 } | |
62 | |
63 bool Syncer::NormalSyncShare(ModelTypeSet request_types, | 57 bool Syncer::NormalSyncShare(ModelTypeSet request_types, |
64 NudgeTracker* nudge_tracker, | 58 NudgeTracker* nudge_tracker, |
65 SyncSession* session) { | 59 SyncSession* session) { |
66 base::AutoReset<bool> is_syncing(&is_syncing_, true); | |
67 HandleCycleBegin(session); | 60 HandleCycleBegin(session); |
68 if (nudge_tracker->IsGetUpdatesRequired() || | 61 if (nudge_tracker->IsGetUpdatesRequired() || |
69 session->context()->ShouldFetchUpdatesBeforeCommit()) { | 62 session->context()->ShouldFetchUpdatesBeforeCommit()) { |
70 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types); | 63 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types); |
71 NormalGetUpdatesDelegate normal_delegate(*nudge_tracker); | 64 NormalGetUpdatesDelegate normal_delegate(*nudge_tracker); |
72 GetUpdatesProcessor get_updates_processor( | 65 GetUpdatesProcessor get_updates_processor( |
73 session->context()->model_type_registry()->update_handler_map(), | 66 session->context()->model_type_registry()->update_handler_map(), |
74 normal_delegate); | 67 normal_delegate); |
75 if (!DownloadAndApplyUpdates( | 68 if (!DownloadAndApplyUpdates( |
76 &request_types, | 69 &request_types, |
(...skipping 11 matching lines...) Expand all Loading... |
88 session, &commit_processor); | 81 session, &commit_processor); |
89 session->mutable_status_controller()->set_commit_result(commit_result); | 82 session->mutable_status_controller()->set_commit_result(commit_result); |
90 | 83 |
91 return HandleCycleEnd(session, nudge_tracker->GetLegacySource()); | 84 return HandleCycleEnd(session, nudge_tracker->GetLegacySource()); |
92 } | 85 } |
93 | 86 |
94 bool Syncer::ConfigureSyncShare( | 87 bool Syncer::ConfigureSyncShare( |
95 ModelTypeSet request_types, | 88 ModelTypeSet request_types, |
96 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, | 89 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
97 SyncSession* session) { | 90 SyncSession* session) { |
98 base::AutoReset<bool> is_syncing(&is_syncing_, true); | |
99 VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types); | 91 VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types); |
100 HandleCycleBegin(session); | 92 HandleCycleBegin(session); |
101 ConfigureGetUpdatesDelegate configure_delegate(source); | 93 ConfigureGetUpdatesDelegate configure_delegate(source); |
102 GetUpdatesProcessor get_updates_processor( | 94 GetUpdatesProcessor get_updates_processor( |
103 session->context()->model_type_registry()->update_handler_map(), | 95 session->context()->model_type_registry()->update_handler_map(), |
104 configure_delegate); | 96 configure_delegate); |
105 DownloadAndApplyUpdates( | 97 DownloadAndApplyUpdates( |
106 &request_types, | 98 &request_types, |
107 session, | 99 session, |
108 &get_updates_processor, | 100 &get_updates_processor, |
109 kCreateMobileBookmarksFolder); | 101 kCreateMobileBookmarksFolder); |
110 return HandleCycleEnd(session, source); | 102 return HandleCycleEnd(session, source); |
111 } | 103 } |
112 | 104 |
113 bool Syncer::PollSyncShare(ModelTypeSet request_types, | 105 bool Syncer::PollSyncShare(ModelTypeSet request_types, |
114 SyncSession* session) { | 106 SyncSession* session) { |
115 base::AutoReset<bool> is_syncing(&is_syncing_, true); | |
116 VLOG(1) << "Polling types " << ModelTypeSetToString(request_types); | 107 VLOG(1) << "Polling types " << ModelTypeSetToString(request_types); |
117 HandleCycleBegin(session); | 108 HandleCycleBegin(session); |
118 PollGetUpdatesDelegate poll_delegate; | 109 PollGetUpdatesDelegate poll_delegate; |
119 GetUpdatesProcessor get_updates_processor( | 110 GetUpdatesProcessor get_updates_processor( |
120 session->context()->model_type_registry()->update_handler_map(), | 111 session->context()->model_type_registry()->update_handler_map(), |
121 poll_delegate); | 112 poll_delegate); |
122 DownloadAndApplyUpdates( | 113 DownloadAndApplyUpdates( |
123 &request_types, | 114 &request_types, |
124 session, | 115 session, |
125 &get_updates_processor, | 116 &get_updates_processor, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 void Syncer::HandleCycleBegin(SyncSession* session) { | 195 void Syncer::HandleCycleBegin(SyncSession* session) { |
205 session->mutable_status_controller()->UpdateStartTime(); | 196 session->mutable_status_controller()->UpdateStartTime(); |
206 session->SendEventNotification(SyncCycleEvent::SYNC_CYCLE_BEGIN); | 197 session->SendEventNotification(SyncCycleEvent::SYNC_CYCLE_BEGIN); |
207 } | 198 } |
208 | 199 |
209 bool Syncer::HandleCycleEnd( | 200 bool Syncer::HandleCycleEnd( |
210 SyncSession* session, | 201 SyncSession* session, |
211 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { | 202 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { |
212 if (!ExitRequested()) { | 203 if (!ExitRequested()) { |
213 session->SendSyncCycleEndEventNotification(source); | 204 session->SendSyncCycleEndEventNotification(source); |
214 | 205 return true; |
215 bool success = !sessions::HasSyncerError( | |
216 session->status_controller().model_neutral_state()); | |
217 if (success && source == sync_pb::GetUpdatesCallerInfo::PERIODIC) | |
218 session->mutable_status_controller()->UpdatePollTime(); | |
219 return success; | |
220 } else { | 206 } else { |
221 return false; | 207 return false; |
222 } | 208 } |
223 } | 209 } |
224 | 210 |
225 } // namespace syncer | 211 } // namespace syncer |
OLD | NEW |