Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: chrome/browser/engagement/important_sites_usage_counter.h

Issue 2752263003: Count site data size for important sites (Closed)
Patch Set: rebase and remove deb file Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/macros.h"
13 #include "base/sequenced_task_runner_helpers.h"
14 #include "chrome/browser/engagement/important_sites_util.h"
15 #include "content/public/browser/local_storage_usage_info.h"
16 #include "storage/browser/quota/quota_manager.h"
17
18 namespace content {
19 class DOMStorageContext;
20 }
21
22 namespace storage {
23 class QuotaManager;
24 }
25
26 // A helper class for important storage that retrieves the localstorage and
27 // quota usage for each domain in |ImportantDomainInfo|, populates
28 // |ImportantDomainInfo::usage| in the |sites| entries and return the result via
29 // |callback|.
30 class ImportantSitesUsageCounter {
31 public:
32 using UsageCallback = base::OnceCallback<void(
33 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites)>;
34
35 // Populates the ImportantDomainInfo::usage field of each site with the amount
36 // of localstorage and quota bytes used. |callback| is asynchronously invoked
37 // on the UI thread with the |sites| vector (populated with usage) as an
38 // argument.
39 static void GetUsage(
40 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites,
41 storage::QuotaManager* quota_manager,
42 content::DOMStorageContext* dom_storage_context,
43 UsageCallback callback);
44
45 private:
46 friend class base::DeleteHelper<ImportantSitesUsageCounter>;
47
48 ImportantSitesUsageCounter(
49 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites,
50 storage::QuotaManager* quota_manager,
51 content::DOMStorageContext* dom_storage_context,
52 UsageCallback callback);
53 ~ImportantSitesUsageCounter();
54
55 void RunAndDestroySelfWhenFinished();
56
57 void GetQuotaUsageOnIOThread();
58
59 void ReceiveQuotaUsageOnIOThread(
60 const std::vector<storage::UsageInfo>& usage_infos);
61
62 void ReceiveQuotaUsage(const std::vector<storage::UsageInfo>& usage_infos);
63
64 void ReceiveLocalStorageUsage(
65 const std::vector<content::LocalStorageUsageInfo>& storage_infos);
66
67 // Look up the corresponding ImportantDomainInfo for |url| and increase its
68 // usage by |size|.
69 void IncrementUsage(const std::string& domain, int64_t size);
70
71 void Done();
72
73 UsageCallback callback_;
74 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites_;
75 storage::QuotaManager* quota_manager_;
76 content::DOMStorageContext* dom_storage_context_;
77 int tasks_;
78
79 DISALLOW_IMPLICIT_CONSTRUCTORS(ImportantSitesUsageCounter);
80 };
81
82 #endif // CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_USAGE_COUNTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698