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

Side by Side Diff: sync/engine/syncer.cc

Issue 23717047: Retry: sync: Gracefully handle early shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renames Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « sync/engine/syncer.h ('k') | sync/engine/syncer_proto_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/engine/syncer.h" 5 #include "sync/engine/syncer.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "sync/engine/apply_control_data_updates.h" 13 #include "sync/engine/apply_control_data_updates.h"
14 #include "sync/engine/apply_updates_and_resolve_conflicts_command.h" 14 #include "sync/engine/apply_updates_and_resolve_conflicts_command.h"
15 #include "sync/engine/build_commit_command.h" 15 #include "sync/engine/build_commit_command.h"
16 #include "sync/engine/commit.h" 16 #include "sync/engine/commit.h"
17 #include "sync/engine/conflict_resolver.h" 17 #include "sync/engine/conflict_resolver.h"
18 #include "sync/engine/download.h" 18 #include "sync/engine/download.h"
19 #include "sync/engine/net/server_connection_manager.h" 19 #include "sync/engine/net/server_connection_manager.h"
20 #include "sync/engine/process_commit_response_command.h" 20 #include "sync/engine/process_commit_response_command.h"
21 #include "sync/engine/syncer_types.h" 21 #include "sync/engine/syncer_types.h"
22 #include "sync/internal_api/public/base/cancelation_signal.h"
22 #include "sync/internal_api/public/base/unique_position.h" 23 #include "sync/internal_api/public/base/unique_position.h"
23 #include "sync/internal_api/public/util/syncer_error.h" 24 #include "sync/internal_api/public/util/syncer_error.h"
24 #include "sync/sessions/nudge_tracker.h" 25 #include "sync/sessions/nudge_tracker.h"
25 #include "sync/syncable/mutable_entry.h" 26 #include "sync/syncable/mutable_entry.h"
26 #include "sync/syncable/syncable-inl.h" 27 #include "sync/syncable/syncable-inl.h"
27 28
28 using base::Time; 29 using base::Time;
29 using base::TimeDelta; 30 using base::TimeDelta;
30 using sync_pb::ClientCommand; 31 using sync_pb::ClientCommand;
31 32
32 namespace syncer { 33 namespace syncer {
33 34
34 // TODO(akalin): We may want to propagate this switch up 35 // TODO(akalin): We may want to propagate this switch up
35 // eventually. 36 // eventually.
36 #if defined(OS_ANDROID) || defined(OS_IOS) 37 #if defined(OS_ANDROID) || defined(OS_IOS)
37 static const bool kCreateMobileBookmarksFolder = true; 38 static const bool kCreateMobileBookmarksFolder = true;
38 #else 39 #else
39 static const bool kCreateMobileBookmarksFolder = false; 40 static const bool kCreateMobileBookmarksFolder = false;
40 #endif 41 #endif
41 42
42 using sessions::StatusController; 43 using sessions::StatusController;
43 using sessions::SyncSession; 44 using sessions::SyncSession;
44 using sessions::NudgeTracker; 45 using sessions::NudgeTracker;
45 46
46 Syncer::Syncer() 47 Syncer::Syncer(syncer::CancelationSignal* cancelation_signal)
47 : early_exit_requested_(false) { 48 : cancelation_signal_(cancelation_signal) {
48 } 49 }
49 50
50 Syncer::~Syncer() {} 51 Syncer::~Syncer() {}
51 52
52 bool Syncer::ExitRequested() { 53 bool Syncer::ExitRequested() {
53 base::AutoLock lock(early_exit_requested_lock_); 54 return cancelation_signal_->IsSignalled();
54 return early_exit_requested_;
55 }
56
57 void Syncer::RequestEarlyExit() {
58 base::AutoLock lock(early_exit_requested_lock_);
59 early_exit_requested_ = true;
60 } 55 }
61 56
62 bool Syncer::NormalSyncShare(ModelTypeSet request_types, 57 bool Syncer::NormalSyncShare(ModelTypeSet request_types,
63 const NudgeTracker& nudge_tracker, 58 const NudgeTracker& nudge_tracker,
64 SyncSession* session) { 59 SyncSession* session) {
65 HandleCycleBegin(session); 60 HandleCycleBegin(session);
66 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types); 61 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types);
67 if (nudge_tracker.IsGetUpdatesRequired() || 62 if (nudge_tracker.IsGetUpdatesRequired() ||
68 session->context()->ShouldFetchUpdatesBeforeCommit()) { 63 session->context()->ShouldFetchUpdatesBeforeCommit()) {
69 if (!DownloadAndApplyUpdates( 64 if (!DownloadAndApplyUpdates(
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { 154 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) {
160 if (!ExitRequested()) { 155 if (!ExitRequested()) {
161 session->SendSyncCycleEndEventNotification(source); 156 session->SendSyncCycleEndEventNotification(source);
162 return true; 157 return true;
163 } else { 158 } else {
164 return false; 159 return false;
165 } 160 }
166 } 161 }
167 162
168 } // namespace syncer 163 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/syncer.h ('k') | sync/engine/syncer_proto_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698