Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Side by Side Diff: components/offline_pages/offline_page_storage_manager.cc

Issue 2026843003: [Offline Pages] Removing client in storage manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Styles. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_storage_manager.h" 5 #include "components/offline_pages/offline_page_storage_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/time/clock.h" 10 #include "base/time/clock.h"
11 #include "base/time/default_clock.h" 11 #include "base/time/default_clock.h"
12 #include "components/offline_pages/client_policy_controller.h" 12 #include "components/offline_pages/client_policy_controller.h"
13 #include "components/offline_pages/offline_page_client_policy.h" 13 #include "components/offline_pages/offline_page_client_policy.h"
14 #include "components/offline_pages/offline_page_item.h" 14 #include "components/offline_pages/offline_page_item.h"
15 #include "components/offline_pages/offline_page_model.h"
15 16
16 namespace offline_pages { 17 namespace offline_pages {
17 18
18 OfflinePageStorageManager::OfflinePageStorageManager( 19 OfflinePageStorageManager::OfflinePageStorageManager(
19 Client* client, 20 OfflinePageModel* model,
20 ClientPolicyController* policy_controller, 21 ClientPolicyController* policy_controller,
21 ArchiveManager* archive_manager) 22 ArchiveManager* archive_manager)
22 : client_(client), 23 : model_(model),
23 policy_controller_(policy_controller), 24 policy_controller_(policy_controller),
24 archive_manager_(archive_manager), 25 archive_manager_(archive_manager),
25 clock_(new base::DefaultClock()), 26 clock_(new base::DefaultClock()),
26 weak_ptr_factory_(this) {} 27 weak_ptr_factory_(this) {}
27 28
28 OfflinePageStorageManager::~OfflinePageStorageManager() {} 29 OfflinePageStorageManager::~OfflinePageStorageManager() {}
29 30
30 void OfflinePageStorageManager::ClearPagesIfNeeded( 31 void OfflinePageStorageManager::ClearPagesIfNeeded(
31 const ClearStorageCallback& callback) { 32 const ClearStorageCallback& callback) {
32 if (IsInProgress()) 33 if (IsInProgress())
(...skipping 12 matching lines...) Expand all
45 void OfflinePageStorageManager::OnGetStorageStatsDoneForClearingPages( 46 void OfflinePageStorageManager::OnGetStorageStatsDoneForClearingPages(
46 const ClearStorageCallback& callback, 47 const ClearStorageCallback& callback,
47 const ArchiveManager::StorageStats& stats) { 48 const ArchiveManager::StorageStats& stats) {
48 DCHECK(IsInProgress()); 49 DCHECK(IsInProgress());
49 ClearMode mode = ShouldClearPages(stats); 50 ClearMode mode = ShouldClearPages(stats);
50 if (mode == ClearMode::NOT_NEEDED) { 51 if (mode == ClearMode::NOT_NEEDED) {
51 last_clear_time_ = clear_time_; 52 last_clear_time_ = clear_time_;
52 callback.Run(0, ClearStorageResult::UNNECESSARY); 53 callback.Run(0, ClearStorageResult::UNNECESSARY);
53 return; 54 return;
54 } 55 }
55 client_->GetAllPages( 56 model_->GetAllPages(
56 base::Bind(&OfflinePageStorageManager::OnGetAllPagesDoneForClearingPages, 57 base::Bind(&OfflinePageStorageManager::OnGetAllPagesDoneForClearingPages,
57 weak_ptr_factory_.GetWeakPtr(), callback, stats)); 58 weak_ptr_factory_.GetWeakPtr(), callback, stats));
58 } 59 }
59 60
60 void OfflinePageStorageManager::OnGetAllPagesDoneForClearingPages( 61 void OfflinePageStorageManager::OnGetAllPagesDoneForClearingPages(
61 const ClearStorageCallback& callback, 62 const ClearStorageCallback& callback,
62 const ArchiveManager::StorageStats& stats, 63 const ArchiveManager::StorageStats& stats,
63 const MultipleOfflinePageItemResult& pages) { 64 const MultipleOfflinePageItemResult& pages) {
64 std::vector<int64_t> page_ids_to_expire; 65 std::vector<int64_t> page_ids_to_expire;
65 std::vector<int64_t> page_ids_to_remove; 66 std::vector<int64_t> page_ids_to_remove;
66 GetPageIdsToClear(pages, stats, &page_ids_to_expire, &page_ids_to_remove); 67 GetPageIdsToClear(pages, stats, &page_ids_to_expire, &page_ids_to_remove);
67 client_->ExpirePages( 68 model_->ExpirePages(
68 page_ids_to_expire, clear_time_, 69 page_ids_to_expire, clear_time_,
69 base::Bind(&OfflinePageStorageManager::OnPagesExpired, 70 base::Bind(&OfflinePageStorageManager::OnPagesExpired,
70 weak_ptr_factory_.GetWeakPtr(), callback, 71 weak_ptr_factory_.GetWeakPtr(), callback,
71 page_ids_to_expire.size(), page_ids_to_remove)); 72 page_ids_to_expire.size(), page_ids_to_remove));
72 } 73 }
73 74
74 void OfflinePageStorageManager::OnPagesExpired( 75 void OfflinePageStorageManager::OnPagesExpired(
75 const ClearStorageCallback& callback, 76 const ClearStorageCallback& callback,
76 size_t pages_expired, 77 size_t pages_expired,
77 const std::vector<int64_t>& page_ids_to_remove, 78 const std::vector<int64_t>& page_ids_to_remove,
78 bool expiration_succeeded) { 79 bool expiration_succeeded) {
79 // We want to delete the outdated page records regardless the expiration 80 // We want to delete the outdated page records regardless the expiration
80 // succeeded or not. 81 // succeeded or not.
81 client_->DeletePagesByOfflineId( 82 model_->DeletePagesByOfflineId(
82 page_ids_to_remove, 83 page_ids_to_remove,
83 base::Bind(&OfflinePageStorageManager::OnOutdatedPagesCleared, 84 base::Bind(&OfflinePageStorageManager::OnOutdatedPagesCleared,
84 weak_ptr_factory_.GetWeakPtr(), callback, pages_expired, 85 weak_ptr_factory_.GetWeakPtr(), callback, pages_expired,
85 expiration_succeeded)); 86 expiration_succeeded));
86 } 87 }
87 88
88 void OfflinePageStorageManager::OnOutdatedPagesCleared( 89 void OfflinePageStorageManager::OnOutdatedPagesCleared(
89 const ClearStorageCallback& callback, 90 const ClearStorageCallback& callback,
90 size_t pages_cleared, 91 size_t pages_cleared,
91 bool expiration_succeeded, 92 bool expiration_succeeded,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 const LifetimePolicy& policy = 201 const LifetimePolicy& policy =
201 policy_controller_->GetPolicy(page.client_id.name_space).lifetime_policy; 202 policy_controller_->GetPolicy(page.client_id.name_space).lifetime_policy;
202 return clear_time_ - page.last_access_time >= policy.expiration_period; 203 return clear_time_ - page.last_access_time >= policy.expiration_period;
203 } 204 }
204 205
205 bool OfflinePageStorageManager::IsInProgress() const { 206 bool OfflinePageStorageManager::IsInProgress() const {
206 return clear_time_ > last_clear_time_; 207 return clear_time_ > last_clear_time_;
207 } 208 }
208 209
209 } // namespace offline_pages 210 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698