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

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

Issue 1947323002: [Offline Pages] Implement OfflinePageStorageManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix rebasing Created 4 years, 7 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 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"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/optional.h" 15 #include "base/optional.h"
16 #include "base/rand_util.h" 16 #include "base/rand_util.h"
17 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "components/offline_pages/client_policy_controller.h"
21 #include "components/offline_pages/offline_page_item.h" 22 #include "components/offline_pages/offline_page_item.h"
23 #include "components/offline_pages/offline_page_storage_manager.h"
22 #include "components/offline_pages/proto/offline_pages.pb.h" 24 #include "components/offline_pages/proto/offline_pages.pb.h"
23 #include "url/gurl.h" 25 #include "url/gurl.h"
24 26
25 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult; 27 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult;
26 using SavePageResult = offline_pages::OfflinePageModel::SavePageResult; 28 using SavePageResult = offline_pages::OfflinePageModel::SavePageResult;
27 29
28 namespace offline_pages { 30 namespace offline_pages {
29 31
30 namespace { 32 namespace {
31 33
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 CHECK(base::CreateDirectory(archives_dir)); 105 CHECK(base::CreateDirectory(archives_dir));
104 } 106 }
105 107
106 } // namespace 108 } // namespace
107 109
108 // static 110 // static
109 bool OfflinePageModel::CanSavePage(const GURL& url) { 111 bool OfflinePageModel::CanSavePage(const GURL& url) {
110 return url.SchemeIsHTTPOrHTTPS(); 112 return url.SchemeIsHTTPOrHTTPS();
111 } 113 }
112 114
115 // protected
116 OfflinePageModel::OfflinePageModel()
117 : is_loaded_(false), weak_ptr_factory_(this) {}
118
113 OfflinePageModel::OfflinePageModel( 119 OfflinePageModel::OfflinePageModel(
114 std::unique_ptr<OfflinePageMetadataStore> store, 120 std::unique_ptr<OfflinePageMetadataStore> store,
115 const base::FilePath& archives_dir, 121 const base::FilePath& archives_dir,
116 const scoped_refptr<base::SequencedTaskRunner>& task_runner) 122 const scoped_refptr<base::SequencedTaskRunner>& task_runner)
117 : store_(std::move(store)), 123 : store_(std::move(store)),
118 archives_dir_(archives_dir), 124 archives_dir_(archives_dir),
119 is_loaded_(false), 125 is_loaded_(false),
120 task_runner_(task_runner), 126 task_runner_(task_runner),
127 policy_controller_(new ClientPolicyController()),
128 storage_manager_(new OfflinePageStorageManager(this)),
121 weak_ptr_factory_(this) { 129 weak_ptr_factory_(this) {
122 task_runner_->PostTaskAndReply( 130 task_runner_->PostTaskAndReply(
123 FROM_HERE, base::Bind(EnsureArchivesDirCreated, archives_dir_), 131 FROM_HERE, base::Bind(EnsureArchivesDirCreated, archives_dir_),
124 base::Bind(&OfflinePageModel::OnEnsureArchivesDirCreatedDone, 132 base::Bind(&OfflinePageModel::OnEnsureArchivesDirCreatedDone,
125 weak_ptr_factory_.GetWeakPtr(), base::TimeTicks::Now())); 133 weak_ptr_factory_.GetWeakPtr(), base::TimeTicks::Now()));
126 } 134 }
127 135
128 OfflinePageModel::~OfflinePageModel() { 136 OfflinePageModel::~OfflinePageModel() {
129 } 137 }
130 138
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 // of total free space includes space taken by offline pages. 501 // of total free space includes space taken by offline pages.
494 if (reporting_after_delete && free_space_bytes > 0) { 502 if (reporting_after_delete && free_space_bytes > 0) {
495 int percentage_of_free = static_cast<int>( 503 int percentage_of_free = static_cast<int>(
496 1.0 * total_page_size / (total_page_size + free_space_bytes) * 100); 504 1.0 * total_page_size / (total_page_size + free_space_bytes) * 100);
497 UMA_HISTOGRAM_PERCENTAGE( 505 UMA_HISTOGRAM_PERCENTAGE(
498 "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace", 506 "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace",
499 percentage_of_free); 507 percentage_of_free);
500 } 508 }
501 } 509 }
502 510
511 ClientPolicyController* OfflinePageModel::GetPolicyController() {
512 return policy_controller_.get();
513 }
514
503 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() { 515 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() {
504 return store_.get(); 516 return store_.get();
505 } 517 }
506 518
519 OfflinePageStorageManager* OfflinePageModel::GetStorageManager() {
520 return storage_manager_.get();
521 }
522
523 bool OfflinePageModel::is_loaded() const {
524 return is_loaded_;
525 }
526
507 void OfflinePageModel::OnCreateArchiveDone(const GURL& requested_url, 527 void OfflinePageModel::OnCreateArchiveDone(const GURL& requested_url,
508 int64_t offline_id, 528 int64_t offline_id,
509 const ClientId& client_id, 529 const ClientId& client_id,
510 const base::Time& start_time, 530 const base::Time& start_time,
511 const SavePageCallback& callback, 531 const SavePageCallback& callback,
512 OfflinePageArchiver* archiver, 532 OfflinePageArchiver* archiver,
513 ArchiverResult archiver_result, 533 ArchiverResult archiver_result,
514 const GURL& url, 534 const GURL& url,
515 const base::FilePath& file_path, 535 const base::FilePath& file_path,
516 int64_t file_size) { 536 int64_t file_size) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { 809 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) {
790 if (!is_loaded_) { 810 if (!is_loaded_) {
791 delayed_tasks_.push_back(task); 811 delayed_tasks_.push_back(task);
792 return; 812 return;
793 } 813 }
794 814
795 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 815 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
796 } 816 }
797 817
798 } // namespace offline_pages 818 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model.h ('k') | components/offline_pages/offline_page_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698