OLD | NEW |
| (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 | |
13 SyncSessionJob::SyncSessionJob( | |
14 Purpose purpose, | |
15 base::TimeTicks start, | |
16 const sessions::SyncSourceInfo& source_info, | |
17 const ConfigurationParams& config_params) | |
18 : purpose_(purpose), | |
19 source_info_(source_info), | |
20 scheduled_start_(start), | |
21 config_params_(config_params) { | |
22 } | |
23 | |
24 #define ENUM_CASE(x) case x: return #x; break; | |
25 const char* SyncSessionJob::GetPurposeString(SyncSessionJob::Purpose purpose) { | |
26 switch (purpose) { | |
27 ENUM_CASE(UNKNOWN); | |
28 ENUM_CASE(POLL); | |
29 ENUM_CASE(NUDGE); | |
30 ENUM_CASE(CONFIGURATION); | |
31 } | |
32 NOTREACHED(); | |
33 return ""; | |
34 } | |
35 #undef ENUM_CASE | |
36 | |
37 bool SyncSessionJob::Finish(bool early_exit, sessions::SyncSession* session) { | |
38 // Did we quit part-way through due to premature exit condition, like | |
39 // shutdown? Note that this branch will not be hit for other kinds | |
40 // of early return scenarios, like certain kinds of transient errors. | |
41 if (early_exit) | |
42 return false; | |
43 | |
44 // Did we hit any errors along the way? | |
45 if (sessions::HasSyncerError( | |
46 session->status_controller().model_neutral_state())) { | |
47 return false; | |
48 } | |
49 | |
50 const sessions::ModelNeutralState& state( | |
51 session->status_controller().model_neutral_state()); | |
52 switch (purpose_) { | |
53 case POLL: | |
54 case NUDGE: | |
55 DCHECK_NE(state.last_download_updates_result, UNSET); | |
56 DCHECK_NE(state.commit_result, UNSET); | |
57 break; | |
58 case CONFIGURATION: | |
59 DCHECK_NE(state.last_download_updates_result, UNSET); | |
60 break; | |
61 case UNKNOWN: | |
62 default: | |
63 NOTREACHED(); | |
64 } | |
65 | |
66 if (!config_params_.ready_task.is_null()) | |
67 config_params_.ready_task.Run(); | |
68 return true; | |
69 } | |
70 | |
71 void SyncSessionJob::CoalesceSources(const sessions::SyncSourceInfo& source) { | |
72 CoalesceStates(source.types, &source_info_.types); | |
73 source_info_.updates_source = source.updates_source; | |
74 } | |
75 | |
76 SyncSessionJob::Purpose SyncSessionJob::purpose() const { | |
77 return purpose_; | |
78 } | |
79 | |
80 const sessions::SyncSourceInfo& SyncSessionJob::source_info() const { | |
81 return source_info_; | |
82 } | |
83 | |
84 base::TimeTicks SyncSessionJob::scheduled_start() const { | |
85 return scheduled_start_; | |
86 } | |
87 | |
88 void SyncSessionJob::set_scheduled_start(base::TimeTicks start) { | |
89 scheduled_start_ = start; | |
90 }; | |
91 | |
92 ConfigurationParams SyncSessionJob::config_params() const { | |
93 return config_params_; | |
94 } | |
95 | |
96 SyncerStep SyncSessionJob::start_step() const { | |
97 SyncerStep start, end; | |
98 GetSyncerStepsForPurpose(purpose_, &start, &end); | |
99 return start; | |
100 } | |
101 | |
102 SyncerStep SyncSessionJob::end_step() const { | |
103 SyncerStep start, end; | |
104 GetSyncerStepsForPurpose(purpose_, &start, &end); | |
105 return end; | |
106 } | |
107 | |
108 // static | |
109 void SyncSessionJob::GetSyncerStepsForPurpose(Purpose purpose, | |
110 SyncerStep* start, | |
111 SyncerStep* end) { | |
112 switch (purpose) { | |
113 case SyncSessionJob::CONFIGURATION: | |
114 *start = DOWNLOAD_UPDATES; | |
115 *end = APPLY_UPDATES; | |
116 return; | |
117 case SyncSessionJob::NUDGE: | |
118 case SyncSessionJob::POLL: | |
119 *start = SYNCER_BEGIN; | |
120 *end = SYNCER_END; | |
121 return; | |
122 default: | |
123 NOTREACHED(); | |
124 *start = SYNCER_END; | |
125 *end = SYNCER_END; | |
126 return; | |
127 } | |
128 } | |
129 | |
130 } // namespace syncer | |
OLD | NEW |