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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 if (matching_url_count != nullptr) | 187 if (matching_url_count != nullptr) |
187 *matching_url_count = count; | 188 *matching_url_count = count; |
188 if (most_recent_creation_time != nullptr && latest_time != base::Time()) | 189 if (most_recent_creation_time != nullptr && latest_time != base::Time()) |
189 *most_recent_creation_time = created_before - latest_time; | 190 *most_recent_creation_time = created_before - latest_time; |
190 | 191 |
191 return matching_page; | 192 return matching_page; |
192 } | 193 } |
193 | 194 |
194 void ReportPageHistogramAfterSave( | 195 void ReportPageHistogramAfterSave( |
195 const std::map<int64_t, OfflinePageItem>& offline_pages, | 196 const std::map<int64_t, OfflinePageItem>& offline_pages, |
196 const OfflinePageItem& offline_page) { | 197 const OfflinePageItem& offline_page, |
| 198 const base::Time& save_time) { |
197 // The histogram below is an expansion of the UMA_HISTOGRAM_TIMES | 199 // The histogram below is an expansion of the UMA_HISTOGRAM_TIMES |
198 // macro adapted to allow for a dynamically suffixed histogram name. | 200 // macro adapted to allow for a dynamically suffixed histogram name. |
199 // Note: The factory creates and owns the histogram. | 201 // Note: The factory creates and owns the histogram. |
200 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( | 202 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( |
201 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"), | 203 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"), |
202 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), | 204 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), |
203 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 205 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
204 histogram->AddTime(base::Time::Now() - offline_page.creation_time); | 206 histogram->AddTime(save_time - offline_page.creation_time); |
205 | 207 |
206 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS | 208 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
207 // macro adapted to allow for a dynamically suffixed histogram name. | 209 // macro adapted to allow for a dynamically suffixed histogram name. |
208 // Note: The factory creates and owns the histogram. | 210 // Note: The factory creates and owns the histogram. |
209 // Reported as Kb between 1Kb and 10Mb. | 211 // Reported as Kb between 1Kb and 10Mb. |
210 histogram = base::Histogram::FactoryGet( | 212 histogram = base::Histogram::FactoryGet( |
211 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"), | 213 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"), |
212 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 214 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
213 histogram->Add(offline_page.file_size / 1024); | 215 histogram->Add(offline_page.file_size / 1024); |
214 | 216 |
(...skipping 12 matching lines...) Expand all Loading... |
227 base::TimeDelta::FromSeconds(1).InSeconds(), | 229 base::TimeDelta::FromSeconds(1).InSeconds(), |
228 base::TimeDelta::FromDays(7).InSeconds(), 50); | 230 base::TimeDelta::FromDays(7).InSeconds(), 50); |
229 } | 231 } |
230 UMA_HISTOGRAM_CUSTOM_COUNTS("OfflinePages.DownloadSavedPageDuplicateCount", | 232 UMA_HISTOGRAM_CUSTOM_COUNTS("OfflinePages.DownloadSavedPageDuplicateCount", |
231 matching_url_count, 1, 20, 10); | 233 matching_url_count, 1, 20, 10); |
232 } | 234 } |
233 } | 235 } |
234 | 236 |
235 void ReportPageHistogramsAfterDelete( | 237 void ReportPageHistogramsAfterDelete( |
236 const std::map<int64_t, OfflinePageItem>& offline_pages, | 238 const std::map<int64_t, OfflinePageItem>& offline_pages, |
237 const std::vector<int64_t>& deleted_offline_ids) { | 239 const std::vector<int64_t>& deleted_offline_ids, |
| 240 const base::Time& delete_time) { |
238 const int max_minutes = base::TimeDelta::FromDays(365).InMinutes(); | 241 const int max_minutes = base::TimeDelta::FromDays(365).InMinutes(); |
239 base::Time now = base::Time::Now(); | |
240 int64_t total_size = 0; | 242 int64_t total_size = 0; |
241 for (int64_t offline_id : deleted_offline_ids) { | 243 for (int64_t offline_id : deleted_offline_ids) { |
242 auto iter = offline_pages.find(offline_id); | 244 auto iter = offline_pages.find(offline_id); |
243 if (iter == offline_pages.end()) | 245 if (iter == offline_pages.end()) |
244 continue; | 246 continue; |
245 | 247 |
246 total_size += iter->second.file_size; | 248 total_size += iter->second.file_size; |
247 ClientId client_id = iter->second.client_id; | 249 ClientId client_id = iter->second.client_id; |
248 | 250 |
249 if (client_id.name_space == kDownloadNamespace) { | 251 if (client_id.name_space == kDownloadNamespace) { |
250 int remaining_pages_with_url; | 252 int remaining_pages_with_url; |
251 GetMatchingURLCountAndMostRecentCreationTime( | 253 GetMatchingURLCountAndMostRecentCreationTime( |
252 offline_pages, iter->second.client_id.name_space, iter->second.url, | 254 offline_pages, iter->second.client_id.name_space, iter->second.url, |
253 base::Time::Max(), &remaining_pages_with_url, nullptr); | 255 base::Time::Max(), &remaining_pages_with_url, nullptr); |
254 UMA_HISTOGRAM_CUSTOM_COUNTS( | 256 UMA_HISTOGRAM_CUSTOM_COUNTS( |
255 "OfflinePages.DownloadDeletedPageDuplicateCount", | 257 "OfflinePages.DownloadDeletedPageDuplicateCount", |
256 remaining_pages_with_url, 1, 20, 10); | 258 remaining_pages_with_url, 1, 20, 10); |
257 } | 259 } |
258 | 260 |
259 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS | 261 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
260 // macro adapted to allow for a dynamically suffixed histogram name. | 262 // macro adapted to allow for a dynamically suffixed histogram name. |
261 // Note: The factory creates and owns the histogram. | 263 // Note: The factory creates and owns the histogram. |
262 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 264 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
263 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), | 265 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), |
264 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); | 266 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); |
265 histogram->Add((now - iter->second.creation_time).InMinutes()); | 267 histogram->Add((delete_time - iter->second.creation_time).InMinutes()); |
266 | 268 |
267 histogram = base::Histogram::FactoryGet( | 269 histogram = base::Histogram::FactoryGet( |
268 AddHistogramSuffix( | 270 AddHistogramSuffix( |
269 client_id, "OfflinePages.DeletePage.TimeSinceLastOpen"), | 271 client_id, "OfflinePages.DeletePage.TimeSinceLastOpen"), |
270 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); | 272 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); |
271 histogram->Add((now - iter->second.last_access_time).InMinutes()); | 273 histogram->Add((delete_time - iter->second.last_access_time).InMinutes()); |
272 | 274 |
273 histogram = base::Histogram::FactoryGet( | 275 histogram = base::Histogram::FactoryGet( |
274 AddHistogramSuffix( | 276 AddHistogramSuffix( |
275 client_id, "OfflinePages.DeletePage.LastOpenToCreated"), | 277 client_id, "OfflinePages.DeletePage.LastOpenToCreated"), |
276 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); | 278 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); |
277 histogram->Add( | 279 histogram->Add( |
278 (iter->second.last_access_time - iter->second.creation_time). | 280 (iter->second.last_access_time - iter->second.creation_time). |
279 InMinutes()); | 281 InMinutes()); |
280 | 282 |
281 // Reported as Kb between 1Kb and 10Mb. | 283 // Reported as Kb between 1Kb and 10Mb. |
282 histogram = base::Histogram::FactoryGet( | 284 histogram = base::Histogram::FactoryGet( |
283 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize"), | 285 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize"), |
284 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 286 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
285 histogram->Add(iter->second.file_size / 1024); | 287 histogram->Add(iter->second.file_size / 1024); |
286 | 288 |
287 histogram = base::Histogram::FactoryGet( | 289 histogram = base::Histogram::FactoryGet( |
288 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount"), | 290 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount"), |
289 1, 1000000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 291 1, 1000000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
290 histogram->Add(iter->second.access_count); | 292 histogram->Add(iter->second.access_count); |
291 } | 293 } |
292 | 294 |
293 if (deleted_offline_ids.size() > 1) { | 295 if (deleted_offline_ids.size() > 1) { |
294 UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count", | 296 UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count", |
295 static_cast<int32_t>(deleted_offline_ids.size())); | 297 static_cast<int32_t>(deleted_offline_ids.size())); |
296 UMA_HISTOGRAM_MEMORY_KB( | 298 UMA_HISTOGRAM_MEMORY_KB( |
297 "OfflinePages.BatchDelete.TotalPageSize", total_size / 1024); | 299 "OfflinePages.BatchDelete.TotalPageSize", total_size / 1024); |
298 } | 300 } |
299 } | 301 } |
300 | 302 |
301 void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item) { | 303 void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item, |
| 304 const base::Time& access_time) { |
302 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS | 305 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
303 // macro adapted to allow for a dynamically suffixed histogram name. | 306 // macro adapted to allow for a dynamically suffixed histogram name. |
304 // Note: The factory creates and owns the histogram. | 307 // Note: The factory creates and owns the histogram. |
305 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 308 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
306 AddHistogramSuffix( | 309 AddHistogramSuffix( |
307 offline_page_item.client_id, | 310 offline_page_item.client_id, |
308 offline_page_item.access_count == 0 ? | 311 offline_page_item.access_count == 0 ? |
309 "OfflinePages.FirstOpenSinceCreated" : | 312 "OfflinePages.FirstOpenSinceCreated" : |
310 "OfflinePages.OpenSinceLastOpen"), | 313 "OfflinePages.OpenSinceLastOpen"), |
311 1, kMaxOpenedPageHistogramBucket.InMinutes(), 50, | 314 1, kMaxOpenedPageHistogramBucket.InMinutes(), 50, |
312 base::HistogramBase::kUmaTargetedHistogramFlag); | 315 base::HistogramBase::kUmaTargetedHistogramFlag); |
313 histogram->Add( | 316 histogram->Add( |
314 (base::Time::Now() - offline_page_item.last_access_time).InMinutes()); | 317 (access_time - offline_page_item.last_access_time).InMinutes()); |
315 } | 318 } |
316 | 319 |
317 } // namespace | 320 } // namespace |
318 | 321 |
319 // protected | 322 // protected |
320 OfflinePageModelImpl::OfflinePageModelImpl() | 323 OfflinePageModelImpl::OfflinePageModelImpl() |
321 : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {} | 324 : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {} |
322 | 325 |
323 OfflinePageModelImpl::OfflinePageModelImpl( | 326 OfflinePageModelImpl::OfflinePageModelImpl( |
324 std::unique_ptr<OfflinePageMetadataStore> store, | 327 std::unique_ptr<OfflinePageMetadataStore> store, |
325 const base::FilePath& archives_dir, | 328 const base::FilePath& archives_dir, |
326 const scoped_refptr<base::SequencedTaskRunner>& task_runner) | 329 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
327 : store_(std::move(store)), | 330 : store_(std::move(store)), |
328 archives_dir_(archives_dir), | 331 archives_dir_(archives_dir), |
329 is_loaded_(false), | 332 is_loaded_(false), |
330 policy_controller_(new ClientPolicyController()), | 333 policy_controller_(new ClientPolicyController()), |
331 archive_manager_(new ArchiveManager(archives_dir, task_runner)), | 334 archive_manager_(new ArchiveManager(archives_dir, task_runner)), |
| 335 testing_clock_(nullptr), |
332 weak_ptr_factory_(this) { | 336 weak_ptr_factory_(this) { |
333 archive_manager_->EnsureArchivesDirCreated( | 337 archive_manager_->EnsureArchivesDirCreated( |
334 base::Bind(&OfflinePageModelImpl::OnEnsureArchivesDirCreatedDone, | 338 base::Bind(&OfflinePageModelImpl::OnEnsureArchivesDirCreatedDone, |
335 weak_ptr_factory_.GetWeakPtr(), base::TimeTicks::Now())); | 339 weak_ptr_factory_.GetWeakPtr(), base::TimeTicks::Now())); |
336 } | 340 } |
337 | 341 |
338 OfflinePageModelImpl::~OfflinePageModelImpl() {} | 342 OfflinePageModelImpl::~OfflinePageModelImpl() {} |
339 | 343 |
340 void OfflinePageModelImpl::AddObserver(Observer* observer) { | 344 void OfflinePageModelImpl::AddObserver(Observer* observer) { |
341 observers_.AddObserver(observer); | 345 observers_.AddObserver(observer); |
(...skipping 27 matching lines...) Expand all Loading... |
369 } | 373 } |
370 | 374 |
371 // If we already have an offline id, use it. If not, generate one. | 375 // If we already have an offline id, use it. If not, generate one. |
372 if (proposed_offline_id == 0ul) | 376 if (proposed_offline_id == 0ul) |
373 proposed_offline_id = GenerateOfflineId(); | 377 proposed_offline_id = GenerateOfflineId(); |
374 | 378 |
375 archiver->CreateArchive( | 379 archiver->CreateArchive( |
376 archives_dir_, proposed_offline_id, | 380 archives_dir_, proposed_offline_id, |
377 base::Bind(&OfflinePageModelImpl::OnCreateArchiveDone, | 381 base::Bind(&OfflinePageModelImpl::OnCreateArchiveDone, |
378 weak_ptr_factory_.GetWeakPtr(), url, proposed_offline_id, | 382 weak_ptr_factory_.GetWeakPtr(), url, proposed_offline_id, |
379 client_id, base::Time::Now(), callback)); | 383 client_id, GetCurrentTime(), callback)); |
380 pending_archivers_.push_back(std::move(archiver)); | 384 pending_archivers_.push_back(std::move(archiver)); |
381 } | 385 } |
382 | 386 |
383 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) { | 387 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) { |
384 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::MarkPageAccessedWhenLoadDone, | 388 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::MarkPageAccessedWhenLoadDone, |
385 weak_ptr_factory_.GetWeakPtr(), offline_id)); | 389 weak_ptr_factory_.GetWeakPtr(), offline_id)); |
386 } | 390 } |
387 | 391 |
388 void OfflinePageModelImpl::MarkPageAccessedWhenLoadDone(int64_t offline_id) { | 392 void OfflinePageModelImpl::MarkPageAccessedWhenLoadDone(int64_t offline_id) { |
389 DCHECK(is_loaded_); | 393 DCHECK(is_loaded_); |
390 | 394 |
391 auto iter = offline_pages_.find(offline_id); | 395 auto iter = offline_pages_.find(offline_id); |
392 if (iter == offline_pages_.end() || iter->second.IsExpired()) | 396 if (iter == offline_pages_.end() || iter->second.IsExpired()) |
393 return; | 397 return; |
394 | 398 |
395 // Make a copy of the cached item and update it. The cached item should only | 399 // Make a copy of the cached item and update it. The cached item should only |
396 // be updated upon the successful store operation. | 400 // be updated upon the successful store operation. |
397 OfflinePageItem offline_page_item = iter->second; | 401 OfflinePageItem offline_page_item = iter->second; |
398 | 402 |
399 ReportPageHistogramsAfterAccess(offline_page_item); | 403 ReportPageHistogramsAfterAccess(offline_page_item, GetCurrentTime()); |
400 | 404 |
401 offline_page_item.last_access_time = base::Time::Now(); | 405 offline_page_item.last_access_time = GetCurrentTime(); |
402 offline_page_item.access_count++; | 406 offline_page_item.access_count++; |
403 | 407 |
404 store_->AddOrUpdateOfflinePage( | 408 store_->AddOrUpdateOfflinePage( |
405 offline_page_item, | 409 offline_page_item, |
406 base::Bind(&OfflinePageModelImpl::OnMarkPageAccesseDone, | 410 base::Bind(&OfflinePageModelImpl::OnMarkPageAccesseDone, |
407 weak_ptr_factory_.GetWeakPtr(), offline_page_item)); | 411 weak_ptr_factory_.GetWeakPtr(), offline_page_item)); |
408 } | 412 } |
409 | 413 |
410 void OfflinePageModelImpl::DeletePagesByOfflineId( | 414 void OfflinePageModelImpl::DeletePagesByOfflineId( |
411 const std::vector<int64_t>& offline_ids, | 415 const std::vector<int64_t>& offline_ids, |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 | 806 |
803 void OfflinePageModelImpl::OnAddOfflinePageDone( | 807 void OfflinePageModelImpl::OnAddOfflinePageDone( |
804 OfflinePageArchiver* archiver, | 808 OfflinePageArchiver* archiver, |
805 const SavePageCallback& callback, | 809 const SavePageCallback& callback, |
806 const OfflinePageItem& offline_page, | 810 const OfflinePageItem& offline_page, |
807 bool success) { | 811 bool success) { |
808 SavePageResult result; | 812 SavePageResult result; |
809 if (success) { | 813 if (success) { |
810 offline_pages_[offline_page.offline_id] = offline_page; | 814 offline_pages_[offline_page.offline_id] = offline_page; |
811 result = SavePageResult::SUCCESS; | 815 result = SavePageResult::SUCCESS; |
812 ReportPageHistogramAfterSave(offline_pages_, offline_page); | 816 ReportPageHistogramAfterSave(offline_pages_, offline_page, |
| 817 GetCurrentTime()); |
813 offline_event_logger_.RecordPageSaved( | 818 offline_event_logger_.RecordPageSaved( |
814 offline_page.client_id.name_space, offline_page.url.spec(), | 819 offline_page.client_id.name_space, offline_page.url.spec(), |
815 std::to_string(offline_page.offline_id)); | 820 std::to_string(offline_page.offline_id)); |
816 } else { | 821 } else { |
817 result = SavePageResult::STORE_FAILURE; | 822 result = SavePageResult::STORE_FAILURE; |
818 } | 823 } |
819 InformSavePageDone(callback, result, offline_page.client_id, | 824 InformSavePageDone(callback, result, offline_page.client_id, |
820 offline_page.offline_id); | 825 offline_page.offline_id); |
821 if (result == SavePageResult::SUCCESS) { | 826 if (result == SavePageResult::SUCCESS) { |
822 DeleteExistingPagesWithSameURL(offline_page); | 827 DeleteExistingPagesWithSameURL(offline_page); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 store_->RemoveOfflinePages( | 966 store_->RemoveOfflinePages( |
962 offline_ids, | 967 offline_ids, |
963 base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone, | 968 base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone, |
964 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); | 969 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); |
965 } | 970 } |
966 | 971 |
967 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( | 972 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( |
968 const std::vector<int64_t>& offline_ids, | 973 const std::vector<int64_t>& offline_ids, |
969 const DeletePageCallback& callback, | 974 const DeletePageCallback& callback, |
970 bool success) { | 975 bool success) { |
971 ReportPageHistogramsAfterDelete(offline_pages_, offline_ids); | 976 ReportPageHistogramsAfterDelete( |
| 977 offline_pages_, offline_ids, GetCurrentTime()); |
972 | 978 |
973 for (int64_t offline_id : offline_ids) { | 979 for (int64_t offline_id : offline_ids) { |
974 offline_event_logger_.RecordPageDeleted(std::to_string(offline_id)); | 980 offline_event_logger_.RecordPageDeleted(std::to_string(offline_id)); |
975 auto iter = offline_pages_.find(offline_id); | 981 auto iter = offline_pages_.find(offline_id); |
976 if (iter == offline_pages_.end()) | 982 if (iter == offline_pages_.end()) |
977 continue; | 983 continue; |
978 FOR_EACH_OBSERVER( | 984 FOR_EACH_OBSERVER( |
979 Observer, observers_, | 985 Observer, observers_, |
980 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); | 986 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); |
981 offline_pages_.erase(iter); | 987 offline_pages_.erase(iter); |
(...skipping 28 matching lines...) Expand all Loading... |
1010 std::vector<int64_t> ids_of_pages_missing_archive_file; | 1016 std::vector<int64_t> ids_of_pages_missing_archive_file; |
1011 for (const auto& id_page_pair : offline_pages_) { | 1017 for (const auto& id_page_pair : offline_pages_) { |
1012 if (archive_paths.count(id_page_pair.second.file_path) == 0UL) | 1018 if (archive_paths.count(id_page_pair.second.file_path) == 0UL) |
1013 ids_of_pages_missing_archive_file.push_back(id_page_pair.first); | 1019 ids_of_pages_missing_archive_file.push_back(id_page_pair.first); |
1014 } | 1020 } |
1015 | 1021 |
1016 if (ids_of_pages_missing_archive_file.empty()) | 1022 if (ids_of_pages_missing_archive_file.empty()) |
1017 return; | 1023 return; |
1018 | 1024 |
1019 ExpirePages( | 1025 ExpirePages( |
1020 ids_of_pages_missing_archive_file, base::Time::Now(), | 1026 ids_of_pages_missing_archive_file, GetCurrentTime(), |
1021 base::Bind(&OfflinePageModelImpl::OnExpirePagesMissingArchiveFileDone, | 1027 base::Bind(&OfflinePageModelImpl::OnExpirePagesMissingArchiveFileDone, |
1022 weak_ptr_factory_.GetWeakPtr(), | 1028 weak_ptr_factory_.GetWeakPtr(), |
1023 ids_of_pages_missing_archive_file)); | 1029 ids_of_pages_missing_archive_file)); |
1024 } | 1030 } |
1025 | 1031 |
1026 void OfflinePageModelImpl::OnExpirePagesMissingArchiveFileDone( | 1032 void OfflinePageModelImpl::OnExpirePagesMissingArchiveFileDone( |
1027 const std::vector<int64_t>& offline_ids, | 1033 const std::vector<int64_t>& offline_ids, |
1028 bool success) { | 1034 bool success) { |
1029 UMA_HISTOGRAM_COUNTS("OfflinePages.Consistency.PagesMissingArchiveFileCount", | 1035 UMA_HISTOGRAM_COUNTS("OfflinePages.Consistency.PagesMissingArchiveFileCount", |
1030 static_cast<int32_t>(offline_ids.size())); | 1036 static_cast<int32_t>(offline_ids.size())); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 | 1148 |
1143 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1149 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
1144 if (!is_loaded_) { | 1150 if (!is_loaded_) { |
1145 delayed_tasks_.push_back(task); | 1151 delayed_tasks_.push_back(task); |
1146 return; | 1152 return; |
1147 } | 1153 } |
1148 | 1154 |
1149 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1155 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
1150 } | 1156 } |
1151 | 1157 |
| 1158 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
| 1159 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
| 1160 } |
| 1161 |
1152 } // namespace offline_pages | 1162 } // namespace offline_pages |
OLD | NEW |