Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/browser/browsing_data_file_system_helper.h

Issue 10805015: Move browsing_data_helper files into a separate directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix chrome_frame build Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_
7
8 #include <list>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/synchronization/lock.h"
16 #include "base/time.h"
17 #include "chrome/common/url_constants.h"
18 #include "googleurl/src/gurl.h"
19 #include "webkit/fileapi/file_system_types.h"
20
21 class Profile;
22
23 // Defines an interface for classes that deal with aggregating and deleting
24 // browsing data stored in an origin's file systems.
25 // BrowsingDataFileSystemHelper instances for a specific profile should be
26 // created via the static Create method. Each instance will lazily fetch file
27 // system data when a client calls StartFetching from the UI thread, and will
28 // notify the client via a supplied callback when the data is available.
29 // Only one StartFetching task can run at a time: executing StartFetching while
30 // another StartFetching task is running will DCHECK.
31 //
32 // The client's callback is passed a list of FileSystemInfo objects containing
33 // usage information for each origin's temporary and persistent file systems.
34 //
35 // Clients may remove an origin's file systems at any time (even before fetching
36 // data) by calling DeleteFileSystemOrigin() on the UI thread. Calling
37 // DeleteFileSystemOrigin() for an origin that doesn't have any is safe; it's
38 // just an expensive NOOP.
39 class BrowsingDataFileSystemHelper
40 : public base::RefCountedThreadSafe<BrowsingDataFileSystemHelper> {
41 public:
42 // Detailed information about a file system, including it's origin GURL,
43 // the presence or absence of persistent and temporary storage, and the
44 // amount of data (in bytes) each contains.
45 struct FileSystemInfo {
46 FileSystemInfo(
47 const GURL& origin,
48 bool has_persistent,
49 bool has_temporary,
50 int64 usage_persistent,
51 int64 usage_temporary);
52 ~FileSystemInfo();
53
54 // The origin for which the information is relevant.
55 GURL origin;
56 // True if the origin has a persistent file system.
57 bool has_persistent;
58 // True if the origin has a temporary file system.
59 bool has_temporary;
60 // Persistent file system usage, in bytes.
61 int64 usage_persistent;
62 // Temporary file system usage, in bytes.
63 int64 usage_temporary;
64 };
65
66 // Creates a BrowsingDataFileSystemHelper instance for the file systems
67 // stored in |profile|'s user data directory. The BrowsingDataFileSystemHelper
68 // object will hold a reference to the Profile that's passed in, but is not
69 // responsible for destroying it.
70 //
71 // The BrowsingDataFileSystemHelper will not change the profile itself, but
72 // can modify data it contains (by removing file systems).
73 static BrowsingDataFileSystemHelper* Create(Profile* profile);
74
75 // Starts the process of fetching file system data, which will call |callback|
76 // upon completion, passing it a constant list of FileSystemInfo objects.
77 // StartFetching must be called only in the UI thread; the provided Callback1
78 // will likewise be executed asynchronously on the UI thread.
79 //
80 // BrowsingDataFileSystemHelper takes ownership of the Callback1, and is
81 // responsible for deleting it once it's no longer needed.
82 virtual void StartFetching(const base::Callback<
83 void(const std::list<FileSystemInfo>&)>& callback) = 0;
84
85 // Deletes any temporary or persistent file systems associated with |origin|
86 // from the disk. Deletion will occur asynchronously on the FILE thread, but
87 // this function must be called only on the UI thread.
88 virtual void DeleteFileSystemOrigin(const GURL& origin) = 0;
89
90 protected:
91 friend class base::RefCountedThreadSafe<BrowsingDataFileSystemHelper>;
92
93 BrowsingDataFileSystemHelper() {}
94 virtual ~BrowsingDataFileSystemHelper() {}
95 };
96
97 // An implementation of the BrowsingDataFileSystemHelper interface that can
98 // be manually populated with data, rather than fetching data from the file
99 // systems created in a particular Profile.
100 class CannedBrowsingDataFileSystemHelper
101 : public BrowsingDataFileSystemHelper {
102 public:
103 // |profile| is unused in this canned implementation, but it's the interface
104 // we're writing to, so we'll accept it, but not store it.
105 explicit CannedBrowsingDataFileSystemHelper(Profile* profile);
106
107 // Creates a copy of the file system helper. StartFetching can only respond
108 // to one client at a time; we need to be able to act on multiple parallel
109 // requests in certain situations (see CookiesTreeModel and its clients). For
110 // these cases, simply clone the object and fire off another fetching process.
111 //
112 // Clone() is safe to call while StartFetching() is running. Clients of the
113 // newly created object must themselves execute StartFetching(), however: the
114 // copy will not have a pending fetch.
115 CannedBrowsingDataFileSystemHelper* Clone();
116
117 // Manually adds a filesystem to the set of canned file systems that this
118 // helper returns via StartFetching. If an origin contains both a temporary
119 // and a persistent filesystem, AddFileSystem must be called twice (once for
120 // each file system type).
121 void AddFileSystem(const GURL& origin,
122 fileapi::FileSystemType type,
123 int64 size);
124
125 // Clear this helper's list of canned filesystems.
126 void Reset();
127
128 // True if no filesystems are currently stored.
129 bool empty() const;
130
131 // Returns the number of currently stored filesystems.
132 size_t GetFileSystemCount() const;
133
134 // Returns the current list of filesystems.
135 const std::list<FileSystemInfo>& GetFileSystemInfo() {
136 return file_system_info_;
137 }
138
139 // BrowsingDataFileSystemHelper implementation.
140 virtual void StartFetching(const base::Callback<
141 void(const std::list<FileSystemInfo>&)>& callback) OVERRIDE;
142
143 // Note that this doesn't actually have an implementation for this canned
144 // class. It hasn't been necessary for anything that uses the canned
145 // implementation, as the canned class is only used in tests, or in read-only
146 // contexts (like the non-modal cookie dialog).
147 virtual void DeleteFileSystemOrigin(const GURL& origin) OVERRIDE {}
148
149 private:
150 // Used by Clone() to create an object without a Profile
151 CannedBrowsingDataFileSystemHelper();
152 virtual ~CannedBrowsingDataFileSystemHelper();
153
154 // Triggers the success callback as the end of a StartFetching workflow. This
155 // must be called on the UI thread.
156 void NotifyOnUIThread();
157
158 // Holds the current list of filesystems returned to the client. Access to
159 // |file_system_info_| is triggered indirectly via the UI thread and guarded
160 // by |is_fetching_|. This means |file_system_info_| is only accessed while
161 // |is_fetching_| is true. The flag |is_fetching_| is only accessed on the UI
162 // thread.
163 std::list<FileSystemInfo> file_system_info_;
164
165 // The callback passed in at the beginning of the StartFetching workflow so
166 // that it can be triggered via NotifyOnUIThread.
167 base::Callback<void(const std::list<FileSystemInfo>&)> completion_callback_;
168
169 // Indicates whether or not we're currently fetching information: set to true
170 // when StartFetching is called on the UI thread, and reset to false when
171 // NotifyOnUIThread triggers the success callback.
172 // This property only mutates on the UI thread.
173 bool is_fetching_;
174
175 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataFileSystemHelper);
176 };
177
178 #endif // CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_database_helper_unittest.cc ('k') | chrome/browser/browsing_data_file_system_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698