OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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_BROWSING_DATA_BROWSING_DATA_CACHE_STORAGE_HELPER_H_ | |
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CACHE_STORAGE_HELPER_H_ | |
7 | |
8 #include <list> | |
9 #include <set> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/callback.h" | |
14 #include "base/compiler_specific.h" | |
15 #include "base/files/file_path.h" | |
16 #include "base/memory/ref_counted.h" | |
17 #include "base/synchronization/lock.h" | |
18 #include "base/time/time.h" | |
19 #include "content/public/browser/cache_storage_context.h" | |
20 #include "content/public/browser/cache_storage_usage_info.h" | |
21 #include "url/gurl.h" | |
22 | |
23 class Profile; | |
24 | |
25 // BrowsingDataCacheStorageHelper is an interface for classes dealing with | |
26 // aggregating and deleting browsing data stored for Cache Storage. | |
27 // A client of this class need to call StartFetching from the UI thread to | |
28 // initiate the flow, and it'll be notified by the callback in its UI thread at | |
29 // some later point. | |
30 class BrowsingDataCacheStorageHelper | |
31 : public base::RefCountedThreadSafe<BrowsingDataCacheStorageHelper> { | |
32 public: | |
33 // Create a BrowsingDataCacheStorageHelper instance for the Cache Storage | |
34 // stored in |context|'s associated profile's user data directory. | |
35 explicit BrowsingDataCacheStorageHelper( | |
36 content::CacheStorageContext* context); | |
37 | |
38 // Starts the fetching process, which will notify its completion via | |
39 // |callback|. This must be called only in the UI thread. | |
40 virtual void StartFetching( | |
41 const base::Callback< | |
42 void(const std::list<content::CacheStorageUsageInfo>&)>& callback); | |
43 // Requests the Cache Storage data for an origin be deleted. | |
44 virtual void DeleteCacheStorage(const GURL& origin); | |
45 | |
46 protected: | |
47 virtual ~BrowsingDataCacheStorageHelper(); | |
48 | |
49 // Owned by the profile. | |
50 content::CacheStorageContext* cache_storage_context_; | |
51 | |
52 // Access to |cache_storage_info_| is triggered indirectly via the UI | |
53 // thread and guarded by |is_fetching_|. This means |cache_storage_info_| | |
54 // is only accessed while |is_fetching_| is true. The flag |is_fetching_| is | |
55 // only accessed on the UI thread. | |
56 // In the context of this class |cache_storage_info_| is only accessed on the | |
57 // context's CacheStorage thread. | |
58 std::list<content::CacheStorageUsageInfo> cache_storage_info_; | |
59 | |
60 // This member is only mutated on the UI thread. | |
61 base::Callback<void(const std::list<content::CacheStorageUsageInfo>&)> | |
62 completion_callback_; | |
63 | |
64 // Indicates whether or not we're currently fetching information: | |
65 // it's true when StartFetching() is called in the UI thread, and it's reset | |
66 // after we notified the callback in the UI thread. | |
67 // This member is only mutated on the UI thread. | |
68 bool is_fetching_ = false; | |
69 | |
70 private: | |
71 friend class base::RefCountedThreadSafe<BrowsingDataCacheStorageHelper>; | |
72 | |
73 // Enumerates all Cache Storage instances on the IO thread. | |
74 void FetchCacheStorageUsageInfoOnIOThread(); | |
75 | |
76 // Notifies the completion callback in the UI thread. | |
77 void NotifyOnUIThread(); | |
78 | |
79 // Deletes Cache Storages for an origin the IO thread. | |
michaeln
2015/08/18 22:25:51
origin -on- the IO thread
but consider removing t
| |
80 void DeleteCacheStorageOnIOThread(const GURL& origin); | |
81 | |
82 // Callback from CacheStorageContext::GetAllOriginsInfo() | |
83 void GetAllOriginsInfoCallback( | |
84 const std::vector<content::CacheStorageUsageInfo>& origins); | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(BrowsingDataCacheStorageHelper); | |
87 }; | |
88 | |
89 // This class is an implementation of BrowsingDataCacheStorageHelper that does | |
90 // not fetch its information from the Cache Storage context, but is passed the | |
91 // info as a parameter. | |
92 class CannedBrowsingDataCacheStorageHelper | |
93 : public BrowsingDataCacheStorageHelper { | |
94 public: | |
95 // Contains information about a Cache Storage. | |
96 struct PendingCacheStorageUsageInfo { | |
97 PendingCacheStorageUsageInfo(const GURL& origin, | |
98 int64 total_size_bytes, | |
99 const base::Time& last_modified); | |
100 ~PendingCacheStorageUsageInfo(); | |
101 | |
102 bool operator<(const PendingCacheStorageUsageInfo& other) const; | |
103 | |
104 GURL origin; | |
105 int64 total_size_bytes; | |
106 base::Time last_modified; | |
107 }; | |
108 | |
109 explicit CannedBrowsingDataCacheStorageHelper( | |
110 content::CacheStorageContext* context); | |
111 | |
112 // Add a Cache Storage to the set of canned Cache Storages that is | |
113 // returned by this helper. | |
114 void AddCacheStorage(const GURL& origin); | |
115 | |
116 // Clear the list of canned Cache Storages. | |
117 void Reset(); | |
118 | |
119 // True if no Cache Storages are currently stored. | |
120 bool empty() const; | |
121 | |
122 // Returns the number of currently stored Cache Storages. | |
123 size_t GetCacheStorageCount() const; | |
124 | |
125 // Returns the current list of Cache Storages. | |
126 const std::set< | |
127 CannedBrowsingDataCacheStorageHelper::PendingCacheStorageUsageInfo>& | |
128 GetCacheStorageUsageInfo() const; | |
129 | |
130 // BrowsingDataCacheStorageHelper methods. | |
131 void StartFetching(const base::Callback< | |
132 void(const std::list<content::CacheStorageUsageInfo>&)>& | |
133 callback) override; | |
134 void DeleteCacheStorage(const GURL& origin) override; | |
135 | |
136 private: | |
137 ~CannedBrowsingDataCacheStorageHelper() override; | |
138 | |
139 std::set<PendingCacheStorageUsageInfo> pending_cache_storage_info_; | |
140 | |
141 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataCacheStorageHelper); | |
142 }; | |
143 | |
144 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CACHE_STORAGE_HELPER_H_ | |
OLD | NEW |