Index: chrome/browser/engagement/important_sites_usage_counter.h |
diff --git a/chrome/browser/engagement/important_sites_usage_counter.h b/chrome/browser/engagement/important_sites_usage_counter.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fe35704e2ebba376d7b4f0e58bc4df9e51fb0ecd |
--- /dev/null |
+++ b/chrome/browser/engagement/important_sites_usage_counter.h |
@@ -0,0 +1,69 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_USAGE_COUNTER_H_ |
+#define CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_USAGE_COUNTER_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/callback.h" |
+#include "chrome/browser/engagement/important_sites_util.h" |
+#include "content/public/browser/local_storage_usage_info.h" |
+#include "storage/browser/quota/quota_manager.h" |
+ |
+namespace content { |
+class DOMStorageContext; |
+} |
+ |
+namespace storage { |
+class QuotaManager; |
+} |
+ |
+// A helper class for important storage that retrieves the localstorage and |
+// quota usage for each domain in |ImportantDomainInfo|, populates |
+// |ImportantDomainInfo::usage| in the |sites| entries and return the result via |
+// |callback|. |
+class ImportantSitesUsageCounter { |
+ public: |
+ using UsageCallback = base::Callback<void( |
+ std::vector<ImportantSitesUtil::ImportantDomainInfo> sites)>; |
+ |
+ // Populates the ImportantDomainInfo::usage field of each site with the amount |
+ // of localstorage and quota bytes used. The |sites| vector with populated |
dominickn
2017/04/11 00:18:20
Nit: Replace last sentence with:
|callback| is sy
dullweber
2017/04/11 09:01:34
Done.
|
+ // usage fields is returned by |callback|. |
+ ImportantSitesUsageCounter( |
+ std::vector<ImportantSitesUtil::ImportantDomainInfo> sites, |
+ storage::QuotaManager* quota_manager, |
+ content::DOMStorageContext* dom_storage_context, |
+ ImportantSitesUsageCounter::UsageCallback callback); |
+ ~ImportantSitesUsageCounter(); |
+ |
+ void RunAndDestroySelf(); |
+ |
+ private: |
+ void GetQuotaUsageOnIOThread(); |
+ |
+ void ReceiveQuotaUsageOnIOThread( |
+ const std::vector<storage::UsageInfo>& usage_infos); |
+ |
+ void ReceiveQuotaUsage(const std::vector<storage::UsageInfo>& usage_infos); |
+ |
+ void ReceiveLocalStorageUsage( |
+ const std::vector<content::LocalStorageUsageInfo>& storage_infos); |
+ |
+ // Look up the corresponding ImportantDomainInfo for |url| and increase its |
+ // usage by |size|. |
+ void IncrementUsage(const std::string& domain, int64_t size); |
+ |
+ void Done(); |
+ |
+ UsageCallback callback_; |
+ std::vector<ImportantSitesUtil::ImportantDomainInfo> sites_; |
+ storage::QuotaManager* quota_manager_; |
+ content::DOMStorageContext* dom_storage_context_; |
+ int tasks_; |
+}; |
+ |
+#endif // CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_USAGE_COUNTER_H_ |