Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_USAGE_COUNTER_H_ | |
| 6 #define CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_USAGE_COUNTER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "chrome/browser/engagement/important_sites_util.h" | |
| 13 #include "content/public/browser/local_storage_usage_info.h" | |
| 14 #include "storage/browser/quota/quota_manager.h" | |
| 15 | |
| 16 namespace content { | |
| 17 class DOMStorageContext; | |
| 18 } | |
| 19 | |
| 20 namespace storage { | |
| 21 class QuotaManager; | |
| 22 } | |
| 23 | |
| 24 // A helper class for important storage that retrieves the localstorage and | |
| 25 // quota usage for each domain in |ImportantDomainInfo|, populates | |
| 26 // |ImportantDomainInfo::usage| in the |sites| entries and return the result via | |
| 27 // |callback|. | |
| 28 class ImportantSitesUsageCounter { | |
| 29 public: | |
| 30 using UsageCallback = base::Callback<void( | |
| 31 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites)>; | |
| 32 | |
| 33 // Populates the ImportantDomainInfo::usage field of each site with the amount | |
| 34 // 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.
| |
| 35 // usage fields is returned by |callback|. | |
| 36 ImportantSitesUsageCounter( | |
| 37 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites, | |
| 38 storage::QuotaManager* quota_manager, | |
| 39 content::DOMStorageContext* dom_storage_context, | |
| 40 ImportantSitesUsageCounter::UsageCallback callback); | |
| 41 ~ImportantSitesUsageCounter(); | |
| 42 | |
| 43 void RunAndDestroySelf(); | |
| 44 | |
| 45 private: | |
| 46 void GetQuotaUsageOnIOThread(); | |
| 47 | |
| 48 void ReceiveQuotaUsageOnIOThread( | |
| 49 const std::vector<storage::UsageInfo>& usage_infos); | |
| 50 | |
| 51 void ReceiveQuotaUsage(const std::vector<storage::UsageInfo>& usage_infos); | |
| 52 | |
| 53 void ReceiveLocalStorageUsage( | |
| 54 const std::vector<content::LocalStorageUsageInfo>& storage_infos); | |
| 55 | |
| 56 // Look up the corresponding ImportantDomainInfo for |url| and increase its | |
| 57 // usage by |size|. | |
| 58 void IncrementUsage(const std::string& domain, int64_t size); | |
| 59 | |
| 60 void Done(); | |
| 61 | |
| 62 UsageCallback callback_; | |
| 63 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites_; | |
| 64 storage::QuotaManager* quota_manager_; | |
| 65 content::DOMStorageContext* dom_storage_context_; | |
| 66 int tasks_; | |
| 67 }; | |
| 68 | |
| 69 #endif // CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_USAGE_COUNTER_H_ | |
| OLD | NEW |