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