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 if (destruction_observer_) | 11 if (destruction_observer_) |
12 destruction_observer_->OnJobDestroyed(this); | 12 destruction_observer_->OnJobDestroyed(this); |
13 } | 13 } |
14 | 14 |
15 SyncSessionJob::SyncSessionJob( | 15 SyncSessionJob::SyncSessionJob( |
16 Purpose purpose, | 16 Purpose purpose, |
17 base::TimeTicks start, | 17 base::TimeTicks start, |
18 scoped_ptr<sessions::SyncSession> session, | 18 scoped_ptr<sessions::SyncSession> session, |
19 const ConfigurationParams& config_params, | 19 const ConfigurationParams& config_params) |
20 const tracked_objects::Location& from_location) | |
21 : purpose_(purpose), | 20 : purpose_(purpose), |
22 scheduled_start_(start), | 21 scheduled_start_(start), |
23 session_(session.Pass()), | 22 session_(session.Pass()), |
24 is_canary_(false), | 23 is_canary_(false), |
25 config_params_(config_params), | 24 config_params_(config_params), |
26 finished_(NOT_FINISHED), | 25 finished_(NOT_FINISHED) { |
27 from_location_(from_location) { | |
28 } | 26 } |
29 | 27 |
30 void SyncSessionJob::set_destruction_observer( | 28 void SyncSessionJob::set_destruction_observer( |
31 const base::WeakPtr<DestructionObserver>& destruction_observer) { | 29 const base::WeakPtr<DestructionObserver>& destruction_observer) { |
32 destruction_observer_ = destruction_observer; | 30 destruction_observer_ = destruction_observer; |
33 } | 31 } |
34 | 32 |
35 #define ENUM_CASE(x) case x: return #x; break; | 33 #define ENUM_CASE(x) case x: return #x; break; |
36 const char* SyncSessionJob::GetPurposeString(SyncSessionJob::Purpose purpose) { | 34 const char* SyncSessionJob::GetPurposeString(SyncSessionJob::Purpose purpose) { |
37 switch (purpose) { | 35 switch (purpose) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 if (!config_params_.ready_task.is_null()) | 81 if (!config_params_.ready_task.is_null()) |
84 config_params_.ready_task.Run(); | 82 config_params_.ready_task.Run(); |
85 return true; | 83 return true; |
86 } | 84 } |
87 | 85 |
88 scoped_ptr<SyncSessionJob> SyncSessionJob::CloneAndAbandon() { | 86 scoped_ptr<SyncSessionJob> SyncSessionJob::CloneAndAbandon() { |
89 DCHECK_EQ(finished_, NOT_FINISHED); | 87 DCHECK_EQ(finished_, NOT_FINISHED); |
90 // Clone |this|, and abandon it by NULL-ing session_. | 88 // Clone |this|, and abandon it by NULL-ing session_. |
91 return scoped_ptr<SyncSessionJob> (new SyncSessionJob( | 89 return scoped_ptr<SyncSessionJob> (new SyncSessionJob( |
92 purpose_, scheduled_start_, session_.Pass(), | 90 purpose_, scheduled_start_, session_.Pass(), |
93 config_params_, from_location_)); | 91 config_params_)); |
94 } | 92 } |
95 | 93 |
96 scoped_ptr<SyncSessionJob> SyncSessionJob::Clone() const { | 94 scoped_ptr<SyncSessionJob> SyncSessionJob::Clone() const { |
97 DCHECK_GT(finished_, NOT_FINISHED); | 95 DCHECK_GT(finished_, NOT_FINISHED); |
98 return scoped_ptr<SyncSessionJob>(new SyncSessionJob( | 96 return scoped_ptr<SyncSessionJob>(new SyncSessionJob( |
99 purpose_, scheduled_start_, CloneSession().Pass(), | 97 purpose_, scheduled_start_, CloneSession().Pass(), |
100 config_params_, from_location_)); | 98 config_params_)); |
101 } | |
102 | |
103 scoped_ptr<SyncSessionJob> SyncSessionJob::CloneFromLocation( | |
104 const tracked_objects::Location& from_here) const { | |
105 DCHECK_GT(finished_, NOT_FINISHED); | |
106 return scoped_ptr<SyncSessionJob>(new SyncSessionJob( | |
107 purpose_, scheduled_start_, CloneSession().Pass(), | |
108 config_params_, from_here)); | |
109 } | 99 } |
110 | 100 |
111 scoped_ptr<sessions::SyncSession> SyncSessionJob::CloneSession() const { | 101 scoped_ptr<sessions::SyncSession> SyncSessionJob::CloneSession() const { |
112 return scoped_ptr<sessions::SyncSession>( | 102 return scoped_ptr<sessions::SyncSession>( |
113 new sessions::SyncSession(session_->context(), | 103 new sessions::SyncSession(session_->context(), |
114 session_->delegate(), session_->source())); | 104 session_->delegate(), session_->source())); |
115 } | 105 } |
116 | 106 |
117 bool SyncSessionJob::is_canary() const { | 107 bool SyncSessionJob::is_canary() const { |
118 return is_canary_; | 108 return is_canary_; |
(...skipping 12 matching lines...) Expand all Loading... |
131 }; | 121 }; |
132 | 122 |
133 const sessions::SyncSession* SyncSessionJob::session() const { | 123 const sessions::SyncSession* SyncSessionJob::session() const { |
134 return session_.get(); | 124 return session_.get(); |
135 } | 125 } |
136 | 126 |
137 sessions::SyncSession* SyncSessionJob::mutable_session() { | 127 sessions::SyncSession* SyncSessionJob::mutable_session() { |
138 return session_.get(); | 128 return session_.get(); |
139 } | 129 } |
140 | 130 |
141 const tracked_objects::Location& SyncSessionJob::from_location() const { | |
142 return from_location_; | |
143 } | |
144 | |
145 ConfigurationParams SyncSessionJob::config_params() const { | 131 ConfigurationParams SyncSessionJob::config_params() const { |
146 return config_params_; | 132 return config_params_; |
147 } | 133 } |
148 | 134 |
149 void SyncSessionJob::GrantCanaryPrivilege() { | 135 void SyncSessionJob::GrantCanaryPrivilege() { |
150 DCHECK_EQ(finished_, NOT_FINISHED); | 136 DCHECK_EQ(finished_, NOT_FINISHED); |
151 DVLOG(2) << "Granting canary priviliege to " << session_.get(); | 137 DVLOG(2) << "Granting canary priviliege to " << session_.get(); |
152 is_canary_ = true; | 138 is_canary_ = true; |
153 } | 139 } |
154 | 140 |
(...skipping 25 matching lines...) Expand all Loading... |
180 return; | 166 return; |
181 default: | 167 default: |
182 NOTREACHED(); | 168 NOTREACHED(); |
183 *start = SYNCER_END; | 169 *start = SYNCER_END; |
184 *end = SYNCER_END; | 170 *end = SYNCER_END; |
185 return; | 171 return; |
186 } | 172 } |
187 } | 173 } |
188 | 174 |
189 } // namespace syncer | 175 } // namespace syncer |
OLD | NEW |