Commit 444db4b4 authored by romax's avatar romax Committed by Commit bot

[Offline Pages] Add cached offline page utils and show usage in settings.

Added some utility functions for cached offline pages:
Get sizes of all cached offline pages;
Delete all cached offline pages.
Also added the usage of cached offline pages to the number shown at:
Chrome Settings -> Privacy -> Clear Browsing Data -> Cache

BUG=716142

Review-Url: https://codereview.chromium.org/2860573004
Cr-Commit-Position: refs/heads/master@{#472255}
parent 07c2492c
...@@ -129,6 +129,19 @@ void CheckDuplicateOngoingDownloads( ...@@ -129,6 +129,19 @@ void CheckDuplicateOngoingDownloads(
request_coordinator_continuation, browser_context, url, callback)); request_coordinator_continuation, browser_context, url, callback));
} }
void DoCalculateSizeBetween(
const offline_pages::SizeInBytesCallback& callback,
const base::Time& begin_time,
const base::Time& end_time,
const offline_pages::MultipleOfflinePageItemResult& result) {
int64_t total_size = 0;
for (auto& page : result) {
if (begin_time <= page.creation_time && page.creation_time < end_time)
total_size += page.file_size;
}
callback.Run(total_size);
}
} // namespace } // namespace
// static // static
...@@ -308,4 +321,23 @@ bool OfflinePageUtils::CanDownloadAsOfflinePage( ...@@ -308,4 +321,23 @@ bool OfflinePageUtils::CanDownloadAsOfflinePage(
net::MatchesMimeType(contents_mime_type, "application/xhtml+xml")); net::MatchesMimeType(contents_mime_type, "application/xhtml+xml"));
} }
// static
bool OfflinePageUtils::GetCachedOfflinePageSizeBetween(
content::BrowserContext* browser_context,
const SizeInBytesCallback& callback,
const base::Time& begin_time,
const base::Time& end_time) {
OfflinePageModel* offline_page_model =
OfflinePageModelFactory::GetForBrowserContext(browser_context);
if (!offline_page_model || begin_time > end_time)
return false;
OfflinePageModelQueryBuilder builder;
builder.RequireRemovedOnCacheReset(
OfflinePageModelQuery::Requirement::INCLUDE_MATCHING);
offline_page_model->GetPagesMatchingQuery(
builder.Build(offline_page_model->GetPolicyController()),
base::Bind(&DoCalculateSizeBetween, callback, begin_time, end_time));
return true;
}
} // namespace offline_pages } // namespace offline_pages
...@@ -9,8 +9,13 @@ ...@@ -9,8 +9,13 @@
#include "base/callback.h" #include "base/callback.h"
#include "components/offline_pages/core/offline_page_model.h" #include "components/offline_pages/core/offline_page_model.h"
#include "components/offline_pages/core/offline_page_types.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace base {
class Time;
}
namespace content { namespace content {
class BrowserContext; class BrowserContext;
class WebContents; class WebContents;
...@@ -114,6 +119,16 @@ class OfflinePageUtils { ...@@ -114,6 +119,16 @@ class OfflinePageUtils {
// of download resource. // of download resource.
static bool CanDownloadAsOfflinePage(const GURL& url, static bool CanDownloadAsOfflinePage(const GURL& url,
const std::string& contents_mime_type); const std::string& contents_mime_type);
// Get total size of cache offline pages for a given time range. Returns false
// when an OfflinePageModel cannot be acquired using the |browser_context|, or
// the time range is invalid (|begin_time| > |end_time|). Also returning false
// means no callback should be expected.
static bool GetCachedOfflinePageSizeBetween(
content::BrowserContext* browser_context,
const SizeInBytesCallback& callback,
const base::Time& begin_time,
const base::Time& end_time);
}; };
} // namespace offline_pages } // namespace offline_pages
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/android/offline_pages/offline_page_model_factory.h" #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
#include "components/offline_pages/core/client_namespace_constants.h" #include "components/offline_pages/core/client_namespace_constants.h"
#include "components/offline_pages/core/offline_page_feature.h" #include "components/offline_pages/core/offline_page_feature.h"
#include "components/offline_pages/core/offline_page_model.h" #include "components/offline_pages/core/offline_page_model.h"
#include "components/offline_pages/core/offline_page_model_impl.h"
#include "components/offline_pages/core/offline_page_test_archiver.h" #include "components/offline_pages/core/offline_page_test_archiver.h"
#include "components/offline_pages/core/offline_page_test_store.h" #include "components/offline_pages/core/offline_page_test_store.h"
#include "components/offline_pages/core/offline_page_types.h" #include "components/offline_pages/core/offline_page_types.h"
...@@ -50,6 +52,7 @@ const int64_t kTestFileSize = 876543LL; ...@@ -50,6 +52,7 @@ const int64_t kTestFileSize = 876543LL;
const char* kTestPage1ClientId = "1234"; const char* kTestPage1ClientId = "1234";
const char* kTestPage2ClientId = "5678"; const char* kTestPage2ClientId = "5678";
const char* kTestPage3ClientId = "7890"; const char* kTestPage3ClientId = "7890";
const char* kTestPage4ClientId = "42";
void CheckDuplicateDownloadsCallback( void CheckDuplicateDownloadsCallback(
OfflinePageUtils::DuplicateCheckResult* out_result, OfflinePageUtils::DuplicateCheckResult* out_result,
...@@ -90,6 +93,7 @@ class OfflinePageUtilsTest ...@@ -90,6 +93,7 @@ class OfflinePageUtilsTest
void OnClearAllDone(); void OnClearAllDone();
void OnExpirePageDone(bool success); void OnExpirePageDone(bool success);
void OnGetURLDone(const GURL& url); void OnGetURLDone(const GURL& url);
void OnSizeInBytesCalculated(int64_t size);
// OfflinePageTestArchiver::Observer implementation: // OfflinePageTestArchiver::Observer implementation:
void SetLastPathCreatedByArchiver(const base::FilePath& file_path) override; void SetLastPathCreatedByArchiver(const base::FilePath& file_path) override;
...@@ -98,6 +102,9 @@ class OfflinePageUtilsTest ...@@ -98,6 +102,9 @@ class OfflinePageUtilsTest
content::WebContents* web_contents() const { return web_contents_.get(); } content::WebContents* web_contents() const { return web_contents_.get(); }
int64_t offline_id() const { return offline_id_; } int64_t offline_id() const { return offline_id_; }
int64_t last_cache_size() { return last_cache_size_; }
void CreateCachedOfflinePages(base::SimpleTestClock* clock);
private: private:
void CreateOfflinePages(); void CreateOfflinePages();
...@@ -112,6 +119,7 @@ class OfflinePageUtilsTest ...@@ -112,6 +119,7 @@ class OfflinePageUtilsTest
TestingProfile profile_; TestingProfile profile_;
std::unique_ptr<content::WebContents> web_contents_; std::unique_ptr<content::WebContents> web_contents_;
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
int64_t last_cache_size_;
}; };
OfflinePageUtilsTest::OfflinePageUtilsTest() = default; OfflinePageUtilsTest::OfflinePageUtilsTest() = default;
...@@ -180,6 +188,10 @@ void OfflinePageUtilsTest::OnGetURLDone(const GURL& url) { ...@@ -180,6 +188,10 @@ void OfflinePageUtilsTest::OnGetURLDone(const GURL& url) {
url_ = url; url_ = url;
} }
void OfflinePageUtilsTest::OnSizeInBytesCalculated(int64_t size) {
last_cache_size_ = size;
}
void OfflinePageUtilsTest::SetLastPathCreatedByArchiver( void OfflinePageUtilsTest::SetLastPathCreatedByArchiver(
const base::FilePath& file_path) {} const base::FilePath& file_path) {}
...@@ -211,6 +223,42 @@ void OfflinePageUtilsTest::CreateRequests() { ...@@ -211,6 +223,42 @@ void OfflinePageUtilsTest::CreateRequests() {
RunUntilIdle(); RunUntilIdle();
} }
void OfflinePageUtilsTest::CreateCachedOfflinePages(
base::SimpleTestClock* clock) {
// Add 4 temporary pages to the model used for test cases. And setting current
// time as the 00:00:00 time anchor.
offline_pages::ClientId client_id;
client_id.name_space = kBookmarkNamespace;
clock->SetNow(base::Time::Now());
// Time 01:00:00.
clock->Advance(base::TimeDelta::FromHours(1));
std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver(
kTestPage1Url, base::FilePath(FILE_PATH_LITERAL("page1.mhtml"))));
client_id.id = kTestPage1ClientId;
SavePage(kTestPage1Url, client_id, std::move(archiver));
// time 02:00:00.
clock->Advance(base::TimeDelta::FromHours(1));
archiver = BuildArchiver(kTestPage2Url,
base::FilePath(FILE_PATH_LITERAL("page2.mhtml")));
client_id.id = kTestPage2ClientId;
SavePage(kTestPage2Url, client_id, std::move(archiver));
// time 03:00:00.
clock->Advance(base::TimeDelta::FromHours(1));
archiver = BuildArchiver(kTestPage3Url,
base::FilePath(FILE_PATH_LITERAL("page3.mhtml")));
client_id.id = kTestPage3ClientId;
SavePage(kTestPage3Url, client_id, std::move(archiver));
// Add a temporary page to test boundary at 10:00:00.
clock->Advance(base::TimeDelta::FromHours(7));
archiver = BuildArchiver(kTestPage4Url,
base::FilePath(FILE_PATH_LITERAL("page4.mhtml")));
client_id.id = kTestPage4ClientId;
SavePage(kTestPage4Url, client_id, std::move(archiver));
// Reset clock->to 03:00:00.
clock->SetNow(clock->Now() - base::TimeDelta::FromHours(7));
}
std::unique_ptr<OfflinePageTestArchiver> OfflinePageUtilsTest::BuildArchiver( std::unique_ptr<OfflinePageTestArchiver> OfflinePageUtilsTest::BuildArchiver(
const GURL& url, const GURL& url,
const base::FilePath& file_name) { const base::FilePath& file_name) {
...@@ -310,4 +358,135 @@ TEST_F(OfflinePageUtilsTest, EqualsIgnoringFragment) { ...@@ -310,4 +358,135 @@ TEST_F(OfflinePageUtilsTest, EqualsIgnoringFragment) {
GURL("http://example.com/"), GURL("http://test.com/#test"))); GURL("http://example.com/"), GURL("http://test.com/#test")));
} }
TEST_F(OfflinePageUtilsTest, TestGetCachedOfflinePageSizeBetween) {
// Set a test clock before adding cached offline pages.
// The clock will be at 03:00:00 after adding pages.
OfflinePageModel* model =
OfflinePageModelFactory::GetForBrowserContext(profile());
base::SimpleTestClock clock;
static_cast<OfflinePageModelImpl*>(model)->set_testing_clock(&clock);
CreateCachedOfflinePages(&clock);
// Advance the clock so that we don't hit the time check boundary.
clock.Advance(base::TimeDelta::FromMinutes(5));
// Get the size of cached offline pages between 01:05:00 and 03:05:00.
bool ret = OfflinePageUtils::GetCachedOfflinePageSizeBetween(
profile(),
base::Bind(&OfflinePageUtilsTest::OnSizeInBytesCalculated, AsWeakPtr()),
clock.Now() - base::TimeDelta::FromHours(2), clock.Now());
RunUntilIdle();
EXPECT_TRUE(ret);
EXPECT_EQ(kTestFileSize * 2, last_cache_size());
}
TEST_F(OfflinePageUtilsTest, TestGetCachedOfflinePageSizeNoPageInModel) {
// Set a test clock.
OfflinePageModel* model =
OfflinePageModelFactory::GetForBrowserContext(profile());
base::SimpleTestClock clock;
static_cast<OfflinePageModelImpl*>(model)->set_testing_clock(&clock);
clock.Advance(base::TimeDelta::FromHours(3));
// Get the size of cached offline pages between 01:00:00 and 03:00:00.
// Since no temporary pages were added to the model, the cache size should be
// 0.
bool ret = OfflinePageUtils::GetCachedOfflinePageSizeBetween(
profile(),
base::Bind(&OfflinePageUtilsTest::OnSizeInBytesCalculated, AsWeakPtr()),
clock.Now() - base::TimeDelta::FromHours(2), clock.Now());
RunUntilIdle();
EXPECT_TRUE(ret);
EXPECT_EQ(0, last_cache_size());
}
TEST_F(OfflinePageUtilsTest, TestGetCachedOfflinePageSizeNoPageInRange) {
// Set a test clock before adding cached offline pages.
// The clock will be at 03:00:00 after adding pages.
OfflinePageModel* model =
OfflinePageModelFactory::GetForBrowserContext(profile());
base::SimpleTestClock clock;
static_cast<OfflinePageModelImpl*>(model)->set_testing_clock(&clock);
CreateCachedOfflinePages(&clock);
// Advance the clock so that we don't hit the time check boundary.
clock.Advance(base::TimeDelta::FromMinutes(5));
// Get the size of cached offline pages between 03:04:00 and 03:05:00.
bool ret = OfflinePageUtils::GetCachedOfflinePageSizeBetween(
profile(),
base::Bind(&OfflinePageUtilsTest::OnSizeInBytesCalculated, AsWeakPtr()),
clock.Now() - base::TimeDelta::FromMinutes(1), clock.Now());
RunUntilIdle();
EXPECT_TRUE(ret);
EXPECT_EQ(0, last_cache_size());
}
TEST_F(OfflinePageUtilsTest, TestGetCachedOfflinePageSizeAllPagesInRange) {
// Set a test clock before adding cached offline pages.
// The clock will be at 03:00:00 after adding pages.
OfflinePageModel* model =
OfflinePageModelFactory::GetForBrowserContext(profile());
base::SimpleTestClock clock;
static_cast<OfflinePageModelImpl*>(model)->set_testing_clock(&clock);
CreateCachedOfflinePages(&clock);
// Advance the clock to 23:00:00.
clock.Advance(base::TimeDelta::FromHours(20));
// Get the size of cached offline pages between -01:00:00 and 23:00:00.
bool ret = OfflinePageUtils::GetCachedOfflinePageSizeBetween(
profile(),
base::Bind(&OfflinePageUtilsTest::OnSizeInBytesCalculated, AsWeakPtr()),
clock.Now() - base::TimeDelta::FromHours(24), clock.Now());
RunUntilIdle();
EXPECT_TRUE(ret);
EXPECT_EQ(kTestFileSize * 4, last_cache_size());
}
TEST_F(OfflinePageUtilsTest, TestGetCachedOfflinePageSizeAllPagesInvalidRange) {
// Set a test clock before adding cached offline pages.
// The clock will be at 03:00:00 after adding pages.
OfflinePageModel* model =
OfflinePageModelFactory::GetForBrowserContext(profile());
base::SimpleTestClock clock;
static_cast<OfflinePageModelImpl*>(model)->set_testing_clock(&clock);
CreateCachedOfflinePages(&clock);
// Advance the clock to 23:00:00.
clock.Advance(base::TimeDelta::FromHours(20));
// Get the size of cached offline pages between 23:00:00 and -01:00:00, which
// is an invalid range, the return value will be false and there will be no
// callback.
bool ret = OfflinePageUtils::GetCachedOfflinePageSizeBetween(
profile(),
base::Bind(&OfflinePageUtilsTest::OnSizeInBytesCalculated, AsWeakPtr()),
clock.Now(), clock.Now() - base::TimeDelta::FromHours(24));
RunUntilIdle();
EXPECT_FALSE(ret);
}
TEST_F(OfflinePageUtilsTest, TestGetCachedOfflinePageSizeEdgeCase) {
// Set a test clock before adding cached offline pages.
// The clock will be at 03:00:00 after adding pages.
OfflinePageModel* model =
OfflinePageModelFactory::GetForBrowserContext(profile());
base::SimpleTestClock clock;
static_cast<OfflinePageModelImpl*>(model)->set_testing_clock(&clock);
CreateCachedOfflinePages(&clock);
// Get the size of cached offline pages between 02:00:00 and 03:00:00, since
// we are using a [begin_time, end_time) range so there will be only 1 page
// when query for this time range.
bool ret = OfflinePageUtils::GetCachedOfflinePageSizeBetween(
profile(),
base::Bind(&OfflinePageUtilsTest::OnSizeInBytesCalculated, AsWeakPtr()),
clock.Now() - base::TimeDelta::FromHours(1), clock.Now());
RunUntilIdle();
EXPECT_TRUE(ret);
EXPECT_EQ(kTestFileSize * 1, last_cache_size());
}
} // namespace offline_pages } // namespace offline_pages
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#if defined(OS_ANDROID)
#include "chrome/browser/android/offline_pages/offline_page_utils.h"
#endif // OS_ANDROID
CacheCounter::CacheResult::CacheResult(const CacheCounter* source, CacheCounter::CacheResult::CacheResult(const CacheCounter* source,
int64_t cache_size, int64_t cache_size,
bool is_upper_limit) bool is_upper_limit)
...@@ -32,8 +36,11 @@ const char* CacheCounter::GetPrefName() const { ...@@ -32,8 +36,11 @@ const char* CacheCounter::GetPrefName() const {
} }
void CacheCounter::Count() { void CacheCounter::Count() {
// Cancel existing requests. // Cancel existing requests and reset states.
weak_ptr_factory_.InvalidateWeakPtrs(); weak_ptr_factory_.InvalidateWeakPtrs();
calculated_size_ = 0;
is_upper_limit_ = false;
pending_sources_ = 1;
base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter = base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter =
browsing_data::ConditionalCacheCountingHelper::CreateForRange( browsing_data::ConditionalCacheCountingHelper::CreateForRange(
content::BrowserContext::GetDefaultStoragePartition(profile_), content::BrowserContext::GetDefaultStoragePartition(profile_),
...@@ -41,14 +48,30 @@ void CacheCounter::Count() { ...@@ -41,14 +48,30 @@ void CacheCounter::Count() {
->CountAndDestroySelfWhenFinished( ->CountAndDestroySelfWhenFinished(
base::Bind(&CacheCounter::OnCacheSizeCalculated, base::Bind(&CacheCounter::OnCacheSizeCalculated,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
#if defined(OS_ANDROID)
if (offline_pages::OfflinePageUtils::GetCachedOfflinePageSizeBetween(
profile_,
base::Bind(&CacheCounter::OnCacheSizeCalculated,
weak_ptr_factory_.GetWeakPtr(),
false /* is_upper_limit */),
GetPeriodStart(), base::Time::Max())) {
pending_sources_++;
}
#endif // OS_ANDROID
} }
void CacheCounter::OnCacheSizeCalculated(int64_t result_bytes, void CacheCounter::OnCacheSizeCalculated(bool is_upper_limit,
bool is_upper_limit) { int64_t cache_bytes) {
// A value less than 0 means a net error code. // A value less than 0 means a net error code.
if (result_bytes < 0) if (cache_bytes < 0)
return; return;
auto result =
base::MakeUnique<CacheResult>(this, result_bytes, is_upper_limit); pending_sources_--;
ReportResult(std::move(result)); calculated_size_ += cache_bytes;
is_upper_limit_ |= is_upper_limit;
if (pending_sources_ == 0) {
auto result =
base::MakeUnique<CacheResult>(this, calculated_size_, is_upper_limit_);
ReportResult(std::move(result));
}
} }
...@@ -42,15 +42,16 @@ class CacheCounter : public browsing_data::BrowsingDataCounter { ...@@ -42,15 +42,16 @@ class CacheCounter : public browsing_data::BrowsingDataCounter {
private: private:
void Count() override; void Count() override;
void OnCacheSizeCalculated(int64_t bytes, bool is_upper_limit); void OnCacheSizeCalculated(bool is_upper_limit, int64_t cache_bytes);
void FetchEstimate( void FetchEstimate(
base::WeakPtr<browsing_data::ConditionalCacheCountingHelper>); base::WeakPtr<browsing_data::ConditionalCacheCountingHelper>);
Profile* profile_; Profile* profile_;
bool pending_; int64_t calculated_size_;
bool is_upper_limit_;
int pending_sources_;
base::WeakPtrFactory<CacheCounter> weak_ptr_factory_; base::WeakPtrFactory<CacheCounter> weak_ptr_factory_;
}; };
#endif // CHROME_BROWSER_BROWSING_DATA_CACHE_COUNTER_H_ #endif // CHROME_BROWSER_BROWSING_DATA_CACHE_COUNTER_H_
...@@ -35,7 +35,7 @@ class ConditionalCacheCountingHelperBrowserTest : public InProcessBrowserTest { ...@@ -35,7 +35,7 @@ class ConditionalCacheCountingHelperBrowserTest : public InProcessBrowserTest {
void TearDownOnMainThread() override { cache_util_.reset(); } void TearDownOnMainThread() override { cache_util_.reset(); }
void CountCallback(int64_t size, bool is_upper_limit) { void CountCallback(bool is_upper_limit, int64_t size) {
// Negative values represent an unexpected error. // Negative values represent an unexpected error.
DCHECK(size >= 0 || size == net::ERR_ABORTED); DCHECK(size >= 0 || size == net::ERR_ABORTED);
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
......
...@@ -330,7 +330,7 @@ void StorageManagerHandler::UpdateBrowsingDataSize() { ...@@ -330,7 +330,7 @@ void StorageManagerHandler::UpdateBrowsingDataSize() {
weak_ptr_factory_.GetWeakPtr(), true)); weak_ptr_factory_.GetWeakPtr(), true));
} }
void StorageManagerHandler::OnGetCacheSize(int64_t size, bool is_upper_limit) { void StorageManagerHandler::OnGetCacheSize(bool is_upper_limit, int64_t size) {
DCHECK(!is_upper_limit); DCHECK(!is_upper_limit);
OnGetBrowsingDataSize(false, size); OnGetBrowsingDataSize(false, size);
} }
......
...@@ -70,7 +70,7 @@ class StorageManagerHandler : public ::options::OptionsPageUIHandler { ...@@ -70,7 +70,7 @@ class StorageManagerHandler : public ::options::OptionsPageUIHandler {
void UpdateBrowsingDataSize(); void UpdateBrowsingDataSize();
// Callback to receive the cache size. // Callback to receive the cache size.
void OnGetCacheSize(int64_t size, bool is_upper_limit); void OnGetCacheSize(bool is_upper_limit, int64_t size);
// Callback to update the UI about the size of browsing data. // Callback to update the UI about the size of browsing data.
void OnGetBrowsingDataSize(bool is_site_data, int64_t size); void OnGetBrowsingDataSize(bool is_site_data, int64_t size);
......
...@@ -261,7 +261,7 @@ void StorageHandler::UpdateBrowsingDataSize() { ...@@ -261,7 +261,7 @@ void StorageHandler::UpdateBrowsingDataSize() {
weak_ptr_factory_.GetWeakPtr(), true)); weak_ptr_factory_.GetWeakPtr(), true));
} }
void StorageHandler::OnGetCacheSize(int64_t size, bool is_upper_limit) { void StorageHandler::OnGetCacheSize(bool is_upper_limit, int64_t size) {
DCHECK(!is_upper_limit); DCHECK(!is_upper_limit);
OnGetBrowsingDataSize(false, size); OnGetBrowsingDataSize(false, size);
} }
......
...@@ -67,7 +67,7 @@ class StorageHandler : public ::settings::SettingsPageUIHandler { ...@@ -67,7 +67,7 @@ class StorageHandler : public ::settings::SettingsPageUIHandler {
void UpdateBrowsingDataSize(); void UpdateBrowsingDataSize();
// Callback to receive the cache size. // Callback to receive the cache size.
void OnGetCacheSize(int64_t size, bool is_upper_limit); void OnGetCacheSize(bool is_upper_limit, int64_t size);
// Callback to update the UI about the size of browsing data. // Callback to update the UI about the size of browsing data.
void OnGetBrowsingDataSize(bool is_site_data, int64_t size); void OnGetBrowsingDataSize(bool is_site_data, int64_t size);
......
...@@ -74,7 +74,7 @@ void ConditionalCacheCountingHelper::Finished() { ...@@ -74,7 +74,7 @@ void ConditionalCacheCountingHelper::Finished() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!is_finished_); DCHECK(!is_finished_);
is_finished_ = true; is_finished_ = true;
result_callback_.Run(calculation_result_, is_upper_limit_); result_callback_.Run(is_upper_limit_, calculation_result_);
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
} }
......
...@@ -25,9 +25,9 @@ namespace browsing_data { ...@@ -25,9 +25,9 @@ namespace browsing_data {
// Helper to count the size of the http cache data from a StoragePartition. // Helper to count the size of the http cache data from a StoragePartition.
class ConditionalCacheCountingHelper { class ConditionalCacheCountingHelper {
public: public:
// Returns the number bytes in the selected range and if this value is an // Returns if this value is an upper estimate and the number bytes in the
// upper estimate. // selected range.
typedef base::Callback<void(int64_t, bool)> CacheCountCallback; typedef base::Callback<void(bool, int64_t)> CacheCountCallback;
static ConditionalCacheCountingHelper* CreateForRange( static ConditionalCacheCountingHelper* CreateForRange(
content::StoragePartition* storage_partition, content::StoragePartition* storage_partition,
......
...@@ -77,6 +77,7 @@ typedef base::Callback<void(const OfflinePageItem*)> ...@@ -77,6 +77,7 @@ typedef base::Callback<void(const OfflinePageItem*)>
typedef base::Callback<void(const MultipleOfflinePageItemResult&)> typedef base::Callback<void(const MultipleOfflinePageItemResult&)>
MultipleOfflinePageItemCallback; MultipleOfflinePageItemCallback;
typedef base::Callback<bool(const GURL&)> UrlPredicate; typedef base::Callback<bool(const GURL&)> UrlPredicate;
typedef base::Callback<void(int64_t)> SizeInBytesCallback;
} // namespace offline_pages } // namespace offline_pages
#endif // COMPONENTS_OFFLINE_PAGES_CORE_OFFLINE_PAGE_TYPES_H_ #endif // COMPONENTS_OFFLINE_PAGES_CORE_OFFLINE_PAGE_TYPES_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment