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 "chrome/browser/chromeos/gdata/gdata_operation_registry.h" | 5 #include "chrome/browser/chromeos/gdata/operation_registry.h" |
6 | 6 |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 | 9 |
10 using content::BrowserThread; | 10 using content::BrowserThread; |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 const int64 kNotificationFrequencyInMilliseconds = 1000; | 14 const int64 kNotificationFrequencyInMilliseconds = 1000; |
15 | 15 |
16 } // namespace | 16 } // namespace |
17 | 17 |
18 namespace gdata { | 18 namespace gdata { |
19 | 19 |
20 // static | 20 // static |
21 std::string GDataOperationRegistry::OperationTypeToString(OperationType type) { | 21 std::string OperationRegistry::OperationTypeToString(OperationType type) { |
22 switch (type) { | 22 switch (type) { |
23 case OPERATION_UPLOAD: return "upload"; | 23 case OPERATION_UPLOAD: return "upload"; |
24 case OPERATION_DOWNLOAD: return "download"; | 24 case OPERATION_DOWNLOAD: return "download"; |
25 case OPERATION_OTHER: return "other"; | 25 case OPERATION_OTHER: return "other"; |
26 } | 26 } |
27 NOTREACHED(); | 27 NOTREACHED(); |
28 return "unknown_transfer_state"; | 28 return "unknown_transfer_state"; |
29 } | 29 } |
30 | 30 |
31 // static | 31 // static |
32 std::string GDataOperationRegistry::OperationTransferStateToString( | 32 std::string OperationRegistry::OperationTransferStateToString( |
33 OperationTransferState state) { | 33 OperationTransferState state) { |
34 switch (state) { | 34 switch (state) { |
35 case OPERATION_NOT_STARTED: return "not_started"; | 35 case OPERATION_NOT_STARTED: return "not_started"; |
36 case OPERATION_STARTED: return "started"; | 36 case OPERATION_STARTED: return "started"; |
37 case OPERATION_IN_PROGRESS: return "in_progress"; | 37 case OPERATION_IN_PROGRESS: return "in_progress"; |
38 case OPERATION_COMPLETED: return "completed"; | 38 case OPERATION_COMPLETED: return "completed"; |
39 case OPERATION_FAILED: return "failed"; | 39 case OPERATION_FAILED: return "failed"; |
40 // Suspended state is opaque to users and looks as same as "in_progress". | 40 // Suspended state is opaque to users and looks as same as "in_progress". |
41 case OPERATION_SUSPENDED: return "in_progress"; | 41 case OPERATION_SUSPENDED: return "in_progress"; |
42 } | 42 } |
43 NOTREACHED(); | 43 NOTREACHED(); |
44 return "unknown_transfer_state"; | 44 return "unknown_transfer_state"; |
45 } | 45 } |
46 | 46 |
47 GDataOperationRegistry::ProgressStatus::ProgressStatus(OperationType type, | 47 OperationRegistry::ProgressStatus::ProgressStatus(OperationType type, |
48 const FilePath& path) | 48 const FilePath& path) |
49 : operation_id(-1), | 49 : operation_id(-1), |
50 operation_type(type), | 50 operation_type(type), |
51 file_path(path), | 51 file_path(path), |
52 transfer_state(OPERATION_NOT_STARTED), | 52 transfer_state(OPERATION_NOT_STARTED), |
53 progress_current(0), | 53 progress_current(0), |
54 progress_total(-1) { | 54 progress_total(-1) { |
55 } | 55 } |
56 | 56 |
57 std::string GDataOperationRegistry::ProgressStatus::DebugString() const { | 57 std::string OperationRegistry::ProgressStatus::DebugString() const { |
58 std::string str; | 58 std::string str; |
59 str += "id="; | 59 str += "id="; |
60 str += base::IntToString(operation_id); | 60 str += base::IntToString(operation_id); |
61 str += " type="; | 61 str += " type="; |
62 str += OperationTypeToString(operation_type); | 62 str += OperationTypeToString(operation_type); |
63 str += " path="; | 63 str += " path="; |
64 str += file_path.AsUTF8Unsafe(); | 64 str += file_path.AsUTF8Unsafe(); |
65 str += " state="; | 65 str += " state="; |
66 str += OperationTransferStateToString(transfer_state); | 66 str += OperationTransferStateToString(transfer_state); |
67 str += " progress="; | 67 str += " progress="; |
68 str += base::Int64ToString(progress_current); | 68 str += base::Int64ToString(progress_current); |
69 str += "/"; | 69 str += "/"; |
70 str += base::Int64ToString(progress_total); | 70 str += base::Int64ToString(progress_total); |
71 return str; | 71 return str; |
72 } | 72 } |
73 | 73 |
74 GDataOperationRegistry::Operation::Operation(GDataOperationRegistry* registry) | 74 OperationRegistry::Operation::Operation(OperationRegistry* registry) |
75 : registry_(registry), | 75 : registry_(registry), |
76 progress_status_(GDataOperationRegistry::OPERATION_OTHER, FilePath()) { | 76 progress_status_(OperationRegistry::OPERATION_OTHER, FilePath()) { |
77 } | 77 } |
78 | 78 |
79 GDataOperationRegistry::Operation::Operation(GDataOperationRegistry* registry, | 79 OperationRegistry::Operation::Operation(OperationRegistry* registry, |
80 OperationType type, | 80 OperationType type, |
81 const FilePath& path) | 81 const FilePath& path) |
82 : registry_(registry), | 82 : registry_(registry), |
83 progress_status_(type, path) { | 83 progress_status_(type, path) { |
84 } | 84 } |
85 | 85 |
86 GDataOperationRegistry::Operation::~Operation() { | 86 OperationRegistry::Operation::~Operation() { |
87 DCHECK(progress_status_.transfer_state == OPERATION_COMPLETED || | 87 DCHECK(progress_status_.transfer_state == OPERATION_COMPLETED || |
88 progress_status_.transfer_state == OPERATION_SUSPENDED || | 88 progress_status_.transfer_state == OPERATION_SUSPENDED || |
89 progress_status_.transfer_state == OPERATION_FAILED); | 89 progress_status_.transfer_state == OPERATION_FAILED); |
90 } | 90 } |
91 | 91 |
92 void GDataOperationRegistry::Operation::Cancel() { | 92 void OperationRegistry::Operation::Cancel() { |
93 DoCancel(); | 93 DoCancel(); |
94 NotifyFinish(OPERATION_FAILED); | 94 NotifyFinish(OPERATION_FAILED); |
95 } | 95 } |
96 | 96 |
97 void GDataOperationRegistry::Operation::NotifyStart() { | 97 void OperationRegistry::Operation::NotifyStart() { |
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
99 // Some operations may be restarted. Report only the first "start". | 99 // Some operations may be restarted. Report only the first "start". |
100 if (progress_status_.transfer_state == OPERATION_NOT_STARTED) { | 100 if (progress_status_.transfer_state == OPERATION_NOT_STARTED) { |
101 progress_status_.transfer_state = OPERATION_STARTED; | 101 progress_status_.transfer_state = OPERATION_STARTED; |
102 progress_status_.start_time = base::Time::Now(); | 102 progress_status_.start_time = base::Time::Now(); |
103 registry_->OnOperationStart(this, &progress_status_.operation_id); | 103 registry_->OnOperationStart(this, &progress_status_.operation_id); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 void GDataOperationRegistry::Operation::NotifyProgress( | 107 void OperationRegistry::Operation::NotifyProgress( |
108 int64 current, int64 total) { | 108 int64 current, int64 total) { |
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
110 DCHECK(progress_status_.transfer_state >= OPERATION_STARTED); | 110 DCHECK(progress_status_.transfer_state >= OPERATION_STARTED); |
111 progress_status_.transfer_state = OPERATION_IN_PROGRESS; | 111 progress_status_.transfer_state = OPERATION_IN_PROGRESS; |
112 progress_status_.progress_current = current; | 112 progress_status_.progress_current = current; |
113 progress_status_.progress_total = total; | 113 progress_status_.progress_total = total; |
114 registry_->OnOperationProgress(progress_status().operation_id); | 114 registry_->OnOperationProgress(progress_status().operation_id); |
115 } | 115 } |
116 | 116 |
117 void GDataOperationRegistry::Operation::NotifyFinish( | 117 void OperationRegistry::Operation::NotifyFinish( |
118 OperationTransferState status) { | 118 OperationTransferState status) { |
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
120 DCHECK(progress_status_.transfer_state >= OPERATION_STARTED); | 120 DCHECK(progress_status_.transfer_state >= OPERATION_STARTED); |
121 DCHECK(status == OPERATION_COMPLETED || status == OPERATION_FAILED); | 121 DCHECK(status == OPERATION_COMPLETED || status == OPERATION_FAILED); |
122 progress_status_.transfer_state = status; | 122 progress_status_.transfer_state = status; |
123 registry_->OnOperationFinish(progress_status().operation_id); | 123 registry_->OnOperationFinish(progress_status().operation_id); |
124 } | 124 } |
125 | 125 |
126 void GDataOperationRegistry::Operation::NotifySuspend() { | 126 void OperationRegistry::Operation::NotifySuspend() { |
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
128 DCHECK(progress_status_.transfer_state >= OPERATION_STARTED); | 128 DCHECK(progress_status_.transfer_state >= OPERATION_STARTED); |
129 progress_status_.transfer_state = OPERATION_SUSPENDED; | 129 progress_status_.transfer_state = OPERATION_SUSPENDED; |
130 registry_->OnOperationSuspend(progress_status().operation_id); | 130 registry_->OnOperationSuspend(progress_status().operation_id); |
131 } | 131 } |
132 | 132 |
133 void GDataOperationRegistry::Operation::NotifyResume() { | 133 void OperationRegistry::Operation::NotifyResume() { |
134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
135 if (progress_status_.transfer_state == OPERATION_NOT_STARTED) { | 135 if (progress_status_.transfer_state == OPERATION_NOT_STARTED) { |
136 progress_status_.transfer_state = OPERATION_IN_PROGRESS; | 136 progress_status_.transfer_state = OPERATION_IN_PROGRESS; |
137 registry_->OnOperationResume(this, &progress_status_); | 137 registry_->OnOperationResume(this, &progress_status_); |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 void GDataOperationRegistry::Operation::NotifyAuthFailed() { | 141 void OperationRegistry::Operation::NotifyAuthFailed() { |
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
143 registry_->OnOperationAuthFailed(); | 143 registry_->OnOperationAuthFailed(); |
144 } | 144 } |
145 | 145 |
146 GDataOperationRegistry::GDataOperationRegistry() | 146 OperationRegistry::OperationRegistry() |
147 : do_notification_frequency_control_(true) { | 147 : do_notification_frequency_control_(true) { |
148 in_flight_operations_.set_check_on_null_data(true); | 148 in_flight_operations_.set_check_on_null_data(true); |
149 } | 149 } |
150 | 150 |
151 GDataOperationRegistry::~GDataOperationRegistry() { | 151 OperationRegistry::~OperationRegistry() { |
152 DCHECK(in_flight_operations_.IsEmpty()); | 152 DCHECK(in_flight_operations_.IsEmpty()); |
153 } | 153 } |
154 | 154 |
155 void GDataOperationRegistry::AddObserver(Observer* observer) { | 155 void OperationRegistry::AddObserver(Observer* observer) { |
156 observer_list_.AddObserver(observer); | 156 observer_list_.AddObserver(observer); |
157 } | 157 } |
158 | 158 |
159 void GDataOperationRegistry::RemoveObserver(Observer* observer) { | 159 void OperationRegistry::RemoveObserver(Observer* observer) { |
160 observer_list_.RemoveObserver(observer); | 160 observer_list_.RemoveObserver(observer); |
161 } | 161 } |
162 | 162 |
163 void GDataOperationRegistry::DisableNotificationFrequencyControlForTest() { | 163 void OperationRegistry::DisableNotificationFrequencyControlForTest() { |
164 do_notification_frequency_control_ = false; | 164 do_notification_frequency_control_ = false; |
165 } | 165 } |
166 | 166 |
167 void GDataOperationRegistry::CancelAll() { | 167 void OperationRegistry::CancelAll() { |
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
169 | 169 |
170 for (OperationIDMap::iterator iter(&in_flight_operations_); | 170 for (OperationIDMap::iterator iter(&in_flight_operations_); |
171 !iter.IsAtEnd(); | 171 !iter.IsAtEnd(); |
172 iter.Advance()) { | 172 iter.Advance()) { |
173 Operation* operation = iter.GetCurrentValue(); | 173 Operation* operation = iter.GetCurrentValue(); |
174 operation->Cancel(); | 174 operation->Cancel(); |
175 // Cancel() may immediately trigger OnOperationFinish and remove the | 175 // Cancel() may immediately trigger OnOperationFinish and remove the |
176 // operation from the map, but IDMap is designed to be safe on such remove | 176 // operation from the map, but IDMap is designed to be safe on such remove |
177 // while iteration. | 177 // while iteration. |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 bool GDataOperationRegistry::CancelForFilePath(const FilePath& file_path) { | 181 bool OperationRegistry::CancelForFilePath(const FilePath& file_path) { |
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
183 | 183 |
184 for (OperationIDMap::iterator iter(&in_flight_operations_); | 184 for (OperationIDMap::iterator iter(&in_flight_operations_); |
185 !iter.IsAtEnd(); | 185 !iter.IsAtEnd(); |
186 iter.Advance()) { | 186 iter.Advance()) { |
187 Operation* operation = iter.GetCurrentValue(); | 187 Operation* operation = iter.GetCurrentValue(); |
188 if (operation->progress_status().file_path == file_path) { | 188 if (operation->progress_status().file_path == file_path) { |
189 operation->Cancel(); | 189 operation->Cancel(); |
190 return true; | 190 return true; |
191 } | 191 } |
192 } | 192 } |
193 return false; | 193 return false; |
194 } | 194 } |
195 | 195 |
196 void GDataOperationRegistry::OnOperationStart( | 196 void OperationRegistry::OnOperationStart( |
197 GDataOperationRegistry::Operation* operation, | 197 OperationRegistry::Operation* operation, |
198 OperationID* id) { | 198 OperationID* id) { |
199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
200 | 200 |
201 *id = in_flight_operations_.Add(operation); | 201 *id = in_flight_operations_.Add(operation); |
202 DVLOG(1) << "GDataOperation[" << *id << "] started."; | 202 DVLOG(1) << "GDataOperation[" << *id << "] started."; |
203 if (IsFileTransferOperation(operation)) | 203 if (IsFileTransferOperation(operation)) |
204 NotifyStatusToObservers(); | 204 NotifyStatusToObservers(); |
205 } | 205 } |
206 | 206 |
207 void GDataOperationRegistry::OnOperationProgress(OperationID id) { | 207 void OperationRegistry::OnOperationProgress(OperationID id) { |
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
209 | 209 |
210 Operation* operation = in_flight_operations_.Lookup(id); | 210 Operation* operation = in_flight_operations_.Lookup(id); |
211 DCHECK(operation); | 211 DCHECK(operation); |
212 | 212 |
213 DVLOG(1) << "GDataOperation[" << id << "] " | 213 DVLOG(1) << "GDataOperation[" << id << "] " |
214 << operation->progress_status().DebugString(); | 214 << operation->progress_status().DebugString(); |
215 if (IsFileTransferOperation(operation)) | 215 if (IsFileTransferOperation(operation)) |
216 NotifyStatusToObservers(); | 216 NotifyStatusToObservers(); |
217 } | 217 } |
218 | 218 |
219 void GDataOperationRegistry::OnOperationFinish(OperationID id) { | 219 void OperationRegistry::OnOperationFinish(OperationID id) { |
220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
221 | 221 |
222 Operation* operation = in_flight_operations_.Lookup(id); | 222 Operation* operation = in_flight_operations_.Lookup(id); |
223 DCHECK(operation); | 223 DCHECK(operation); |
224 | 224 |
225 DVLOG(1) << "GDataOperation[" << id << "] finished."; | 225 DVLOG(1) << "GDataOperation[" << id << "] finished."; |
226 if (IsFileTransferOperation(operation)) | 226 if (IsFileTransferOperation(operation)) |
227 NotifyStatusToObservers(); | 227 NotifyStatusToObservers(); |
228 in_flight_operations_.Remove(id); | 228 in_flight_operations_.Remove(id); |
229 } | 229 } |
230 | 230 |
231 void GDataOperationRegistry::OnOperationResume( | 231 void OperationRegistry::OnOperationResume( |
232 GDataOperationRegistry::Operation* operation, | 232 OperationRegistry::Operation* operation, |
233 GDataOperationRegistry::ProgressStatus* new_status) { | 233 OperationRegistry::ProgressStatus* new_status) { |
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
235 | 235 |
236 // Find the corresponding suspended task. | 236 // Find the corresponding suspended task. |
237 Operation* suspended = NULL; | 237 Operation* suspended = NULL; |
238 for (OperationIDMap::iterator iter(&in_flight_operations_); | 238 for (OperationIDMap::iterator iter(&in_flight_operations_); |
239 !iter.IsAtEnd(); | 239 !iter.IsAtEnd(); |
240 iter.Advance()) { | 240 iter.Advance()) { |
241 Operation* in_flight_operation = iter.GetCurrentValue(); | 241 Operation* in_flight_operation = iter.GetCurrentValue(); |
242 const ProgressStatus& status = in_flight_operation->progress_status(); | 242 const ProgressStatus& status = in_flight_operation->progress_status(); |
243 if (status.transfer_state == OPERATION_SUSPENDED && | 243 if (status.transfer_state == OPERATION_SUSPENDED && |
(...skipping 14 matching lines...) Expand all Loading... |
258 | 258 |
259 // Remove the old one and initiate the new operation. | 259 // Remove the old one and initiate the new operation. |
260 in_flight_operations_.Remove(old_id); | 260 in_flight_operations_.Remove(old_id); |
261 new_status->operation_id = in_flight_operations_.Add(operation); | 261 new_status->operation_id = in_flight_operations_.Add(operation); |
262 DVLOG(1) << "GDataOperation[" << old_id << " -> " << | 262 DVLOG(1) << "GDataOperation[" << old_id << " -> " << |
263 new_status->operation_id << "] resumed."; | 263 new_status->operation_id << "] resumed."; |
264 if (IsFileTransferOperation(operation)) | 264 if (IsFileTransferOperation(operation)) |
265 NotifyStatusToObservers(); | 265 NotifyStatusToObservers(); |
266 } | 266 } |
267 | 267 |
268 void GDataOperationRegistry::OnOperationSuspend(OperationID id) { | 268 void OperationRegistry::OnOperationSuspend(OperationID id) { |
269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
270 | 270 |
271 Operation* operation = in_flight_operations_.Lookup(id); | 271 Operation* operation = in_flight_operations_.Lookup(id); |
272 DCHECK(operation); | 272 DCHECK(operation); |
273 | 273 |
274 DVLOG(1) << "GDataOperation[" << id << "] suspended."; | 274 DVLOG(1) << "GDataOperation[" << id << "] suspended."; |
275 if (IsFileTransferOperation(operation)) | 275 if (IsFileTransferOperation(operation)) |
276 NotifyStatusToObservers(); | 276 NotifyStatusToObservers(); |
277 } | 277 } |
278 | 278 |
279 void GDataOperationRegistry::OnOperationAuthFailed() { | 279 void OperationRegistry::OnOperationAuthFailed() { |
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
281 | 281 |
282 DVLOG(1) << "GDataOperation authentication failed."; | 282 DVLOG(1) << "GDataOperation authentication failed."; |
283 FOR_EACH_OBSERVER(Observer, observer_list_, OnAuthenticationFailed()); | 283 FOR_EACH_OBSERVER(Observer, observer_list_, OnAuthenticationFailed()); |
284 } | 284 } |
285 | 285 |
286 bool GDataOperationRegistry::IsFileTransferOperation( | 286 bool OperationRegistry::IsFileTransferOperation( |
287 const Operation* operation) const { | 287 const Operation* operation) const { |
288 OperationType type = operation->progress_status().operation_type; | 288 OperationType type = operation->progress_status().operation_type; |
289 return type == OPERATION_UPLOAD || type == OPERATION_DOWNLOAD; | 289 return type == OPERATION_UPLOAD || type == OPERATION_DOWNLOAD; |
290 } | 290 } |
291 | 291 |
292 GDataOperationRegistry::ProgressStatusList | 292 OperationRegistry::ProgressStatusList |
293 GDataOperationRegistry::GetProgressStatusList() { | 293 OperationRegistry::GetProgressStatusList() { |
294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
295 | 295 |
296 ProgressStatusList status_list; | 296 ProgressStatusList status_list; |
297 for (OperationIDMap::const_iterator iter(&in_flight_operations_); | 297 for (OperationIDMap::const_iterator iter(&in_flight_operations_); |
298 !iter.IsAtEnd(); | 298 !iter.IsAtEnd(); |
299 iter.Advance()) { | 299 iter.Advance()) { |
300 const Operation* operation = iter.GetCurrentValue(); | 300 const Operation* operation = iter.GetCurrentValue(); |
301 if (IsFileTransferOperation(operation)) | 301 if (IsFileTransferOperation(operation)) |
302 status_list.push_back(operation->progress_status()); | 302 status_list.push_back(operation->progress_status()); |
303 } | 303 } |
304 return status_list; | 304 return status_list; |
305 } | 305 } |
306 | 306 |
307 bool GDataOperationRegistry::ShouldNotifyStatusNow( | 307 bool OperationRegistry::ShouldNotifyStatusNow( |
308 const ProgressStatusList& list) { | 308 const ProgressStatusList& list) { |
309 if (!do_notification_frequency_control_) | 309 if (!do_notification_frequency_control_) |
310 return true; | 310 return true; |
311 | 311 |
312 base::Time now = base::Time::Now(); | 312 base::Time now = base::Time::Now(); |
313 | 313 |
314 // If it is a first event, or some time abnormality is detected, we should | 314 // If it is a first event, or some time abnormality is detected, we should |
315 // not skip this notification. | 315 // not skip this notification. |
316 if (last_notification_.is_null() || now < last_notification_) { | 316 if (last_notification_.is_null() || now < last_notification_) { |
317 last_notification_ = now; | 317 last_notification_ = now; |
(...skipping 14 matching lines...) Expand all Loading... |
332 if (list[i].transfer_state != OPERATION_IN_PROGRESS) { | 332 if (list[i].transfer_state != OPERATION_IN_PROGRESS) { |
333 last_notification_ = now; | 333 last_notification_ = now; |
334 return true; | 334 return true; |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 // Otherwise we can skip it. | 338 // Otherwise we can skip it. |
339 return false; | 339 return false; |
340 } | 340 } |
341 | 341 |
342 void GDataOperationRegistry::NotifyStatusToObservers() { | 342 void OperationRegistry::NotifyStatusToObservers() { |
343 ProgressStatusList list(GetProgressStatusList()); | 343 ProgressStatusList list(GetProgressStatusList()); |
344 if (ShouldNotifyStatusNow(list)) | 344 if (ShouldNotifyStatusNow(list)) |
345 FOR_EACH_OBSERVER(Observer, observer_list_, OnProgressUpdate(list)); | 345 FOR_EACH_OBSERVER(Observer, observer_list_, OnProgressUpdate(list)); |
346 } | 346 } |
347 | 347 |
348 } // namespace gdata | 348 } // namespace gdata |
OLD | NEW |