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/sync_session_job.h" | 5 #include "sync/engine/sync_session_job.h" |
6 #include "sync/internal_api/public/sessions/model_neutral_state.h" | 6 #include "sync/internal_api/public/sessions/model_neutral_state.h" |
7 | 7 |
8 namespace syncer { | 8 namespace syncer { |
9 | 9 |
10 SyncSessionJob::~SyncSessionJob() { | 10 SyncSessionJob::~SyncSessionJob() { |
11 } | 11 } |
12 | 12 |
13 SyncSessionJob::SyncSessionJob( | 13 SyncSessionJob::SyncSessionJob( |
14 Purpose purpose, | 14 Purpose purpose, |
15 base::TimeTicks start, | 15 base::TimeTicks start, |
16 const sessions::SyncSourceInfo& source_info, | 16 const sessions::SyncSourceInfo& source_info, |
17 const ConfigurationParams& config_params) | 17 const ConfigurationParams& config_params) |
18 : purpose_(purpose), | 18 : purpose_(purpose), |
19 source_info_(source_info), | 19 source_info_(source_info), |
20 scheduled_start_(start), | 20 scheduled_start_(start), |
21 config_params_(config_params), | 21 config_params_(config_params) { |
22 finished_(NOT_FINISHED) { | |
23 } | 22 } |
24 | 23 |
25 #define ENUM_CASE(x) case x: return #x; break; | 24 #define ENUM_CASE(x) case x: return #x; break; |
26 const char* SyncSessionJob::GetPurposeString(SyncSessionJob::Purpose purpose) { | 25 const char* SyncSessionJob::GetPurposeString(SyncSessionJob::Purpose purpose) { |
27 switch (purpose) { | 26 switch (purpose) { |
28 ENUM_CASE(UNKNOWN); | 27 ENUM_CASE(UNKNOWN); |
29 ENUM_CASE(POLL); | 28 ENUM_CASE(POLL); |
30 ENUM_CASE(NUDGE); | 29 ENUM_CASE(NUDGE); |
31 ENUM_CASE(CONFIGURATION); | 30 ENUM_CASE(CONFIGURATION); |
32 } | 31 } |
33 NOTREACHED(); | 32 NOTREACHED(); |
34 return ""; | 33 return ""; |
35 } | 34 } |
36 #undef ENUM_CASE | 35 #undef ENUM_CASE |
37 | 36 |
38 bool SyncSessionJob::Finish(bool early_exit, sessions::SyncSession* session) { | 37 bool SyncSessionJob::Finish(bool early_exit, sessions::SyncSession* session) { |
39 DCHECK_EQ(finished_, NOT_FINISHED); | 38 // Did we quit part-way through due to premature exit condition, like |
40 // Did we run through all SyncerSteps from start_step() to end_step() | 39 // shutdown? Note that this branch will not be hit for other kinds |
41 // until the SyncSession returned !HasMoreToSync()? | 40 // of early return scenarios, like certain kinds of transient errors. |
42 // Note: if not, it's possible the scheduler hasn't started with | |
43 // SyncShare yet, it's possible there is still more to sync in the session, | |
44 // and it's also possible the job quit part way through due to a premature | |
45 // exit condition (such as shutdown). | |
46 finished_ = early_exit ? EARLY_EXIT : FINISHED; | |
47 | |
48 if (early_exit) | 41 if (early_exit) |
49 return false; | 42 return false; |
50 | 43 |
51 // Did we hit any errors along the way? | 44 // Did we hit any errors along the way? |
52 if (sessions::HasSyncerError( | 45 if (sessions::HasSyncerError( |
53 session->status_controller().model_neutral_state())) { | 46 session->status_controller().model_neutral_state())) { |
54 return false; | 47 return false; |
55 } | 48 } |
56 | 49 |
57 const sessions::ModelNeutralState& state( | 50 const sessions::ModelNeutralState& state( |
(...skipping 10 matching lines...) Expand all Loading... |
68 case UNKNOWN: | 61 case UNKNOWN: |
69 default: | 62 default: |
70 NOTREACHED(); | 63 NOTREACHED(); |
71 } | 64 } |
72 | 65 |
73 if (!config_params_.ready_task.is_null()) | 66 if (!config_params_.ready_task.is_null()) |
74 config_params_.ready_task.Run(); | 67 config_params_.ready_task.Run(); |
75 return true; | 68 return true; |
76 } | 69 } |
77 | 70 |
78 scoped_ptr<SyncSessionJob> SyncSessionJob::Clone() const { | |
79 return scoped_ptr<SyncSessionJob>(new SyncSessionJob( | |
80 purpose_, scheduled_start_, source_info_, | |
81 config_params_)); | |
82 } | |
83 | |
84 void SyncSessionJob::CoalesceSources(const sessions::SyncSourceInfo& source) { | 71 void SyncSessionJob::CoalesceSources(const sessions::SyncSourceInfo& source) { |
85 CoalesceStates(source.types, &source_info_.types); | 72 CoalesceStates(source.types, &source_info_.types); |
86 source_info_.updates_source = source.updates_source; | 73 source_info_.updates_source = source.updates_source; |
87 } | 74 } |
88 | 75 |
89 SyncSessionJob::Purpose SyncSessionJob::purpose() const { | 76 SyncSessionJob::Purpose SyncSessionJob::purpose() const { |
90 return purpose_; | 77 return purpose_; |
91 } | 78 } |
92 | 79 |
93 const sessions::SyncSourceInfo& SyncSessionJob::source_info() const { | 80 const sessions::SyncSourceInfo& SyncSessionJob::source_info() const { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 return; | 121 return; |
135 default: | 122 default: |
136 NOTREACHED(); | 123 NOTREACHED(); |
137 *start = SYNCER_END; | 124 *start = SYNCER_END; |
138 *end = SYNCER_END; | 125 *end = SYNCER_END; |
139 return; | 126 return; |
140 } | 127 } |
141 } | 128 } |
142 | 129 |
143 } // namespace syncer | 130 } // namespace syncer |
OLD | NEW |