Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_service_worker_helper.h
blobc8ddddd52714f109feb928a0c474e81720e11616
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_SERVICE_WORKER_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_SERVICE_WORKER_HELPER_H_
8 #include <list>
9 #include <set>
10 #include <vector>
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "content/public/browser/service_worker_context.h"
15 #include "content/public/browser/service_worker_usage_info.h"
16 #include "url/gurl.h"
18 class Profile;
20 // BrowsingDataServiceWorkerHelper is an interface for classes dealing with
21 // aggregating and deleting browsing data stored for Service Workers -
22 // registrations, scripts, and caches.
23 // A client of this class need to call StartFetching from the UI thread to
24 // initiate the flow, and it'll be notified by the callback in its UI thread at
25 // some later point.
26 class BrowsingDataServiceWorkerHelper
27 : public base::RefCountedThreadSafe<BrowsingDataServiceWorkerHelper> {
28 public:
29 using FetchCallback =
30 base::Callback<void(const std::list<content::ServiceWorkerUsageInfo>&)>;
32 // Create a BrowsingDataServiceWorkerHelper instance for the Service Workers
33 // stored in |context|'s associated profile's user data directory.
34 explicit BrowsingDataServiceWorkerHelper(
35 content::ServiceWorkerContext* context);
37 // Starts the fetching process, which will notify its completion via
38 // |callback|. This must be called only in the UI thread.
39 virtual void StartFetching(const FetchCallback& callback);
40 // Requests the Service Worker data for an origin be deleted.
41 virtual void DeleteServiceWorkers(const GURL& origin);
43 protected:
44 virtual ~BrowsingDataServiceWorkerHelper();
46 // Owned by the profile.
47 content::ServiceWorkerContext* service_worker_context_;
49 private:
50 friend class base::RefCountedThreadSafe<BrowsingDataServiceWorkerHelper>;
52 // Enumerates all Service Worker instances on the IO thread.
53 void FetchServiceWorkerUsageInfoOnIOThread(const FetchCallback& callback);
55 // Deletes Service Workers for an origin the IO thread.
56 void DeleteServiceWorkersOnIOThread(const GURL& origin);
58 DISALLOW_COPY_AND_ASSIGN(BrowsingDataServiceWorkerHelper);
61 // This class is an implementation of BrowsingDataServiceWorkerHelper that does
62 // not fetch its information from the Service Worker context, but is passed the
63 // info as a parameter.
64 class CannedBrowsingDataServiceWorkerHelper
65 : public BrowsingDataServiceWorkerHelper {
66 public:
67 // Contains information about a Service Worker.
68 struct PendingServiceWorkerUsageInfo {
69 PendingServiceWorkerUsageInfo(const GURL& origin,
70 const std::vector<GURL>& scopes);
71 ~PendingServiceWorkerUsageInfo();
73 bool operator<(const PendingServiceWorkerUsageInfo& other) const;
75 GURL origin;
76 std::vector<GURL> scopes;
79 explicit CannedBrowsingDataServiceWorkerHelper(
80 content::ServiceWorkerContext* context);
82 // Add a Service Worker to the set of canned Service Workers that is
83 // returned by this helper.
84 void AddServiceWorker(const GURL& origin, const std::vector<GURL>& scopes);
86 // Clear the list of canned Service Workers.
87 void Reset();
89 // True if no Service Workers are currently stored.
90 bool empty() const;
92 // Returns the number of currently stored Service Workers.
93 size_t GetServiceWorkerCount() const;
95 // Returns the current list of Service Workers.
96 const std::set<
97 CannedBrowsingDataServiceWorkerHelper::PendingServiceWorkerUsageInfo>&
98 GetServiceWorkerUsageInfo() const;
100 // BrowsingDataServiceWorkerHelper methods.
101 void StartFetching(const FetchCallback& callback) override;
102 void DeleteServiceWorkers(const GURL& origin) override;
104 private:
105 ~CannedBrowsingDataServiceWorkerHelper() override;
107 std::set<PendingServiceWorkerUsageInfo> pending_service_worker_info_;
109 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataServiceWorkerHelper);
112 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_SERVICE_WORKER_HELPER_H_