| 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" |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 370 |
| 371 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) { | 371 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) { |
| 372 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::MarkPageAccessedWhenLoadDone, | 372 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::MarkPageAccessedWhenLoadDone, |
| 373 weak_ptr_factory_.GetWeakPtr(), offline_id)); | 373 weak_ptr_factory_.GetWeakPtr(), offline_id)); |
| 374 } | 374 } |
| 375 | 375 |
| 376 void OfflinePageModelImpl::MarkPageAccessedWhenLoadDone(int64_t offline_id) { | 376 void OfflinePageModelImpl::MarkPageAccessedWhenLoadDone(int64_t offline_id) { |
| 377 DCHECK(is_loaded_); | 377 DCHECK(is_loaded_); |
| 378 | 378 |
| 379 auto iter = offline_pages_.find(offline_id); | 379 auto iter = offline_pages_.find(offline_id); |
| 380 if (iter == offline_pages_.end() || iter->second.IsExpired()) | 380 if (iter == offline_pages_.end()) |
| 381 return; | 381 return; |
| 382 | 382 |
| 383 // Make a copy of the cached item and update it. The cached item should only | 383 // Make a copy of the cached item and update it. The cached item should only |
| 384 // be updated upon the successful store operation. | 384 // be updated upon the successful store operation. |
| 385 OfflinePageItem offline_page_item = iter->second; | 385 OfflinePageItem offline_page_item = iter->second; |
| 386 | 386 |
| 387 ReportPageHistogramsAfterAccess(offline_page_item, GetCurrentTime()); | 387 ReportPageHistogramsAfterAccess(offline_page_item, GetCurrentTime()); |
| 388 | 388 |
| 389 offline_page_item.last_access_time = GetCurrentTime(); | 389 offline_page_item.last_access_time = GetCurrentTime(); |
| 390 offline_page_item.access_count++; | 390 offline_page_item.access_count++; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 404 } | 404 } |
| 405 | 405 |
| 406 void OfflinePageModelImpl::DoDeletePagesByOfflineId( | 406 void OfflinePageModelImpl::DoDeletePagesByOfflineId( |
| 407 const std::vector<int64_t>& offline_ids, | 407 const std::vector<int64_t>& offline_ids, |
| 408 const DeletePageCallback& callback) { | 408 const DeletePageCallback& callback) { |
| 409 DCHECK(is_loaded_); | 409 DCHECK(is_loaded_); |
| 410 | 410 |
| 411 std::vector<base::FilePath> paths_to_delete; | 411 std::vector<base::FilePath> paths_to_delete; |
| 412 for (const auto& offline_id : offline_ids) { | 412 for (const auto& offline_id : offline_ids) { |
| 413 auto iter = offline_pages_.find(offline_id); | 413 auto iter = offline_pages_.find(offline_id); |
| 414 if (iter != offline_pages_.end() && !iter->second.IsExpired()) { | 414 if (iter != offline_pages_.end()) { |
| 415 paths_to_delete.push_back(iter->second.file_path); | 415 paths_to_delete.push_back(iter->second.file_path); |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 | 418 |
| 419 // If there're no pages to delete, return early. | 419 // If there're no pages to delete, return early. |
| 420 if (paths_to_delete.empty()) { | 420 if (paths_to_delete.empty()) { |
| 421 InformDeletePageDone(callback, DeletePageResult::SUCCESS); | 421 InformDeletePageDone(callback, DeletePageResult::SUCCESS); |
| 422 return; | 422 return; |
| 423 } | 423 } |
| 424 | 424 |
| 425 archive_manager_->DeleteMultipleArchives( | 425 archive_manager_->DeleteMultipleArchives( |
| 426 paths_to_delete, | 426 paths_to_delete, |
| 427 base::Bind(&OfflinePageModelImpl::OnDeleteArchiveFilesDone, | 427 base::Bind(&OfflinePageModelImpl::OnDeleteArchiveFilesDone, |
| 428 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); | 428 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); |
| 429 } | 429 } |
| 430 | 430 |
| 431 void OfflinePageModelImpl::DeletePagesByClientIds( | 431 void OfflinePageModelImpl::DeletePagesByClientIds( |
| 432 const std::vector<ClientId>& client_ids, | 432 const std::vector<ClientId>& client_ids, |
| 433 const DeletePageCallback& callback) { | 433 const DeletePageCallback& callback) { |
| 434 OfflinePageModelQueryBuilder builder; | 434 OfflinePageModelQueryBuilder builder; |
| 435 builder | 435 builder.SetClientIds(OfflinePageModelQuery::Requirement::INCLUDE_MATCHING, |
| 436 .SetClientIds(OfflinePageModelQuery::Requirement::INCLUDE_MATCHING, | 436 client_ids); |
| 437 client_ids) | |
| 438 .AllowExpiredPages(true); | |
| 439 auto delete_pages = base::Bind(&OfflinePageModelImpl::DeletePages, | 437 auto delete_pages = base::Bind(&OfflinePageModelImpl::DeletePages, |
| 440 weak_ptr_factory_.GetWeakPtr(), callback); | 438 weak_ptr_factory_.GetWeakPtr(), callback); |
| 441 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::GetPagesMatchingQuery, | 439 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::GetPagesMatchingQuery, |
| 442 weak_ptr_factory_.GetWeakPtr(), | 440 weak_ptr_factory_.GetWeakPtr(), |
| 443 base::Passed(builder.Build(GetPolicyController())), | 441 base::Passed(builder.Build(GetPolicyController())), |
| 444 delete_pages)); | 442 delete_pages)); |
| 445 } | 443 } |
| 446 | 444 |
| 447 void OfflinePageModelImpl::DeletePages( | 445 void OfflinePageModelImpl::DeletePages( |
| 448 const DeletePageCallback& callback, | 446 const DeletePageCallback& callback, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 | 530 |
| 533 void OfflinePageModelImpl::GetAllPages( | 531 void OfflinePageModelImpl::GetAllPages( |
| 534 const MultipleOfflinePageItemCallback& callback) { | 532 const MultipleOfflinePageItemCallback& callback) { |
| 535 OfflinePageModelQueryBuilder builder; | 533 OfflinePageModelQueryBuilder builder; |
| 536 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::GetPagesMatchingQuery, | 534 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::GetPagesMatchingQuery, |
| 537 weak_ptr_factory_.GetWeakPtr(), | 535 weak_ptr_factory_.GetWeakPtr(), |
| 538 base::Passed(builder.Build(GetPolicyController())), | 536 base::Passed(builder.Build(GetPolicyController())), |
| 539 callback)); | 537 callback)); |
| 540 } | 538 } |
| 541 | 539 |
| 542 void OfflinePageModelImpl::GetAllPagesWithExpired( | |
| 543 const MultipleOfflinePageItemCallback& callback) { | |
| 544 OfflinePageModelQueryBuilder builder; | |
| 545 builder.AllowExpiredPages(true); | |
| 546 | |
| 547 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::GetPagesMatchingQuery, | |
| 548 weak_ptr_factory_.GetWeakPtr(), | |
| 549 base::Passed(builder.Build(GetPolicyController())), | |
| 550 callback)); | |
| 551 } | |
| 552 | |
| 553 void OfflinePageModelImpl::GetOfflineIdsForClientId( | 540 void OfflinePageModelImpl::GetOfflineIdsForClientId( |
| 554 const ClientId& client_id, | 541 const ClientId& client_id, |
| 555 const MultipleOfflineIdCallback& callback) { | 542 const MultipleOfflineIdCallback& callback) { |
| 556 RunWhenLoaded( | 543 RunWhenLoaded( |
| 557 base::Bind(&OfflinePageModelImpl::GetOfflineIdsForClientIdWhenLoadDone, | 544 base::Bind(&OfflinePageModelImpl::GetOfflineIdsForClientIdWhenLoadDone, |
| 558 weak_ptr_factory_.GetWeakPtr(), client_id, callback)); | 545 weak_ptr_factory_.GetWeakPtr(), client_id, callback)); |
| 559 } | 546 } |
| 560 | 547 |
| 561 void OfflinePageModelImpl::GetOfflineIdsForClientIdWhenLoadDone( | 548 void OfflinePageModelImpl::GetOfflineIdsForClientIdWhenLoadDone( |
| 562 const ClientId& client_id, | 549 const ClientId& client_id, |
| 563 const MultipleOfflineIdCallback& callback) const { | 550 const MultipleOfflineIdCallback& callback) const { |
| 564 callback.Run(MaybeGetOfflineIdsForClientId(client_id)); | 551 callback.Run(MaybeGetOfflineIdsForClientId(client_id)); |
| 565 } | 552 } |
| 566 | 553 |
| 567 const std::vector<int64_t> OfflinePageModelImpl::MaybeGetOfflineIdsForClientId( | 554 const std::vector<int64_t> OfflinePageModelImpl::MaybeGetOfflineIdsForClientId( |
| 568 const ClientId& client_id) const { | 555 const ClientId& client_id) const { |
| 569 DCHECK(is_loaded_); | 556 DCHECK(is_loaded_); |
| 570 std::vector<int64_t> results; | 557 std::vector<int64_t> results; |
| 571 | 558 |
| 572 // We want only all pages, including those marked for deletion. | 559 // We want only all pages, including those marked for deletion. |
| 573 // TODO(fgorski): actually use an index rather than linear scan. | 560 // TODO(fgorski): actually use an index rather than linear scan. |
| 574 for (const auto& id_page_pair : offline_pages_) { | 561 for (const auto& id_page_pair : offline_pages_) { |
| 575 if (id_page_pair.second.client_id == client_id && | 562 if (id_page_pair.second.client_id == client_id) |
| 576 !id_page_pair.second.IsExpired()) { | |
| 577 results.push_back(id_page_pair.second.offline_id); | 563 results.push_back(id_page_pair.second.offline_id); |
| 578 } | |
| 579 } | 564 } |
| 580 return results; | 565 return results; |
| 581 } | 566 } |
| 582 | 567 |
| 583 void OfflinePageModelImpl::GetPageByOfflineId( | 568 void OfflinePageModelImpl::GetPageByOfflineId( |
| 584 int64_t offline_id, | 569 int64_t offline_id, |
| 585 const SingleOfflinePageItemCallback& callback) { | 570 const SingleOfflinePageItemCallback& callback) { |
| 586 std::vector<int64_t> query_ids; | 571 std::vector<int64_t> query_ids; |
| 587 query_ids.emplace_back(offline_id); | 572 query_ids.emplace_back(offline_id); |
| 588 | 573 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 const MultipleOfflinePageItemCallback& callback) const { | 609 const MultipleOfflinePageItemCallback& callback) const { |
| 625 std::vector<OfflinePageItem> result; | 610 std::vector<OfflinePageItem> result; |
| 626 | 611 |
| 627 GURL::Replacements remove_params; | 612 GURL::Replacements remove_params; |
| 628 remove_params.ClearRef(); | 613 remove_params.ClearRef(); |
| 629 | 614 |
| 630 GURL url_without_fragment = | 615 GURL url_without_fragment = |
| 631 url.ReplaceComponents(remove_params); | 616 url.ReplaceComponents(remove_params); |
| 632 | 617 |
| 633 for (const auto& id_page_pair : offline_pages_) { | 618 for (const auto& id_page_pair : offline_pages_) { |
| 634 if (id_page_pair.second.IsExpired()) | |
| 635 continue; | |
| 636 // First, search by last committed URL with fragment stripped. | 619 // First, search by last committed URL with fragment stripped. |
| 637 if (url_without_fragment == | 620 if (url_without_fragment == |
| 638 id_page_pair.second.url.ReplaceComponents(remove_params)) { | 621 id_page_pair.second.url.ReplaceComponents(remove_params)) { |
| 639 result.push_back(id_page_pair.second); | 622 result.push_back(id_page_pair.second); |
| 640 continue; | 623 continue; |
| 641 } | 624 } |
| 642 // Then, search by original request URL if |url_search_mode| wants it. | 625 // Then, search by original request URL if |url_search_mode| wants it. |
| 643 // Note that we want to do the exact match with fragment included. This is | 626 // Note that we want to do the exact match with fragment included. This is |
| 644 // because original URL is used for redirect purpose and it is always safer | 627 // because original URL is used for redirect purpose and it is always safer |
| 645 // to support the exact redirect. | 628 // to support the exact redirect. |
| 646 if (url_search_mode == URLSearchMode::SEARCH_BY_ALL_URLS && | 629 if (url_search_mode == URLSearchMode::SEARCH_BY_ALL_URLS && |
| 647 url == id_page_pair.second.original_url) { | 630 url == id_page_pair.second.original_url) { |
| 648 result.push_back(id_page_pair.second); | 631 result.push_back(id_page_pair.second); |
| 649 } | 632 } |
| 650 } | 633 } |
| 651 | 634 |
| 652 callback.Run(result); | 635 callback.Run(result); |
| 653 } | 636 } |
| 654 | 637 |
| 655 void OfflinePageModelImpl::CheckMetadataConsistency() { | 638 void OfflinePageModelImpl::CheckMetadataConsistency() { |
| 656 archive_manager_->GetAllArchives( | 639 archive_manager_->GetAllArchives( |
| 657 base::Bind(&OfflinePageModelImpl::CheckMetadataConsistencyForArchivePaths, | 640 base::Bind(&OfflinePageModelImpl::CheckMetadataConsistencyForArchivePaths, |
| 658 weak_ptr_factory_.GetWeakPtr())); | 641 weak_ptr_factory_.GetWeakPtr())); |
| 659 } | 642 } |
| 660 | 643 |
| 661 void OfflinePageModelImpl::ExpirePages( | |
| 662 const std::vector<int64_t>& offline_ids, | |
| 663 const base::Time& expiration_time, | |
| 664 const base::Callback<void(bool)>& callback) { | |
| 665 std::vector<base::FilePath> paths_to_delete; | |
| 666 std::vector<OfflinePageItem> items_to_update; | |
| 667 for (int64_t offline_id : offline_ids) { | |
| 668 auto iter = offline_pages_.find(offline_id); | |
| 669 if (iter == offline_pages_.end()) | |
| 670 continue; | |
| 671 | |
| 672 OfflinePageItem offline_page = iter->second; | |
| 673 paths_to_delete.push_back(offline_page.file_path); | |
| 674 offline_page.expiration_time = expiration_time; | |
| 675 | |
| 676 items_to_update.push_back(offline_page); | |
| 677 } | |
| 678 | |
| 679 store_->UpdateOfflinePages( | |
| 680 items_to_update, | |
| 681 base::Bind(&OfflinePageModelImpl::OnExpirePageDone, | |
| 682 weak_ptr_factory_.GetWeakPtr(), expiration_time)); | |
| 683 | |
| 684 if (paths_to_delete.empty()) { | |
| 685 callback.Run(true); | |
| 686 return; | |
| 687 } | |
| 688 archive_manager_->DeleteMultipleArchives(paths_to_delete, callback); | |
| 689 } | |
| 690 | |
| 691 void OfflinePageModelImpl::OnExpirePageDone( | |
| 692 const base::Time& expiration_time, | |
| 693 std::unique_ptr<OfflinePagesUpdateResult> result) { | |
| 694 UMA_HISTOGRAM_BOOLEAN("OfflinePages.ExpirePage.StoreUpdateResult", | |
| 695 result->updated_items.size() > 0); | |
| 696 for (const auto& expired_page : result->updated_items) { | |
| 697 const auto& iter = offline_pages_.find(expired_page.offline_id); | |
| 698 if (iter == offline_pages_.end()) | |
| 699 continue; | |
| 700 | |
| 701 iter->second.expiration_time = expiration_time; | |
| 702 ClientId client_id = iter->second.client_id; | |
| 703 offline_event_logger_.RecordPageExpired( | |
| 704 std::to_string(expired_page.offline_id)); | |
| 705 base::HistogramBase* histogram = base::Histogram::FactoryGet( | |
| 706 AddHistogramSuffix(client_id, "OfflinePages.ExpirePage.PageLifetime"), | |
| 707 1, base::TimeDelta::FromDays(30).InMinutes(), 50, | |
| 708 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 709 histogram->Add((expiration_time - iter->second.creation_time).InMinutes()); | |
| 710 histogram = base::Histogram::FactoryGet( | |
| 711 AddHistogramSuffix(client_id, | |
| 712 "OfflinePages.ExpirePage.TimeSinceLastAccess"), | |
| 713 1, base::TimeDelta::FromDays(30).InMinutes(), 50, | |
| 714 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 715 histogram->Add( | |
| 716 (expiration_time - iter->second.last_access_time).InMinutes()); | |
| 717 } | |
| 718 } | |
| 719 | |
| 720 ClientPolicyController* OfflinePageModelImpl::GetPolicyController() { | 644 ClientPolicyController* OfflinePageModelImpl::GetPolicyController() { |
| 721 return policy_controller_.get(); | 645 return policy_controller_.get(); |
| 722 } | 646 } |
| 723 | 647 |
| 724 OfflinePageMetadataStore* OfflinePageModelImpl::GetStoreForTesting() { | 648 OfflinePageMetadataStore* OfflinePageModelImpl::GetStoreForTesting() { |
| 725 return store_.get(); | 649 return store_.get(); |
| 726 } | 650 } |
| 727 | 651 |
| 728 OfflinePageStorageManager* OfflinePageModelImpl::GetStorageManager() { | 652 OfflinePageStorageManager* OfflinePageModelImpl::GetStorageManager() { |
| 729 return storage_manager_.get(); | 653 return storage_manager_.get(); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 static_cast<int>(result), | 948 static_cast<int>(result), |
| 1025 static_cast<int>(DeletePageResult::RESULT_COUNT)); | 949 static_cast<int>(DeletePageResult::RESULT_COUNT)); |
| 1026 archive_manager_->GetStorageStats( | 950 archive_manager_->GetStorageStats( |
| 1027 base::Bind(&ReportStorageHistogramsAfterDelete)); | 951 base::Bind(&ReportStorageHistogramsAfterDelete)); |
| 1028 if (!callback.is_null()) | 952 if (!callback.is_null()) |
| 1029 callback.Run(result); | 953 callback.Run(result); |
| 1030 } | 954 } |
| 1031 | 955 |
| 1032 void OfflinePageModelImpl::CheckMetadataConsistencyForArchivePaths( | 956 void OfflinePageModelImpl::CheckMetadataConsistencyForArchivePaths( |
| 1033 const std::set<base::FilePath>& archive_paths) { | 957 const std::set<base::FilePath>& archive_paths) { |
| 1034 ExpirePagesMissingArchiveFile(archive_paths); | 958 DeletePagesMissingArchiveFile(archive_paths); |
| 1035 DeleteOrphanedArchives(archive_paths); | 959 DeleteOrphanedArchives(archive_paths); |
| 1036 } | 960 } |
| 1037 | 961 |
| 1038 void OfflinePageModelImpl::ExpirePagesMissingArchiveFile( | 962 void OfflinePageModelImpl::DeletePagesMissingArchiveFile( |
| 1039 const std::set<base::FilePath>& archive_paths) { | 963 const std::set<base::FilePath>& archive_paths) { |
| 1040 std::vector<int64_t> ids_of_pages_missing_archive_file; | 964 std::vector<int64_t> ids_of_pages_missing_archive_file; |
| 1041 for (const auto& id_page_pair : offline_pages_) { | 965 for (const auto& id_page_pair : offline_pages_) { |
| 1042 if (archive_paths.count(id_page_pair.second.file_path) == 0UL) | 966 if (archive_paths.count(id_page_pair.second.file_path) == 0UL) |
| 1043 ids_of_pages_missing_archive_file.push_back(id_page_pair.first); | 967 ids_of_pages_missing_archive_file.push_back(id_page_pair.first); |
| 1044 } | 968 } |
| 1045 | 969 |
| 1046 if (ids_of_pages_missing_archive_file.empty()) | 970 if (ids_of_pages_missing_archive_file.empty()) |
| 1047 return; | 971 return; |
| 1048 | 972 |
| 1049 ExpirePages( | 973 DeletePagesByOfflineId( |
| 1050 ids_of_pages_missing_archive_file, GetCurrentTime(), | 974 ids_of_pages_missing_archive_file, |
| 1051 base::Bind(&OfflinePageModelImpl::OnExpirePagesMissingArchiveFileDone, | 975 base::Bind(&OfflinePageModelImpl::OnDeletePagesMissingArchiveFileDone, |
| 1052 weak_ptr_factory_.GetWeakPtr(), | 976 weak_ptr_factory_.GetWeakPtr(), |
| 1053 ids_of_pages_missing_archive_file)); | 977 ids_of_pages_missing_archive_file)); |
| 1054 } | 978 } |
| 1055 | 979 |
| 1056 void OfflinePageModelImpl::OnExpirePagesMissingArchiveFileDone( | 980 void OfflinePageModelImpl::OnDeletePagesMissingArchiveFileDone( |
| 1057 const std::vector<int64_t>& offline_ids, | 981 const std::vector<int64_t>& offline_ids, |
| 1058 bool success) { | 982 DeletePageResult result) { |
| 1059 UMA_HISTOGRAM_COUNTS("OfflinePages.Consistency.PagesMissingArchiveFileCount", | 983 UMA_HISTOGRAM_COUNTS("OfflinePages.Consistency.PagesMissingArchiveFileCount", |
| 1060 static_cast<int32_t>(offline_ids.size())); | 984 static_cast<int32_t>(offline_ids.size())); |
| 1061 UMA_HISTOGRAM_BOOLEAN( | 985 UMA_HISTOGRAM_ENUMERATION( |
| 1062 "OfflinePages.Consistency.ExpirePagesMissingArchiveFileResult", success); | 986 "OfflinePages.Consistency.DeletePagesMissingArchiveFileResult", |
| 987 static_cast<int>(result), |
| 988 static_cast<int>(DeletePageResult::RESULT_COUNT)); |
| 1063 } | 989 } |
| 1064 | 990 |
| 1065 void OfflinePageModelImpl::DeleteOrphanedArchives( | 991 void OfflinePageModelImpl::DeleteOrphanedArchives( |
| 1066 const std::set<base::FilePath>& archive_paths) { | 992 const std::set<base::FilePath>& archive_paths) { |
| 1067 // Archives are considered orphaned unless they are pointed to by some pages. | 993 // Archives are considered orphaned unless they are pointed to by some pages. |
| 1068 std::set<base::FilePath> orphaned_archive_set(archive_paths); | 994 std::set<base::FilePath> orphaned_archive_set(archive_paths); |
| 1069 for (const auto& id_page_pair : offline_pages_) | 995 for (const auto& id_page_pair : offline_pages_) |
| 1070 orphaned_archive_set.erase(id_page_pair.second.file_path); | 996 orphaned_archive_set.erase(id_page_pair.second.file_path); |
| 1071 | 997 |
| 1072 if (orphaned_archive_set.empty()) | 998 if (orphaned_archive_set.empty()) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1099 void OfflinePageModelImpl::ClearStorageIfNeeded( | 1025 void OfflinePageModelImpl::ClearStorageIfNeeded( |
| 1100 const ClearStorageCallback& callback) { | 1026 const ClearStorageCallback& callback) { |
| 1101 // Create Storage Manager if necessary. | 1027 // Create Storage Manager if necessary. |
| 1102 if (!storage_manager_) { | 1028 if (!storage_manager_) { |
| 1103 storage_manager_.reset(new OfflinePageStorageManager( | 1029 storage_manager_.reset(new OfflinePageStorageManager( |
| 1104 this, GetPolicyController(), archive_manager_.get())); | 1030 this, GetPolicyController(), archive_manager_.get())); |
| 1105 } | 1031 } |
| 1106 storage_manager_->ClearPagesIfNeeded(callback); | 1032 storage_manager_->ClearPagesIfNeeded(callback); |
| 1107 } | 1033 } |
| 1108 | 1034 |
| 1109 void OfflinePageModelImpl::OnStorageCleared(size_t expired_page_count, | 1035 void OfflinePageModelImpl::OnStorageCleared(size_t deleted_page_count, |
| 1110 ClearStorageResult result) { | 1036 ClearStorageResult result) { |
| 1111 UMA_HISTOGRAM_ENUMERATION("OfflinePages.ClearStorageResult", | 1037 UMA_HISTOGRAM_ENUMERATION("OfflinePages.ClearStorageResult", |
| 1112 static_cast<int>(result), | 1038 static_cast<int>(result), |
| 1113 static_cast<int>(ClearStorageResult::RESULT_COUNT)); | 1039 static_cast<int>(ClearStorageResult::RESULT_COUNT)); |
| 1114 if (expired_page_count > 0) { | 1040 if (deleted_page_count > 0) { |
| 1115 UMA_HISTOGRAM_COUNTS("OfflinePages.ExpirePage.BatchSize", | 1041 UMA_HISTOGRAM_COUNTS("OfflinePages.ClearStorageBatchSize", |
| 1116 static_cast<int32_t>(expired_page_count)); | 1042 static_cast<int32_t>(deleted_page_count)); |
| 1117 } | 1043 } |
| 1118 } | 1044 } |
| 1119 | 1045 |
| 1120 void OfflinePageModelImpl::PostClearStorageIfNeededTask(bool delayed) { | 1046 void OfflinePageModelImpl::PostClearStorageIfNeededTask(bool delayed) { |
| 1121 base::TimeDelta delay = | 1047 base::TimeDelta delay = |
| 1122 delayed ? kStorageManagerStartingDelay : base::TimeDelta(); | 1048 delayed ? kStorageManagerStartingDelay : base::TimeDelta(); |
| 1123 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1049 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1124 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, | 1050 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, |
| 1125 weak_ptr_factory_.GetWeakPtr(), | 1051 weak_ptr_factory_.GetWeakPtr(), |
| 1126 base::Bind(&OfflinePageModelImpl::OnStorageCleared, | 1052 base::Bind(&OfflinePageModelImpl::OnStorageCleared, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1141 } | 1067 } |
| 1142 | 1068 |
| 1143 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1069 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1144 } | 1070 } |
| 1145 | 1071 |
| 1146 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1072 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
| 1147 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1073 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
| 1148 } | 1074 } |
| 1149 | 1075 |
| 1150 } // namespace offline_pages | 1076 } // namespace offline_pages |
| OLD | NEW |