Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_file_system_helper.h
blobddf49178b068262e36ec7b7db382505de20cbd29
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_FILE_SYSTEM_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_FILE_SYSTEM_HELPER_H_
8 #include <list>
9 #include <map>
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "storage/common/fileapi/file_system_types.h"
14 #include "url/gurl.h"
16 namespace storage {
17 class FileSystemContext;
20 class Profile;
22 // Defines an interface for classes that deal with aggregating and deleting
23 // browsing data stored in an origin's file systems.
24 // BrowsingDataFileSystemHelper instances for a specific profile should be
25 // created via the static Create method. Each instance will lazily fetch file
26 // system data when a client calls StartFetching from the UI thread, and will
27 // notify the client via a supplied callback when the data is available.
29 // The client's callback is passed a list of FileSystemInfo objects containing
30 // usage information for each origin's temporary and persistent file systems.
32 // Clients may remove an origin's file systems at any time (even before fetching
33 // data) by calling DeleteFileSystemOrigin() on the UI thread. Calling
34 // DeleteFileSystemOrigin() for an origin that doesn't have any is safe; it's
35 // just an expensive NOOP.
36 class BrowsingDataFileSystemHelper
37 : public base::RefCountedThreadSafe<BrowsingDataFileSystemHelper> {
38 public:
39 // Detailed information about a file system, including it's origin GURL,
40 // the amount of data (in bytes) for each sandboxed filesystem type.
41 struct FileSystemInfo {
42 explicit FileSystemInfo(const GURL& origin);
43 ~FileSystemInfo();
45 // The origin for which the information is relevant.
46 GURL origin;
47 // FileSystemType to usage (in bytes) map.
48 std::map<storage::FileSystemType, int64> usage_map;
51 using FetchCallback = base::Callback<void(const std::list<FileSystemInfo>&)>;
53 // Creates a BrowsingDataFileSystemHelper instance for the file systems
54 // stored in |profile|'s user data directory. The BrowsingDataFileSystemHelper
55 // object will hold a reference to the Profile that's passed in, but is not
56 // responsible for destroying it.
58 // The BrowsingDataFileSystemHelper will not change the profile itself, but
59 // can modify data it contains (by removing file systems).
60 static BrowsingDataFileSystemHelper* Create(
61 storage::FileSystemContext* file_system_context);
63 // Starts the process of fetching file system data, which will call |callback|
64 // upon completion, passing it a constant list of FileSystemInfo objects.
65 // StartFetching must be called only in the UI thread; the provided Callback1
66 // will likewise be executed asynchronously on the UI thread.
68 // BrowsingDataFileSystemHelper takes ownership of the Callback1, and is
69 // responsible for deleting it once it's no longer needed.
70 virtual void StartFetching(const FetchCallback& callback) = 0;
72 // Deletes any temporary or persistent file systems associated with |origin|
73 // from the disk. Deletion will occur asynchronously on the FILE thread, but
74 // this function must be called only on the UI thread.
75 virtual void DeleteFileSystemOrigin(const GURL& origin) = 0;
77 protected:
78 friend class base::RefCountedThreadSafe<BrowsingDataFileSystemHelper>;
80 BrowsingDataFileSystemHelper() {}
81 virtual ~BrowsingDataFileSystemHelper() {}
84 // An implementation of the BrowsingDataFileSystemHelper interface that can
85 // be manually populated with data, rather than fetching data from the file
86 // systems created in a particular Profile.
87 class CannedBrowsingDataFileSystemHelper
88 : public BrowsingDataFileSystemHelper {
89 public:
90 // |profile| is unused in this canned implementation, but it's the interface
91 // we're writing to, so we'll accept it, but not store it.
92 explicit CannedBrowsingDataFileSystemHelper(Profile* profile);
94 // Manually adds a filesystem to the set of canned file systems that this
95 // helper returns via StartFetching. If an origin contains both a temporary
96 // and a persistent filesystem, AddFileSystem must be called twice (once for
97 // each file system type).
98 void AddFileSystem(const GURL& origin,
99 storage::FileSystemType type,
100 int64 size);
102 // Clear this helper's list of canned filesystems.
103 void Reset();
105 // True if no filesystems are currently stored.
106 bool empty() const;
108 // Returns the number of currently stored filesystems.
109 size_t GetFileSystemCount() const;
111 // Returns the current list of filesystems.
112 const std::list<FileSystemInfo>& GetFileSystemInfo() {
113 return file_system_info_;
116 // BrowsingDataFileSystemHelper implementation.
117 void StartFetching(const FetchCallback& callback) override;
119 // Note that this doesn't actually have an implementation for this canned
120 // class. It hasn't been necessary for anything that uses the canned
121 // implementation, as the canned class is only used in tests, or in read-only
122 // contexts (like the non-modal cookie dialog).
123 void DeleteFileSystemOrigin(const GURL& origin) override {}
125 private:
126 ~CannedBrowsingDataFileSystemHelper() override;
128 // Holds the current list of filesystems returned to the client.
129 std::list<FileSystemInfo> file_system_info_;
131 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataFileSystemHelper);
134 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_FILE_SYSTEM_HELPER_H_