summaryrefslogtreecommitdiffstats
path: root/chrome/browser/storage/storage_info_fetcher.h
blob: 2269beabd6866bc14d928fc98b4a3a5e483f61e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_STORAGE_STORAGE_INFO_FETCHER_H_
#define CHROME_BROWSER_STORAGE_STORAGE_INFO_FETCHER_H_

#include "base/memory/ref_counted.h"
#include "storage/browser/quota/quota_manager.h"

class Profile;

// Asynchronously fetches the amount of storage used by websites.
class StorageInfoFetcher :
    public base::RefCountedThreadSafe<StorageInfoFetcher> {
 public:
  using FetchCallback =
      base::Callback<void(const storage::UsageInfoEntries&)>;
  using ClearCallback =
      base::Callback<void(storage::QuotaStatusCode code)>;

  explicit StorageInfoFetcher(Profile* profile);

  // Asynchronously fetches the StorageInfo.
  void FetchStorageInfo(const FetchCallback& fetch_callback);

  // Asynchronously clears storage for the given host.
  void ClearStorage(
      const std::string& host,
      storage::StorageType type,
      const ClearCallback& clear_callback);

 private:
  virtual ~StorageInfoFetcher();

  friend class base::RefCountedThreadSafe<StorageInfoFetcher>;

  // Fetches the usage information.
  void GetUsageInfo(const storage::GetUsageInfoCallback& callback);

  // Called when usage information is available.
  void OnGetUsageInfoInternal(const storage::UsageInfoEntries& entries);

  // Reports back to all observers that information is available.
  void OnFetchCompleted();

  // Called when usage has been cleared.
  void OnUsageClearedInternal(storage::QuotaStatusCode code);

  // Reports back to all observers that storage has been deleted.
  void OnClearCompleted(storage::QuotaStatusCode code);

  // The quota manager to use to calculate the storage usage.
  storage::QuotaManager* quota_manager_;

  // Hosts and their usage.
  storage::UsageInfoEntries entries_;

  // The storage type to delete.
  storage::StorageType type_to_delete_;

  // The callback to use when fetching is complete.
  FetchCallback fetch_callback_;

  // The callback to use when storage has been cleared.
  ClearCallback clear_callback_;

  DISALLOW_COPY_AND_ASSIGN(StorageInfoFetcher);
};

#endif  // CHROME_BROWSER_STORAGE_STORAGE_INFO_FETCHER_H_