| OLD | NEW |
| 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_model_impl.h" | 5 #include "components/offline_pages/offline_page_model_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 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/rand_util.h" | 15 #include "base/rand_util.h" |
| 16 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "components/offline_pages/archive_manager.h" | 20 #include "components/offline_pages/archive_manager.h" |
| 21 #include "components/offline_pages/client_namespace_constants.h" | 21 #include "components/offline_pages/client_namespace_constants.h" |
| 22 #include "components/offline_pages/client_policy_controller.h" | 22 #include "components/offline_pages/client_policy_controller.h" |
| 23 #include "components/offline_pages/downloads/download_ui_adapter.h" |
| 23 #include "components/offline_pages/offline_page_item.h" | 24 #include "components/offline_pages/offline_page_item.h" |
| 24 #include "components/offline_pages/offline_page_storage_manager.h" | 25 #include "components/offline_pages/offline_page_storage_manager.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 27 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult; | 28 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult; |
| 28 using ClearStorageCallback = | 29 using ClearStorageCallback = |
| 29 offline_pages::OfflinePageStorageManager::ClearStorageCallback; | 30 offline_pages::OfflinePageStorageManager::ClearStorageCallback; |
| 30 using ClearStorageResult = | 31 using ClearStorageResult = |
| 31 offline_pages::OfflinePageStorageManager::ClearStorageResult; | 32 offline_pages::OfflinePageStorageManager::ClearStorageResult; |
| 32 | 33 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 OfflinePageModelImpl::OfflinePageModelImpl( | 250 OfflinePageModelImpl::OfflinePageModelImpl( |
| 250 std::unique_ptr<OfflinePageMetadataStore> store, | 251 std::unique_ptr<OfflinePageMetadataStore> store, |
| 251 const base::FilePath& archives_dir, | 252 const base::FilePath& archives_dir, |
| 252 const scoped_refptr<base::SequencedTaskRunner>& task_runner) | 253 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
| 253 : store_(std::move(store)), | 254 : store_(std::move(store)), |
| 254 archives_dir_(archives_dir), | 255 archives_dir_(archives_dir), |
| 255 is_loaded_(false), | 256 is_loaded_(false), |
| 256 policy_controller_(new ClientPolicyController()), | 257 policy_controller_(new ClientPolicyController()), |
| 257 archive_manager_(new ArchiveManager(archives_dir, task_runner)), | 258 archive_manager_(new ArchiveManager(archives_dir, task_runner)), |
| 258 weak_ptr_factory_(this) { | 259 weak_ptr_factory_(this) { |
| 260 download_ui_adapter_.reset(new DownloadUIAdapter(this)); |
| 259 archive_manager_->EnsureArchivesDirCreated( | 261 archive_manager_->EnsureArchivesDirCreated( |
| 260 base::Bind(&OfflinePageModelImpl::OnEnsureArchivesDirCreatedDone, | 262 base::Bind(&OfflinePageModelImpl::OnEnsureArchivesDirCreatedDone, |
| 261 weak_ptr_factory_.GetWeakPtr(), base::TimeTicks::Now())); | 263 weak_ptr_factory_.GetWeakPtr(), base::TimeTicks::Now())); |
| 262 } | 264 } |
| 263 | 265 |
| 264 OfflinePageModelImpl::~OfflinePageModelImpl() {} | 266 OfflinePageModelImpl::~OfflinePageModelImpl() {} |
| 265 | 267 |
| 266 void OfflinePageModelImpl::AddObserver(Observer* observer) { | 268 void OfflinePageModelImpl::AddObserver(Observer* observer) { |
| 267 observers_.AddObserver(observer); | 269 observers_.AddObserver(observer); |
| 268 } | 270 } |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 base::HistogramBase::kUmaTargetedHistogramFlag); | 678 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 677 histogram->Add( | 679 histogram->Add( |
| 678 (expiration_time - iter->second.last_access_time).InMinutes()); | 680 (expiration_time - iter->second.last_access_time).InMinutes()); |
| 679 } | 681 } |
| 680 } | 682 } |
| 681 | 683 |
| 682 ClientPolicyController* OfflinePageModelImpl::GetPolicyController() { | 684 ClientPolicyController* OfflinePageModelImpl::GetPolicyController() { |
| 683 return policy_controller_.get(); | 685 return policy_controller_.get(); |
| 684 } | 686 } |
| 685 | 687 |
| 688 DownloadUIAdapter* OfflinePageModelImpl::GetDownloadUIAdapter() { |
| 689 return download_ui_adapter_.get(); |
| 690 } |
| 691 |
| 686 OfflinePageMetadataStore* OfflinePageModelImpl::GetStoreForTesting() { | 692 OfflinePageMetadataStore* OfflinePageModelImpl::GetStoreForTesting() { |
| 687 return store_.get(); | 693 return store_.get(); |
| 688 } | 694 } |
| 689 | 695 |
| 690 OfflinePageStorageManager* OfflinePageModelImpl::GetStorageManager() { | 696 OfflinePageStorageManager* OfflinePageModelImpl::GetStorageManager() { |
| 691 return storage_manager_.get(); | 697 return storage_manager_.get(); |
| 692 } | 698 } |
| 693 | 699 |
| 694 bool OfflinePageModelImpl::is_loaded() const { | 700 bool OfflinePageModelImpl::is_loaded() const { |
| 695 return is_loaded_; | 701 return is_loaded_; |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1076 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
| 1071 if (!is_loaded_) { | 1077 if (!is_loaded_) { |
| 1072 delayed_tasks_.push_back(task); | 1078 delayed_tasks_.push_back(task); |
| 1073 return; | 1079 return; |
| 1074 } | 1080 } |
| 1075 | 1081 |
| 1076 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1082 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1077 } | 1083 } |
| 1078 | 1084 |
| 1079 } // namespace offline_pages | 1085 } // namespace offline_pages |
| OLD | NEW |