OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/offline_pages/offline_page_model.h" | 5 #include "components/offline_pages/offline_page_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 void OfflinePageModel::HasPages(const std::string& name_space, | 273 void OfflinePageModel::HasPages(const std::string& name_space, |
274 const HasPagesCallback& callback) { | 274 const HasPagesCallback& callback) { |
275 RunWhenLoaded(base::Bind(&OfflinePageModel::HasPagesAfterLoadDone, | 275 RunWhenLoaded(base::Bind(&OfflinePageModel::HasPagesAfterLoadDone, |
276 weak_ptr_factory_.GetWeakPtr(), name_space, | 276 weak_ptr_factory_.GetWeakPtr(), name_space, |
277 callback)); | 277 callback)); |
278 } | 278 } |
279 | 279 |
280 void OfflinePageModel::HasPagesAfterLoadDone( | 280 void OfflinePageModel::HasPagesAfterLoadDone( |
281 const std::string& name_space, | 281 const std::string& name_space, |
282 const HasPagesCallback& callback) const { | 282 const HasPagesCallback& callback) const { |
283 callback.Run(MaybeHasPages(name_space)); | 283 DCHECK(is_loaded_); |
284 } | |
285 | 284 |
286 bool OfflinePageModel::MaybeHasPages(const std::string& name_space) const { | 285 bool has_pages = false; |
287 if (!is_loaded_) | |
288 return false; | |
289 | 286 |
290 for (const auto& id_page_pair : offline_pages_) { | 287 for (const auto& id_page_pair : offline_pages_) { |
291 if (id_page_pair.second.client_id.name_space == name_space) | 288 if (id_page_pair.second.client_id.name_space == name_space) { |
292 return true; | 289 has_pages = true; |
290 break; | |
291 } | |
293 } | 292 } |
294 | 293 |
295 return false; | 294 callback.Run(has_pages); |
296 } | 295 } |
297 | 296 |
298 void OfflinePageModel::GetAllPages(const GetAllPagesCallback& callback) { | 297 void OfflinePageModel::GetAllPages(const GetAllPagesCallback& callback) { |
299 if (!is_loaded_) { | 298 if (!is_loaded_) { |
300 delayed_tasks_.push_back( | 299 delayed_tasks_.push_back( |
301 base::Bind(&OfflinePageModel::GetAllPagesAfterLoadDone, | 300 base::Bind(&OfflinePageModel::GetAllPagesAfterLoadDone, |
302 weak_ptr_factory_.GetWeakPtr(), callback)); | 301 weak_ptr_factory_.GetWeakPtr(), callback)); |
303 return; | 302 return; |
304 } | 303 } |
305 | 304 |
306 GetAllPagesAfterLoadDone(callback); | 305 GetAllPagesAfterLoadDone(callback); |
307 } | 306 } |
308 | 307 |
309 void OfflinePageModel::GetAllPagesAfterLoadDone( | 308 void OfflinePageModel::GetAllPagesAfterLoadDone( |
310 const GetAllPagesCallback& callback) { | 309 const GetAllPagesCallback& callback) { |
311 DCHECK(is_loaded_); | 310 DCHECK(is_loaded_); |
312 | 311 |
313 std::vector<OfflinePageItem> offline_pages; | 312 std::vector<OfflinePageItem> offline_pages; |
314 for (const auto& id_page_pair : offline_pages_) | 313 for (const auto& id_page_pair : offline_pages_) |
315 offline_pages.push_back(id_page_pair.second); | 314 offline_pages.push_back(id_page_pair.second); |
316 | 315 |
317 callback.Run(offline_pages); | 316 callback.Run(offline_pages); |
318 } | 317 } |
319 | 318 |
320 const std::vector<OfflinePageItem> OfflinePageModel::GetPagesToCleanUp() const { | 319 const std::vector<OfflinePageItem> OfflinePageModel::GetPagesToCleanUp() const { |
jianli
2016/04/25 22:41:31
Do we also need to remove this?
dewittj
2016/04/25 22:56:55
I have been leaving things like this and markpagea
fgorski
2016/04/26 03:20:50
Put a TODO(fgorski): This needs an update as part
dewittj
2016/04/26 16:24:01
Done.
| |
321 DCHECK(is_loaded_); | 320 DCHECK(is_loaded_); |
322 std::vector<OfflinePageItem> offline_pages; | 321 std::vector<OfflinePageItem> offline_pages; |
323 base::Time now = base::Time::Now(); | 322 base::Time now = base::Time::Now(); |
324 for (const auto& id_page_pair : offline_pages_) { | 323 for (const auto& id_page_pair : offline_pages_) { |
325 if (now - id_page_pair.second.last_access_time > kPageCleanUpThreshold) | 324 if (now - id_page_pair.second.last_access_time > kPageCleanUpThreshold) |
326 offline_pages.push_back(id_page_pair.second); | 325 offline_pages.push_back(id_page_pair.second); |
327 } | 326 } |
328 return offline_pages; | 327 return offline_pages; |
329 } | 328 } |
330 | 329 |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { | 697 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { |
699 if (!is_loaded_) { | 698 if (!is_loaded_) { |
700 delayed_tasks_.push_back(task); | 699 delayed_tasks_.push_back(task); |
701 return; | 700 return; |
702 } | 701 } |
703 | 702 |
704 task_runner_->PostTask(FROM_HERE, task); | 703 task_runner_->PostTask(FROM_HERE, task); |
705 } | 704 } |
706 | 705 |
707 } // namespace offline_pages | 706 } // namespace offline_pages |
OLD | NEW |