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