Chromium Code Reviews| 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) { |
|
fgorski
2016/11/22 00:02:59
nit: since both body and condition are one liners,
romax
2016/11/23 23:32:03
Done.
| |
| 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 } | 564 } |
| 579 } | 565 } |
| 580 return results; | 566 return results; |
| 581 } | 567 } |
| 582 | 568 |
| 583 void OfflinePageModelImpl::GetPageByOfflineId( | 569 void OfflinePageModelImpl::GetPageByOfflineId( |
| 584 int64_t offline_id, | 570 int64_t offline_id, |
| 585 const SingleOfflinePageItemCallback& callback) { | 571 const SingleOfflinePageItemCallback& callback) { |
| 586 std::vector<int64_t> query_ids; | 572 std::vector<int64_t> query_ids; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 const MultipleOfflinePageItemCallback& callback) const { | 610 const MultipleOfflinePageItemCallback& callback) const { |
| 625 std::vector<OfflinePageItem> result; | 611 std::vector<OfflinePageItem> result; |
| 626 | 612 |
| 627 GURL::Replacements remove_params; | 613 GURL::Replacements remove_params; |
| 628 remove_params.ClearRef(); | 614 remove_params.ClearRef(); |
| 629 | 615 |
| 630 GURL url_without_fragment = | 616 GURL url_without_fragment = |
| 631 url.ReplaceComponents(remove_params); | 617 url.ReplaceComponents(remove_params); |
| 632 | 618 |
| 633 for (const auto& id_page_pair : offline_pages_) { | 619 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. | 620 // First, search by last committed URL with fragment stripped. |
| 637 if (url_without_fragment == | 621 if (url_without_fragment == |
| 638 id_page_pair.second.url.ReplaceComponents(remove_params)) { | 622 id_page_pair.second.url.ReplaceComponents(remove_params)) { |
| 639 result.push_back(id_page_pair.second); | 623 result.push_back(id_page_pair.second); |
| 640 continue; | 624 continue; |
| 641 } | 625 } |
| 642 // Then, search by original request URL if |url_search_mode| wants it. | 626 // 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 | 627 // 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 | 628 // because original URL is used for redirect purpose and it is always safer |
| 645 // to support the exact redirect. | 629 // to support the exact redirect. |
| 646 if (url_search_mode == URLSearchMode::SEARCH_BY_ALL_URLS && | 630 if (url_search_mode == URLSearchMode::SEARCH_BY_ALL_URLS && |
| 647 url == id_page_pair.second.original_url) { | 631 url == id_page_pair.second.original_url) { |
| 648 result.push_back(id_page_pair.second); | 632 result.push_back(id_page_pair.second); |
| 649 } | 633 } |
| 650 } | 634 } |
| 651 | 635 |
| 652 callback.Run(result); | 636 callback.Run(result); |
| 653 } | 637 } |
| 654 | 638 |
| 655 void OfflinePageModelImpl::CheckMetadataConsistency() { | 639 void OfflinePageModelImpl::CheckMetadataConsistency() { |
| 656 archive_manager_->GetAllArchives( | 640 archive_manager_->GetAllArchives( |
| 657 base::Bind(&OfflinePageModelImpl::CheckMetadataConsistencyForArchivePaths, | 641 base::Bind(&OfflinePageModelImpl::CheckMetadataConsistencyForArchivePaths, |
| 658 weak_ptr_factory_.GetWeakPtr())); | 642 weak_ptr_factory_.GetWeakPtr())); |
| 659 } | 643 } |
| 660 | 644 |
| 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() { | 645 ClientPolicyController* OfflinePageModelImpl::GetPolicyController() { |
| 721 return policy_controller_.get(); | 646 return policy_controller_.get(); |
| 722 } | 647 } |
| 723 | 648 |
| 724 OfflinePageMetadataStore* OfflinePageModelImpl::GetStoreForTesting() { | 649 OfflinePageMetadataStore* OfflinePageModelImpl::GetStoreForTesting() { |
| 725 return store_.get(); | 650 return store_.get(); |
| 726 } | 651 } |
| 727 | 652 |
| 728 OfflinePageStorageManager* OfflinePageModelImpl::GetStorageManager() { | 653 OfflinePageStorageManager* OfflinePageModelImpl::GetStorageManager() { |
| 729 return storage_manager_.get(); | 654 return storage_manager_.get(); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1024 static_cast<int>(result), | 949 static_cast<int>(result), |
| 1025 static_cast<int>(DeletePageResult::RESULT_COUNT)); | 950 static_cast<int>(DeletePageResult::RESULT_COUNT)); |
| 1026 archive_manager_->GetStorageStats( | 951 archive_manager_->GetStorageStats( |
| 1027 base::Bind(&ReportStorageHistogramsAfterDelete)); | 952 base::Bind(&ReportStorageHistogramsAfterDelete)); |
| 1028 if (!callback.is_null()) | 953 if (!callback.is_null()) |
| 1029 callback.Run(result); | 954 callback.Run(result); |
| 1030 } | 955 } |
| 1031 | 956 |
| 1032 void OfflinePageModelImpl::CheckMetadataConsistencyForArchivePaths( | 957 void OfflinePageModelImpl::CheckMetadataConsistencyForArchivePaths( |
| 1033 const std::set<base::FilePath>& archive_paths) { | 958 const std::set<base::FilePath>& archive_paths) { |
| 1034 ExpirePagesMissingArchiveFile(archive_paths); | 959 DeletePagesMissingArchiveFile(archive_paths); |
| 1035 DeleteOrphanedArchives(archive_paths); | 960 DeleteOrphanedArchives(archive_paths); |
| 1036 } | 961 } |
| 1037 | 962 |
| 1038 void OfflinePageModelImpl::ExpirePagesMissingArchiveFile( | 963 void OfflinePageModelImpl::DeletePagesMissingArchiveFile( |
| 1039 const std::set<base::FilePath>& archive_paths) { | 964 const std::set<base::FilePath>& archive_paths) { |
| 1040 std::vector<int64_t> ids_of_pages_missing_archive_file; | 965 std::vector<int64_t> ids_of_pages_missing_archive_file; |
| 1041 for (const auto& id_page_pair : offline_pages_) { | 966 for (const auto& id_page_pair : offline_pages_) { |
| 1042 if (archive_paths.count(id_page_pair.second.file_path) == 0UL) | 967 if (archive_paths.count(id_page_pair.second.file_path) == 0UL) |
| 1043 ids_of_pages_missing_archive_file.push_back(id_page_pair.first); | 968 ids_of_pages_missing_archive_file.push_back(id_page_pair.first); |
| 1044 } | 969 } |
| 1045 | 970 |
| 1046 if (ids_of_pages_missing_archive_file.empty()) | 971 if (ids_of_pages_missing_archive_file.empty()) |
| 1047 return; | 972 return; |
| 1048 | 973 |
| 1049 ExpirePages( | 974 DeletePagesByOfflineId( |
| 1050 ids_of_pages_missing_archive_file, GetCurrentTime(), | 975 ids_of_pages_missing_archive_file, |
| 1051 base::Bind(&OfflinePageModelImpl::OnExpirePagesMissingArchiveFileDone, | 976 base::Bind(&OfflinePageModelImpl::OnDeletePagesMissingArchiveFileDone, |
| 1052 weak_ptr_factory_.GetWeakPtr(), | 977 weak_ptr_factory_.GetWeakPtr(), |
| 1053 ids_of_pages_missing_archive_file)); | 978 ids_of_pages_missing_archive_file)); |
| 1054 } | 979 } |
| 1055 | 980 |
| 1056 void OfflinePageModelImpl::OnExpirePagesMissingArchiveFileDone( | 981 void OfflinePageModelImpl::OnDeletePagesMissingArchiveFileDone( |
| 1057 const std::vector<int64_t>& offline_ids, | 982 const std::vector<int64_t>& offline_ids, |
| 1058 bool success) { | 983 DeletePageResult result) { |
| 1059 UMA_HISTOGRAM_COUNTS("OfflinePages.Consistency.PagesMissingArchiveFileCount", | 984 UMA_HISTOGRAM_COUNTS("OfflinePages.Consistency.PagesMissingArchiveFileCount", |
| 1060 static_cast<int32_t>(offline_ids.size())); | 985 static_cast<int32_t>(offline_ids.size())); |
| 1061 UMA_HISTOGRAM_BOOLEAN( | 986 UMA_HISTOGRAM_ENUMERATION( |
| 1062 "OfflinePages.Consistency.ExpirePagesMissingArchiveFileResult", success); | 987 "OfflinePages.Consistency.DeletePagesMissingArchiveFileResult", |
| 988 static_cast<int>(result), | |
| 989 static_cast<int>(DeletePageResult::RESULT_COUNT)); | |
| 1063 } | 990 } |
| 1064 | 991 |
| 1065 void OfflinePageModelImpl::DeleteOrphanedArchives( | 992 void OfflinePageModelImpl::DeleteOrphanedArchives( |
| 1066 const std::set<base::FilePath>& archive_paths) { | 993 const std::set<base::FilePath>& archive_paths) { |
| 1067 // Archives are considered orphaned unless they are pointed to by some pages. | 994 // Archives are considered orphaned unless they are pointed to by some pages. |
| 1068 std::set<base::FilePath> orphaned_archive_set(archive_paths); | 995 std::set<base::FilePath> orphaned_archive_set(archive_paths); |
| 1069 for (const auto& id_page_pair : offline_pages_) | 996 for (const auto& id_page_pair : offline_pages_) |
| 1070 orphaned_archive_set.erase(id_page_pair.second.file_path); | 997 orphaned_archive_set.erase(id_page_pair.second.file_path); |
| 1071 | 998 |
| 1072 if (orphaned_archive_set.empty()) | 999 if (orphaned_archive_set.empty()) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1099 void OfflinePageModelImpl::ClearStorageIfNeeded( | 1026 void OfflinePageModelImpl::ClearStorageIfNeeded( |
| 1100 const ClearStorageCallback& callback) { | 1027 const ClearStorageCallback& callback) { |
| 1101 // Create Storage Manager if necessary. | 1028 // Create Storage Manager if necessary. |
| 1102 if (!storage_manager_) { | 1029 if (!storage_manager_) { |
| 1103 storage_manager_.reset(new OfflinePageStorageManager( | 1030 storage_manager_.reset(new OfflinePageStorageManager( |
| 1104 this, GetPolicyController(), archive_manager_.get())); | 1031 this, GetPolicyController(), archive_manager_.get())); |
| 1105 } | 1032 } |
| 1106 storage_manager_->ClearPagesIfNeeded(callback); | 1033 storage_manager_->ClearPagesIfNeeded(callback); |
| 1107 } | 1034 } |
| 1108 | 1035 |
| 1109 void OfflinePageModelImpl::OnStorageCleared(size_t expired_page_count, | 1036 void OfflinePageModelImpl::OnStorageCleared(size_t deleted_page_count, |
| 1110 ClearStorageResult result) { | 1037 ClearStorageResult result) { |
| 1111 UMA_HISTOGRAM_ENUMERATION("OfflinePages.ClearStorageResult", | 1038 UMA_HISTOGRAM_ENUMERATION("OfflinePages.ClearStorageResult", |
| 1112 static_cast<int>(result), | 1039 static_cast<int>(result), |
| 1113 static_cast<int>(ClearStorageResult::RESULT_COUNT)); | 1040 static_cast<int>(ClearStorageResult::RESULT_COUNT)); |
| 1114 if (expired_page_count > 0) { | 1041 if (deleted_page_count > 0) { |
| 1115 UMA_HISTOGRAM_COUNTS("OfflinePages.ExpirePage.BatchSize", | 1042 UMA_HISTOGRAM_COUNTS("OfflinePages.ClearStorageBatchSize", |
| 1116 static_cast<int32_t>(expired_page_count)); | 1043 static_cast<int32_t>(deleted_page_count)); |
| 1117 } | 1044 } |
| 1118 } | 1045 } |
| 1119 | 1046 |
| 1120 void OfflinePageModelImpl::PostClearStorageIfNeededTask(bool delayed) { | 1047 void OfflinePageModelImpl::PostClearStorageIfNeededTask(bool delayed) { |
| 1121 base::TimeDelta delay = | 1048 base::TimeDelta delay = |
| 1122 delayed ? kStorageManagerStartingDelay : base::TimeDelta(); | 1049 delayed ? kStorageManagerStartingDelay : base::TimeDelta(); |
| 1123 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1050 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1124 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, | 1051 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, |
| 1125 weak_ptr_factory_.GetWeakPtr(), | 1052 weak_ptr_factory_.GetWeakPtr(), |
| 1126 base::Bind(&OfflinePageModelImpl::OnStorageCleared, | 1053 base::Bind(&OfflinePageModelImpl::OnStorageCleared, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1141 } | 1068 } |
| 1142 | 1069 |
| 1143 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1070 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1144 } | 1071 } |
| 1145 | 1072 |
| 1146 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1073 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
| 1147 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1074 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
| 1148 } | 1075 } |
| 1149 | 1076 |
| 1150 } // namespace offline_pages | 1077 } // namespace offline_pages |
| OLD | NEW |