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

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

Issue 10917234: sync: make scheduling logic and job ownership more obvious. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review Created 8 years, 1 month 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
OLDNEW
(Empty)
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.
4
5 #include "sync/engine/sync_session_job.h"
6 #include "sync/internal_api/public/sessions/model_neutral_state.h"
7
8 namespace syncer {
9
10 SyncSessionJob::~SyncSessionJob() {}
11
12 SyncSessionJob::SyncSessionJob(
13 Purpose purpose,
14 base::TimeTicks start,
15 scoped_ptr<sessions::SyncSession> session,
16 const ConfigurationParams& config_params,
17 const tracked_objects::Location& from_location)
18 : purpose_(purpose),
19 scheduled_start_(start),
20 session_(session.Pass()),
21 is_canary_(false),
22 config_params_(config_params),
23 finished_(NOT_FINISHED),
24 from_location_(from_location) {
25 }
26
27 #define ENUM_CASE(x) case x: return #x; break;
28 const char* SyncSessionJob::GetPurposeString(SyncSessionJob::Purpose purpose) {
29 switch (purpose) {
30 ENUM_CASE(UNKNOWN);
31 ENUM_CASE(POLL);
32 ENUM_CASE(NUDGE);
33 ENUM_CASE(CONFIGURATION);
34 }
35 NOTREACHED();
36 return "";
37 }
38 #undef ENUM_CASE
39
40 bool SyncSessionJob::Finish(bool early_exit) {
41 DCHECK_EQ(finished_, NOT_FINISHED);
42 // Did we run through all SyncerSteps from start_step() to end_step()
43 // until the SyncSession returned !HasMoreToSync()?
44 // Note: if not, it's possible the scheduler hasn't started with
45 // SyncShare yet, it's possible there is still more to sync in the session,
46 // and it's also possible the job quit part way through due to a premature
47 // exit condition (such as shutdown).
48 finished_ = early_exit ? EARLY_EXIT : FINISHED;
49
50 if (early_exit)
51 return false;
52
53 DCHECK(!session_->HasMoreToSync());
54
55 // Did we hit any errors along the way?
56 if (sessions::HasSyncerError(
57 session_->status_controller().model_neutral_state())) {
58 return false;
59 }
60
61 const sessions::ModelNeutralState& state(
62 session_->status_controller().model_neutral_state());
63 switch (purpose_) {
64 case POLL:
65 case NUDGE:
66 DCHECK(state.last_download_updates_result != UNSET &&
akalin 2012/10/26 06:52:29 split into two DCHECK_NEs?
67 state.commit_result != UNSET);
68 break;
69 case CONFIGURATION:
70 DCHECK_NE(state.last_download_updates_result, UNSET);
71 break;
72 case UNKNOWN:
73 default:
74 NOTREACHED();
75 }
76
77 if (!config_params_.ready_task.is_null())
78 config_params_.ready_task.Run();
79 return true;
80 }
81
82 scoped_ptr<SyncSessionJob> SyncSessionJob::CloneAndAbandon() {
83 DCHECK_EQ(finished_, NOT_FINISHED);
84 // Clone |this|, and abandon it by NULL-ing session_.
85 return scoped_ptr<SyncSessionJob> (new SyncSessionJob(
86 purpose_, scheduled_start_, session_.Pass(),
87 config_params_, from_location_));
88 }
89
90 scoped_ptr<SyncSessionJob> SyncSessionJob::Clone() const {
91 DCHECK_GT(finished_, NOT_FINISHED);
92 return scoped_ptr<SyncSessionJob>(new SyncSessionJob(
93 purpose_, scheduled_start_, CloneSession().Pass(),
94 config_params_, from_location_));
95 }
96
97 scoped_ptr<SyncSessionJob> SyncSessionJob::CloneFromLocation(
98 const tracked_objects::Location& from_here) const {
99 DCHECK_GT(finished_, NOT_FINISHED);
100 return scoped_ptr<SyncSessionJob>(new SyncSessionJob(
101 purpose_, scheduled_start_, CloneSession().Pass(),
102 config_params_, from_here));
103 }
104
105 scoped_ptr<sessions::SyncSession> SyncSessionJob::CloneSession() const {
106 return scoped_ptr<sessions::SyncSession>(
107 new sessions::SyncSession(session_->context(),
108 session_->delegate(), session_->source(), session_->routing_info(),
109 session_->workers()));
110 }
111
112 bool SyncSessionJob::is_canary() const {
113 return is_canary_;
114 }
115
116 SyncSessionJob::Purpose SyncSessionJob::purpose() const {
117 return purpose_;
118 }
119
120 base::TimeTicks SyncSessionJob::scheduled_start() const {
121 return scheduled_start_;
122 }
123
124 void SyncSessionJob::set_scheduled_start(base::TimeTicks start) {
125 scheduled_start_ = start;
126 };
127
128 const sessions::SyncSession* SyncSessionJob::session() const {
akalin 2012/10/26 06:52:29 const ref?
tim (not reviewing) 2012/10/26 22:52:27 We use session() for equality checks in several pl
129 return session_.get();
130 }
131
132 sessions::SyncSession* SyncSessionJob::mutable_session() {
133 return session_.get();
134 }
135
136 const tracked_objects::Location& SyncSessionJob::from_location() const {
137 return from_location_;
138 }
139
140 ConfigurationParams SyncSessionJob::config_params() const {
141 return config_params_;
142 }
143
144 void SyncSessionJob::GrantCanaryPrivilege() {
145 DCHECK_EQ(finished_, NOT_FINISHED);
146 DVLOG(2) << "Granting canary priviliege to " << session_.get();
147 is_canary_ = true;
148 }
149
150 SyncerStep SyncSessionJob::start_step() const {
151 SyncerStep start, end;
152 GetSyncerStepsForPurpose(purpose_, &start, &end);
153 return start;
154 }
155
156 SyncerStep SyncSessionJob::end_step() const {
157 SyncerStep start, end;
158 GetSyncerStepsForPurpose(purpose_, &start, &end);
159 return end;
160 }
161
162 // static
163 void SyncSessionJob::GetSyncerStepsForPurpose(Purpose purpose,
164 SyncerStep* start,
165 SyncerStep* end) {
166 switch (purpose) {
167 case SyncSessionJob::CONFIGURATION:
168 *start = DOWNLOAD_UPDATES;
169 *end = APPLY_UPDATES;
170 return;
171 case SyncSessionJob::NUDGE:
172 case SyncSessionJob::POLL:
173 *start = SYNCER_BEGIN;
174 *end = SYNCER_END;
175 return;
176 default:
177 NOTREACHED();
178 *start = SYNCER_END;
179 *end = SYNCER_END;
180 return;
181 }
182 }
183
184 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698