Chromium Code Reviews| 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" |
| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 } | 110 } |
| 109 | 111 |
| 110 OfflinePageModel::OfflinePageModel( | 112 OfflinePageModel::OfflinePageModel( |
| 111 std::unique_ptr<OfflinePageMetadataStore> store, | 113 std::unique_ptr<OfflinePageMetadataStore> store, |
| 112 const base::FilePath& archives_dir, | 114 const base::FilePath& archives_dir, |
| 113 const scoped_refptr<base::SequencedTaskRunner>& task_runner) | 115 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
| 114 : store_(std::move(store)), | 116 : store_(std::move(store)), |
| 115 archives_dir_(archives_dir), | 117 archives_dir_(archives_dir), |
| 116 is_loaded_(false), | 118 is_loaded_(false), |
| 117 task_runner_(task_runner), | 119 task_runner_(task_runner), |
| 120 policy_controller_(std::move(new ClientPolicyController())), | |
|
fgorski
2016/05/06 05:57:24
I don't think you need std::move here. unique poin
romax
2016/05/07 02:22:42
Done.
| |
| 121 storage_manager_(std::move(new OfflinePageStorageManager(this))), | |
|
fgorski
2016/05/06 05:57:24
same
romax
2016/05/07 02:22:42
Done.
| |
| 118 weak_ptr_factory_(this) { | 122 weak_ptr_factory_(this) { |
| 119 task_runner_->PostTaskAndReply( | 123 task_runner_->PostTaskAndReply( |
| 120 FROM_HERE, base::Bind(EnsureArchivesDirCreated, archives_dir_), | 124 FROM_HERE, base::Bind(EnsureArchivesDirCreated, archives_dir_), |
| 121 base::Bind(&OfflinePageModel::OnEnsureArchivesDirCreatedDone, | 125 base::Bind(&OfflinePageModel::OnEnsureArchivesDirCreatedDone, |
| 122 weak_ptr_factory_.GetWeakPtr())); | 126 weak_ptr_factory_.GetWeakPtr())); |
| 123 } | 127 } |
| 124 | 128 |
| 125 OfflinePageModel::~OfflinePageModel() { | 129 OfflinePageModel::~OfflinePageModel() { |
| 126 } | 130 } |
| 127 | 131 |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 // of total free space includes space taken by offline pages. | 494 // of total free space includes space taken by offline pages. |
| 491 if (reporting_after_delete && free_space_bytes > 0) { | 495 if (reporting_after_delete && free_space_bytes > 0) { |
| 492 int percentage_of_free = static_cast<int>( | 496 int percentage_of_free = static_cast<int>( |
| 493 1.0 * total_page_size / (total_page_size + free_space_bytes) * 100); | 497 1.0 * total_page_size / (total_page_size + free_space_bytes) * 100); |
| 494 UMA_HISTOGRAM_PERCENTAGE( | 498 UMA_HISTOGRAM_PERCENTAGE( |
| 495 "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace", | 499 "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace", |
| 496 percentage_of_free); | 500 percentage_of_free); |
| 497 } | 501 } |
| 498 } | 502 } |
| 499 | 503 |
| 504 ClientPolicyController* OfflinePageModel::GetPolicyController() { | |
| 505 return policy_controller_.get(); | |
| 506 } | |
| 507 | |
| 500 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() { | 508 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() { |
| 501 return store_.get(); | 509 return store_.get(); |
| 502 } | 510 } |
| 503 | 511 |
| 512 OfflinePageStorageManager* OfflinePageModel::GetStorageManager() { | |
| 513 return storage_manager_.get(); | |
| 514 } | |
| 515 | |
| 504 void OfflinePageModel::OnCreateArchiveDone(const GURL& requested_url, | 516 void OfflinePageModel::OnCreateArchiveDone(const GURL& requested_url, |
| 505 int64_t offline_id, | 517 int64_t offline_id, |
| 506 const ClientId& client_id, | 518 const ClientId& client_id, |
| 507 const base::Time& start_time, | 519 const base::Time& start_time, |
| 508 const SavePageCallback& callback, | 520 const SavePageCallback& callback, |
| 509 OfflinePageArchiver* archiver, | 521 OfflinePageArchiver* archiver, |
| 510 ArchiverResult archiver_result, | 522 ArchiverResult archiver_result, |
| 511 const GURL& url, | 523 const GURL& url, |
| 512 const base::FilePath& file_path, | 524 const base::FilePath& file_path, |
| 513 int64_t file_size) { | 525 int64_t file_size) { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { | 790 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { |
| 779 if (!is_loaded_) { | 791 if (!is_loaded_) { |
| 780 delayed_tasks_.push_back(task); | 792 delayed_tasks_.push_back(task); |
| 781 return; | 793 return; |
| 782 } | 794 } |
| 783 | 795 |
| 784 task_runner_->PostTask(FROM_HERE, task); | 796 task_runner_->PostTask(FROM_HERE, task); |
| 785 } | 797 } |
| 786 | 798 |
| 787 } // namespace offline_pages | 799 } // namespace offline_pages |
| OLD | NEW |