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 "base/sequenced_task_runner_helpers.h" | |
13 #include "chrome/browser/engagement/important_sites_util.h" | |
14 #include "content/public/browser/local_storage_usage_info.h" | |
15 #include "storage/browser/quota/quota_manager.h" | |
16 | |
17 namespace content { | |
18 class DOMStorageContext; | |
19 } | |
20 | |
21 namespace storage { | |
22 class QuotaManager; | |
23 } | |
24 | |
25 // A helper class for important storage that retrieves the localstorage and | |
26 // quota usage for each domain in |ImportantDomainInfo|, populates | |
27 // |ImportantDomainInfo::usage| in the |sites| entries and return the result via | |
28 // |callback|. | |
29 class ImportantSitesUsageCounter { | |
30 public: | |
31 using UsageCallback = base::Callback<void( | |
32 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites)>; | |
33 | |
34 // Populates the ImportantDomainInfo::usage field of each site with the amount | |
35 // of localstorage and quota bytes used. |callback| is synchronously invoked | |
Bernhard Bauer
2017/05/04 14:16:44
The callback is called asynchronously, no?
dullweber
2017/05/05 08:35:27
Oh, yes. Thanks!
| |
36 // on the UI thread with the |sites| vector (populated with usage) as an | |
37 // argument. | |
38 static void GetUsage( | |
39 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites, | |
40 storage::QuotaManager* quota_manager, | |
41 content::DOMStorageContext* dom_storage_context, | |
42 UsageCallback callback); | |
Bernhard Bauer
2017/05/04 14:16:44
Nit: Callbacks are usually passed by const referen
dullweber
2017/05/05 08:35:28
changed to OnceCallback.
| |
43 | |
44 private: | |
45 friend class base::DeleteHelper<ImportantSitesUsageCounter>; | |
46 | |
47 ImportantSitesUsageCounter( | |
48 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites, | |
49 storage::QuotaManager* quota_manager, | |
50 content::DOMStorageContext* dom_storage_context, | |
51 UsageCallback callback); | |
52 ~ImportantSitesUsageCounter(); | |
53 | |
54 void RunAndDestroySelf(); | |
55 | |
56 void GetQuotaUsageOnIOThread(); | |
57 | |
58 void ReceiveQuotaUsageOnIOThread( | |
59 const std::vector<storage::UsageInfo>& usage_infos); | |
60 | |
61 void ReceiveQuotaUsage(const std::vector<storage::UsageInfo>& usage_infos); | |
62 | |
63 void ReceiveLocalStorageUsage( | |
64 const std::vector<content::LocalStorageUsageInfo>& storage_infos); | |
65 | |
66 // Look up the corresponding ImportantDomainInfo for |url| and increase its | |
67 // usage by |size|. | |
68 void IncrementUsage(const std::string& domain, int64_t size); | |
69 | |
70 void Done(); | |
71 | |
72 UsageCallback callback_; | |
73 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites_; | |
74 storage::QuotaManager* quota_manager_; | |
75 content::DOMStorageContext* dom_storage_context_; | |
76 int tasks_; | |
Bernhard Bauer
2017/05/04 14:16:44
DISALLOW_IMPLICIT_CONSTRUCTORS()
dullweber
2017/05/05 08:35:27
Done.
| |
77 }; | |
78 | |
79 #endif // CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_USAGE_COUNTER_H_ | |
OLD | NEW |