| 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/string16.h" | 17 #include "base/strings/string16.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "base/time/clock.h" |
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 21 #include "components/offline_pages/archive_manager.h" | 22 #include "components/offline_pages/archive_manager.h" |
| 22 #include "components/offline_pages/client_namespace_constants.h" | 23 #include "components/offline_pages/client_namespace_constants.h" |
| 23 #include "components/offline_pages/client_policy_controller.h" | 24 #include "components/offline_pages/client_policy_controller.h" |
| 24 #include "components/offline_pages/offline_page_item.h" | 25 #include "components/offline_pages/offline_page_item.h" |
| 25 #include "components/offline_pages/offline_page_storage_manager.h" | 26 #include "components/offline_pages/offline_page_storage_manager.h" |
| 26 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 27 | 28 |
| 28 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult; | 29 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult; |
| 29 using ClearStorageCallback = | 30 using ClearStorageCallback = |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // Note: The factory creates and owns the histogram. | 144 // Note: The factory creates and owns the histogram. |
| 144 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( | 145 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( |
| 145 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult"), | 146 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult"), |
| 146 1, | 147 1, |
| 147 static_cast<int>(SavePageResult::RESULT_COUNT), | 148 static_cast<int>(SavePageResult::RESULT_COUNT), |
| 148 static_cast<int>(SavePageResult::RESULT_COUNT) + 1, | 149 static_cast<int>(SavePageResult::RESULT_COUNT) + 1, |
| 149 base::HistogramBase::kUmaTargetedHistogramFlag); | 150 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 150 histogram->Add(static_cast<int>(result)); | 151 histogram->Add(static_cast<int>(result)); |
| 151 } | 152 } |
| 152 | 153 |
| 153 void ReportPageHistogramAfterSave(const OfflinePageItem& offline_page) { | 154 void ReportPageHistogramAfterSave(const OfflinePageItem& offline_page, |
| 155 const base::Time& save_time) { |
| 154 // The histogram below is an expansion of the UMA_HISTOGRAM_TIMES | 156 // The histogram below is an expansion of the UMA_HISTOGRAM_TIMES |
| 155 // macro adapted to allow for a dynamically suffixed histogram name. | 157 // macro adapted to allow for a dynamically suffixed histogram name. |
| 156 // Note: The factory creates and owns the histogram. | 158 // Note: The factory creates and owns the histogram. |
| 157 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( | 159 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( |
| 158 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"), | 160 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"), |
| 159 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), | 161 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), |
| 160 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 162 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
| 161 histogram->AddTime(base::Time::Now() - offline_page.creation_time); | 163 histogram->AddTime(save_time - offline_page.creation_time); |
| 162 | 164 |
| 163 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS | 165 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
| 164 // macro adapted to allow for a dynamically suffixed histogram name. | 166 // macro adapted to allow for a dynamically suffixed histogram name. |
| 165 // Note: The factory creates and owns the histogram. | 167 // Note: The factory creates and owns the histogram. |
| 166 // Reported as Kb between 1Kb and 10Mb. | 168 // Reported as Kb between 1Kb and 10Mb. |
| 167 histogram = base::Histogram::FactoryGet( | 169 histogram = base::Histogram::FactoryGet( |
| 168 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"), | 170 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"), |
| 169 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 171 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
| 170 histogram->Add(offline_page.file_size / 1024); | 172 histogram->Add(offline_page.file_size / 1024); |
| 171 } | 173 } |
| 172 | 174 |
| 173 void ReportPageHistogramsAfterDelete( | 175 void ReportPageHistogramsAfterDelete( |
| 174 const std::map<int64_t, OfflinePageItem>& offline_pages, | 176 const std::map<int64_t, OfflinePageItem>& offline_pages, |
| 175 const std::vector<int64_t>& deleted_offline_ids) { | 177 const std::vector<int64_t>& deleted_offline_ids, |
| 178 const base::Time& delete_time) { |
| 176 const int max_minutes = base::TimeDelta::FromDays(365).InMinutes(); | 179 const int max_minutes = base::TimeDelta::FromDays(365).InMinutes(); |
| 177 base::Time now = base::Time::Now(); | |
| 178 int64_t total_size = 0; | 180 int64_t total_size = 0; |
| 179 for (int64_t offline_id : deleted_offline_ids) { | 181 for (int64_t offline_id : deleted_offline_ids) { |
| 180 auto iter = offline_pages.find(offline_id); | 182 auto iter = offline_pages.find(offline_id); |
| 181 if (iter == offline_pages.end()) | 183 if (iter == offline_pages.end()) |
| 182 continue; | 184 continue; |
| 183 total_size += iter->second.file_size; | 185 total_size += iter->second.file_size; |
| 184 ClientId client_id = iter->second.client_id; | 186 ClientId client_id = iter->second.client_id; |
| 185 | 187 |
| 186 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS | 188 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
| 187 // macro adapted to allow for a dynamically suffixed histogram name. | 189 // macro adapted to allow for a dynamically suffixed histogram name. |
| 188 // Note: The factory creates and owns the histogram. | 190 // Note: The factory creates and owns the histogram. |
| 189 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 191 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
| 190 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), | 192 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), |
| 191 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); | 193 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); |
| 192 histogram->Add((now - iter->second.creation_time).InMinutes()); | 194 histogram->Add((delete_time - iter->second.creation_time).InMinutes()); |
| 193 | 195 |
| 194 histogram = base::Histogram::FactoryGet( | 196 histogram = base::Histogram::FactoryGet( |
| 195 AddHistogramSuffix( | 197 AddHistogramSuffix( |
| 196 client_id, "OfflinePages.DeletePage.TimeSinceLastOpen"), | 198 client_id, "OfflinePages.DeletePage.TimeSinceLastOpen"), |
| 197 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); | 199 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); |
| 198 histogram->Add((now - iter->second.last_access_time).InMinutes()); | 200 histogram->Add((delete_time - iter->second.last_access_time).InMinutes()); |
| 199 | 201 |
| 200 histogram = base::Histogram::FactoryGet( | 202 histogram = base::Histogram::FactoryGet( |
| 201 AddHistogramSuffix( | 203 AddHistogramSuffix( |
| 202 client_id, "OfflinePages.DeletePage.LastOpenToCreated"), | 204 client_id, "OfflinePages.DeletePage.LastOpenToCreated"), |
| 203 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); | 205 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); |
| 204 histogram->Add( | 206 histogram->Add( |
| 205 (iter->second.last_access_time - iter->second.creation_time). | 207 (iter->second.last_access_time - iter->second.creation_time). |
| 206 InMinutes()); | 208 InMinutes()); |
| 207 | 209 |
| 208 // Reported as Kb between 1Kb and 10Mb. | 210 // Reported as Kb between 1Kb and 10Mb. |
| 209 histogram = base::Histogram::FactoryGet( | 211 histogram = base::Histogram::FactoryGet( |
| 210 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize"), | 212 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize"), |
| 211 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 213 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
| 212 histogram->Add(iter->second.file_size / 1024); | 214 histogram->Add(iter->second.file_size / 1024); |
| 213 | 215 |
| 214 histogram = base::Histogram::FactoryGet( | 216 histogram = base::Histogram::FactoryGet( |
| 215 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount"), | 217 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount"), |
| 216 1, 1000000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 218 1, 1000000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
| 217 histogram->Add(iter->second.access_count); | 219 histogram->Add(iter->second.access_count); |
| 218 } | 220 } |
| 219 | 221 |
| 220 if (deleted_offline_ids.size() > 1) { | 222 if (deleted_offline_ids.size() > 1) { |
| 221 UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count", | 223 UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count", |
| 222 static_cast<int32_t>(deleted_offline_ids.size())); | 224 static_cast<int32_t>(deleted_offline_ids.size())); |
| 223 UMA_HISTOGRAM_MEMORY_KB( | 225 UMA_HISTOGRAM_MEMORY_KB( |
| 224 "OfflinePages.BatchDelete.TotalPageSize", total_size / 1024); | 226 "OfflinePages.BatchDelete.TotalPageSize", total_size / 1024); |
| 225 } | 227 } |
| 226 } | 228 } |
| 227 | 229 |
| 228 void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item) { | 230 void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item, |
| 231 const base::Time& access_time) { |
| 229 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS | 232 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
| 230 // macro adapted to allow for a dynamically suffixed histogram name. | 233 // macro adapted to allow for a dynamically suffixed histogram name. |
| 231 // Note: The factory creates and owns the histogram. | 234 // Note: The factory creates and owns the histogram. |
| 232 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 235 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
| 233 AddHistogramSuffix( | 236 AddHistogramSuffix( |
| 234 offline_page_item.client_id, | 237 offline_page_item.client_id, |
| 235 offline_page_item.access_count == 0 ? | 238 offline_page_item.access_count == 0 ? |
| 236 "OfflinePages.FirstOpenSinceCreated" : | 239 "OfflinePages.FirstOpenSinceCreated" : |
| 237 "OfflinePages.OpenSinceLastOpen"), | 240 "OfflinePages.OpenSinceLastOpen"), |
| 238 1, kMaxOpenedPageHistogramBucket.InMinutes(), 50, | 241 1, kMaxOpenedPageHistogramBucket.InMinutes(), 50, |
| 239 base::HistogramBase::kUmaTargetedHistogramFlag); | 242 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 240 histogram->Add( | 243 histogram->Add( |
| 241 (base::Time::Now() - offline_page_item.last_access_time).InMinutes()); | 244 (access_time - offline_page_item.last_access_time).InMinutes()); |
| 242 } | 245 } |
| 243 | 246 |
| 244 } // namespace | 247 } // namespace |
| 245 | 248 |
| 246 // protected | 249 // protected |
| 247 OfflinePageModelImpl::OfflinePageModelImpl() | 250 OfflinePageModelImpl::OfflinePageModelImpl() |
| 248 : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {} | 251 : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {} |
| 249 | 252 |
| 250 OfflinePageModelImpl::OfflinePageModelImpl( | 253 OfflinePageModelImpl::OfflinePageModelImpl( |
| 251 std::unique_ptr<OfflinePageMetadataStore> store, | 254 std::unique_ptr<OfflinePageMetadataStore> store, |
| 252 const base::FilePath& archives_dir, | 255 const base::FilePath& archives_dir, |
| 253 const scoped_refptr<base::SequencedTaskRunner>& task_runner) | 256 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
| 254 : store_(std::move(store)), | 257 : store_(std::move(store)), |
| 255 archives_dir_(archives_dir), | 258 archives_dir_(archives_dir), |
| 256 is_loaded_(false), | 259 is_loaded_(false), |
| 257 policy_controller_(new ClientPolicyController()), | 260 policy_controller_(new ClientPolicyController()), |
| 258 archive_manager_(new ArchiveManager(archives_dir, task_runner)), | 261 archive_manager_(new ArchiveManager(archives_dir, task_runner)), |
| 262 testing_clock_(nullptr), |
| 259 weak_ptr_factory_(this) { | 263 weak_ptr_factory_(this) { |
| 260 archive_manager_->EnsureArchivesDirCreated( | 264 archive_manager_->EnsureArchivesDirCreated( |
| 261 base::Bind(&OfflinePageModelImpl::OnEnsureArchivesDirCreatedDone, | 265 base::Bind(&OfflinePageModelImpl::OnEnsureArchivesDirCreatedDone, |
| 262 weak_ptr_factory_.GetWeakPtr(), base::TimeTicks::Now())); | 266 weak_ptr_factory_.GetWeakPtr(), base::TimeTicks::Now())); |
| 263 } | 267 } |
| 264 | 268 |
| 265 OfflinePageModelImpl::~OfflinePageModelImpl() {} | 269 OfflinePageModelImpl::~OfflinePageModelImpl() {} |
| 266 | 270 |
| 267 void OfflinePageModelImpl::AddObserver(Observer* observer) { | 271 void OfflinePageModelImpl::AddObserver(Observer* observer) { |
| 268 observers_.AddObserver(observer); | 272 observers_.AddObserver(observer); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 296 } | 300 } |
| 297 | 301 |
| 298 // If we already have an offline id, use it. If not, generate one. | 302 // If we already have an offline id, use it. If not, generate one. |
| 299 if (proposed_offline_id == 0l) | 303 if (proposed_offline_id == 0l) |
| 300 proposed_offline_id = GenerateOfflineId(); | 304 proposed_offline_id = GenerateOfflineId(); |
| 301 | 305 |
| 302 archiver->CreateArchive( | 306 archiver->CreateArchive( |
| 303 archives_dir_, proposed_offline_id, | 307 archives_dir_, proposed_offline_id, |
| 304 base::Bind(&OfflinePageModelImpl::OnCreateArchiveDone, | 308 base::Bind(&OfflinePageModelImpl::OnCreateArchiveDone, |
| 305 weak_ptr_factory_.GetWeakPtr(), url, proposed_offline_id, | 309 weak_ptr_factory_.GetWeakPtr(), url, proposed_offline_id, |
| 306 client_id, base::Time::Now(), callback)); | 310 client_id, GetCurrentTime(), callback)); |
| 307 pending_archivers_.push_back(std::move(archiver)); | 311 pending_archivers_.push_back(std::move(archiver)); |
| 308 } | 312 } |
| 309 | 313 |
| 310 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) { | 314 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) { |
| 311 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::MarkPageAccessedWhenLoadDone, | 315 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::MarkPageAccessedWhenLoadDone, |
| 312 weak_ptr_factory_.GetWeakPtr(), offline_id)); | 316 weak_ptr_factory_.GetWeakPtr(), offline_id)); |
| 313 } | 317 } |
| 314 | 318 |
| 315 void OfflinePageModelImpl::MarkPageAccessedWhenLoadDone(int64_t offline_id) { | 319 void OfflinePageModelImpl::MarkPageAccessedWhenLoadDone(int64_t offline_id) { |
| 316 DCHECK(is_loaded_); | 320 DCHECK(is_loaded_); |
| 317 | 321 |
| 318 auto iter = offline_pages_.find(offline_id); | 322 auto iter = offline_pages_.find(offline_id); |
| 319 if (iter == offline_pages_.end() || iter->second.IsExpired()) | 323 if (iter == offline_pages_.end() || iter->second.IsExpired()) |
| 320 return; | 324 return; |
| 321 | 325 |
| 322 // Make a copy of the cached item and update it. The cached item should only | 326 // Make a copy of the cached item and update it. The cached item should only |
| 323 // be updated upon the successful store operation. | 327 // be updated upon the successful store operation. |
| 324 OfflinePageItem offline_page_item = iter->second; | 328 OfflinePageItem offline_page_item = iter->second; |
| 325 | 329 |
| 326 ReportPageHistogramsAfterAccess(offline_page_item); | 330 ReportPageHistogramsAfterAccess(offline_page_item, GetCurrentTime()); |
| 327 | 331 |
| 328 offline_page_item.last_access_time = base::Time::Now(); | 332 offline_page_item.last_access_time = GetCurrentTime(); |
| 329 offline_page_item.access_count++; | 333 offline_page_item.access_count++; |
| 330 | 334 |
| 331 store_->AddOrUpdateOfflinePage( | 335 store_->AddOrUpdateOfflinePage( |
| 332 offline_page_item, | 336 offline_page_item, |
| 333 base::Bind(&OfflinePageModelImpl::OnMarkPageAccesseDone, | 337 base::Bind(&OfflinePageModelImpl::OnMarkPageAccesseDone, |
| 334 weak_ptr_factory_.GetWeakPtr(), offline_page_item)); | 338 weak_ptr_factory_.GetWeakPtr(), offline_page_item)); |
| 335 } | 339 } |
| 336 | 340 |
| 337 void OfflinePageModelImpl::DeletePagesByOfflineId( | 341 void OfflinePageModelImpl::DeletePagesByOfflineId( |
| 338 const std::vector<int64_t>& offline_ids, | 342 const std::vector<int64_t>& offline_ids, |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 | 733 |
| 730 void OfflinePageModelImpl::OnAddOfflinePageDone( | 734 void OfflinePageModelImpl::OnAddOfflinePageDone( |
| 731 OfflinePageArchiver* archiver, | 735 OfflinePageArchiver* archiver, |
| 732 const SavePageCallback& callback, | 736 const SavePageCallback& callback, |
| 733 const OfflinePageItem& offline_page, | 737 const OfflinePageItem& offline_page, |
| 734 bool success) { | 738 bool success) { |
| 735 SavePageResult result; | 739 SavePageResult result; |
| 736 if (success) { | 740 if (success) { |
| 737 offline_pages_[offline_page.offline_id] = offline_page; | 741 offline_pages_[offline_page.offline_id] = offline_page; |
| 738 result = SavePageResult::SUCCESS; | 742 result = SavePageResult::SUCCESS; |
| 739 ReportPageHistogramAfterSave(offline_page); | 743 ReportPageHistogramAfterSave(offline_page, GetCurrentTime()); |
| 740 offline_event_logger_.RecordPageSaved( | 744 offline_event_logger_.RecordPageSaved( |
| 741 offline_page.client_id.name_space, offline_page.url.spec(), | 745 offline_page.client_id.name_space, offline_page.url.spec(), |
| 742 std::to_string(offline_page.offline_id)); | 746 std::to_string(offline_page.offline_id)); |
| 743 } else { | 747 } else { |
| 744 result = SavePageResult::STORE_FAILURE; | 748 result = SavePageResult::STORE_FAILURE; |
| 745 } | 749 } |
| 746 InformSavePageDone(callback, result, offline_page.client_id, | 750 InformSavePageDone(callback, result, offline_page.client_id, |
| 747 offline_page.offline_id); | 751 offline_page.offline_id); |
| 748 if (result == SavePageResult::SUCCESS) { | 752 if (result == SavePageResult::SUCCESS) { |
| 749 DeleteExistingPagesWithSameURL(offline_page); | 753 DeleteExistingPagesWithSameURL(offline_page); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 store_->RemoveOfflinePages( | 892 store_->RemoveOfflinePages( |
| 889 offline_ids, | 893 offline_ids, |
| 890 base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone, | 894 base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone, |
| 891 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); | 895 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); |
| 892 } | 896 } |
| 893 | 897 |
| 894 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( | 898 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( |
| 895 const std::vector<int64_t>& offline_ids, | 899 const std::vector<int64_t>& offline_ids, |
| 896 const DeletePageCallback& callback, | 900 const DeletePageCallback& callback, |
| 897 bool success) { | 901 bool success) { |
| 898 ReportPageHistogramsAfterDelete(offline_pages_, offline_ids); | 902 ReportPageHistogramsAfterDelete( |
| 903 offline_pages_, offline_ids, GetCurrentTime()); |
| 899 | 904 |
| 900 for (int64_t offline_id : offline_ids) { | 905 for (int64_t offline_id : offline_ids) { |
| 901 offline_event_logger_.RecordPageDeleted(std::to_string(offline_id)); | 906 offline_event_logger_.RecordPageDeleted(std::to_string(offline_id)); |
| 902 auto iter = offline_pages_.find(offline_id); | 907 auto iter = offline_pages_.find(offline_id); |
| 903 if (iter == offline_pages_.end()) | 908 if (iter == offline_pages_.end()) |
| 904 continue; | 909 continue; |
| 905 FOR_EACH_OBSERVER( | 910 FOR_EACH_OBSERVER( |
| 906 Observer, observers_, | 911 Observer, observers_, |
| 907 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); | 912 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); |
| 908 offline_pages_.erase(iter); | 913 offline_pages_.erase(iter); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 937 std::vector<int64_t> ids_of_pages_missing_archive_file; | 942 std::vector<int64_t> ids_of_pages_missing_archive_file; |
| 938 for (const auto& id_page_pair : offline_pages_) { | 943 for (const auto& id_page_pair : offline_pages_) { |
| 939 if (archive_paths.count(id_page_pair.second.file_path) == 0UL) | 944 if (archive_paths.count(id_page_pair.second.file_path) == 0UL) |
| 940 ids_of_pages_missing_archive_file.push_back(id_page_pair.first); | 945 ids_of_pages_missing_archive_file.push_back(id_page_pair.first); |
| 941 } | 946 } |
| 942 | 947 |
| 943 if (ids_of_pages_missing_archive_file.empty()) | 948 if (ids_of_pages_missing_archive_file.empty()) |
| 944 return; | 949 return; |
| 945 | 950 |
| 946 ExpirePages( | 951 ExpirePages( |
| 947 ids_of_pages_missing_archive_file, base::Time::Now(), | 952 ids_of_pages_missing_archive_file, GetCurrentTime(), |
| 948 base::Bind(&OfflinePageModelImpl::OnExpirePagesMissingArchiveFileDone, | 953 base::Bind(&OfflinePageModelImpl::OnExpirePagesMissingArchiveFileDone, |
| 949 weak_ptr_factory_.GetWeakPtr(), | 954 weak_ptr_factory_.GetWeakPtr(), |
| 950 ids_of_pages_missing_archive_file)); | 955 ids_of_pages_missing_archive_file)); |
| 951 } | 956 } |
| 952 | 957 |
| 953 void OfflinePageModelImpl::OnExpirePagesMissingArchiveFileDone( | 958 void OfflinePageModelImpl::OnExpirePagesMissingArchiveFileDone( |
| 954 const std::vector<int64_t>& offline_ids, | 959 const std::vector<int64_t>& offline_ids, |
| 955 bool success) { | 960 bool success) { |
| 956 UMA_HISTOGRAM_COUNTS("OfflinePages.Consistency.PagesMissingArchiveFileCount", | 961 UMA_HISTOGRAM_COUNTS("OfflinePages.Consistency.PagesMissingArchiveFileCount", |
| 957 static_cast<int32_t>(offline_ids.size())); | 962 static_cast<int32_t>(offline_ids.size())); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 | 1074 |
| 1070 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1075 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
| 1071 if (!is_loaded_) { | 1076 if (!is_loaded_) { |
| 1072 delayed_tasks_.push_back(task); | 1077 delayed_tasks_.push_back(task); |
| 1073 return; | 1078 return; |
| 1074 } | 1079 } |
| 1075 | 1080 |
| 1076 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1081 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1077 } | 1082 } |
| 1078 | 1083 |
| 1084 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
| 1085 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
| 1086 } |
| 1087 |
| 1079 } // namespace offline_pages | 1088 } // namespace offline_pages |
| OLD | NEW |