Simplify browsing data helpers for storage types
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_local_storage_helper.h
blob910d973379f4fa927aa257a398ec631a96d6045b
1 // Copyright (c) 2012 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_LOCAL_STORAGE_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_LOCAL_STORAGE_HELPER_H_
8 #include <list>
9 #include <set>
10 #include <vector>
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/files/file_path.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/synchronization/lock.h"
17 #include "base/time/time.h"
18 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/dom_storage_context.h"
20 #include "url/gurl.h"
22 class Profile;
24 // This class fetches local storage information and provides a
25 // means to delete the data associated with an origin.
26 class BrowsingDataLocalStorageHelper
27 : public base::RefCounted<BrowsingDataLocalStorageHelper> {
28 public:
29 // Contains detailed information about local storage.
30 struct LocalStorageInfo {
31 LocalStorageInfo(
32 const GURL& origin_url,
33 int64 size,
34 base::Time last_modified);
35 ~LocalStorageInfo();
37 GURL origin_url;
38 int64 size;
39 base::Time last_modified;
42 using FetchCallback =
43 base::Callback<void(const std::list<LocalStorageInfo>&)>;
45 explicit BrowsingDataLocalStorageHelper(Profile* profile);
47 // Starts the fetching process, which will notify its completion via
48 // callback. This must be called only in the UI thread.
49 virtual void StartFetching(const FetchCallback& callback);
51 // Deletes the local storage for the |origin|.
52 virtual void DeleteOrigin(const GURL& origin);
54 protected:
55 friend class base::RefCounted<BrowsingDataLocalStorageHelper>;
56 virtual ~BrowsingDataLocalStorageHelper();
58 content::DOMStorageContext* dom_storage_context_; // Owned by the profile
60 private:
61 void GetUsageInfoCallback(
62 const FetchCallback& callback,
63 const std::vector<content::LocalStorageUsageInfo>& infos);
65 DISALLOW_COPY_AND_ASSIGN(BrowsingDataLocalStorageHelper);
68 // This class is a thin wrapper around BrowsingDataLocalStorageHelper that does
69 // not fetch its information from the local storage tracker, but gets them
70 // passed as a parameter during construction.
71 class CannedBrowsingDataLocalStorageHelper
72 : public BrowsingDataLocalStorageHelper {
73 public:
74 explicit CannedBrowsingDataLocalStorageHelper(Profile* profile);
76 // Add a local storage to the set of canned local storages that is returned
77 // by this helper.
78 void AddLocalStorage(const GURL& origin);
80 // Clear the list of canned local storages.
81 void Reset();
83 // True if no local storages are currently stored.
84 bool empty() const;
86 // Returns the number of local storages currently stored.
87 size_t GetLocalStorageCount() const;
89 // Returns the set of origins that use local storage.
90 const std::set<GURL>& GetLocalStorageInfo() const;
92 // BrowsingDataLocalStorageHelper implementation.
93 void StartFetching(const FetchCallback& callback) override;
94 void DeleteOrigin(const GURL& origin) override;
96 private:
97 ~CannedBrowsingDataLocalStorageHelper() override;
99 std::set<GURL> pending_local_storage_info_;
101 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataLocalStorageHelper);
104 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_LOCAL_STORAGE_HELPER_H_