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

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

Issue 7676002: When deleting storage through the cookies tree model, also update its cache (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 9 years, 4 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/browsing_data_file_system_helper.h" 5 #include "chrome/browser/browsing_data_file_system_helper.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "content/browser/browser_thread.h" 13 #include "content/browser/browser_thread.h"
14 #include "webkit/fileapi/file_system_quota_util.h" 14 #include "webkit/fileapi/file_system_quota_util.h"
15 #include "webkit/fileapi/file_system_context.h" 15 #include "webkit/fileapi/file_system_context.h"
16 #include "webkit/fileapi/file_system_types.h" 16 #include "webkit/fileapi/file_system_types.h"
17 #include "webkit/fileapi/sandbox_mount_point_provider.h" 17 #include "webkit/fileapi/sandbox_mount_point_provider.h"
18 18
19 namespace { 19 namespace {
20 20
21 // An implementation of the BrowsingDataFileSystemHelper interface that pulls 21 // An implementation of the BrowsingDataFileSystemHelper interface that pulls
22 // data from a given |profile| and returns a list of FileSystemInfo items to a 22 // data from a given |profile| and returns a list of FileSystemInfo items to a
23 // client. 23 // client.
24 class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper { 24 class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper {
25 public: 25 public:
26 // BrowsingDataFileSystemHelper implementation 26 // BrowsingDataFileSystemHelper implementation
27 explicit BrowsingDataFileSystemHelperImpl(Profile* profile); 27 explicit BrowsingDataFileSystemHelperImpl(Profile* profile);
28 virtual void StartFetching( 28 virtual void StartFetching(
29 Callback1<const std::vector<FileSystemInfo>& >::Type* callback); 29 Callback1<const std::list<FileSystemInfo>& >::Type* callback);
30 virtual void CancelNotification(); 30 virtual void CancelNotification();
31 virtual void DeleteFileSystemOrigin(const GURL& origin); 31 virtual void DeleteFileSystemOrigin(const GURL& origin);
32 32
33 private: 33 private:
34 virtual ~BrowsingDataFileSystemHelperImpl(); 34 virtual ~BrowsingDataFileSystemHelperImpl();
35 35
36 // Enumerates all filesystem files, storing the resulting list into 36 // Enumerates all filesystem files, storing the resulting list into
37 // file_system_file_ for later use. This must be called on the FILE thread. 37 // file_system_file_ for later use. This must be called on the FILE thread.
38 void FetchFileSystemInfoInFileThread(); 38 void FetchFileSystemInfoInFileThread();
39 39
40 // Triggers the success callback as the end of a StartFetching workflow. This 40 // Triggers the success callback as the end of a StartFetching workflow. This
41 // must be called on the UI thread. 41 // must be called on the UI thread.
42 void NotifyOnUIThread(); 42 void NotifyOnUIThread();
43 43
44 // Deletes all file systems associated with |origin|. This must be called on 44 // Deletes all file systems associated with |origin|. This must be called on
45 // the FILE thread. 45 // the FILE thread.
46 void DeleteFileSystemOriginInFileThread(const GURL& origin); 46 void DeleteFileSystemOriginInFileThread(const GURL& origin);
47 47
48 // We don't own the Profile object. Clients are responsible for destroying the 48 // We don't own the Profile object. Clients are responsible for destroying the
49 // object when it's no longer used. 49 // object when it's no longer used.
50 Profile* profile_; 50 Profile* profile_;
51 51
52 // Holds the current list of file systems returned to the client after 52 // Holds the current list of file systems returned to the client after
53 // StartFetching is called. This only mutates in the FILE thread. 53 // StartFetching is called. This only mutates in the FILE thread.
54 std::vector<FileSystemInfo> file_system_info_; 54 std::list<FileSystemInfo> file_system_info_;
55 55
56 // Holds the callback passed in at the beginning of the StartFetching workflow 56 // Holds the callback passed in at the beginning of the StartFetching workflow
57 // so that it can be triggered via NotifyOnUIThread. This only mutates on the 57 // so that it can be triggered via NotifyOnUIThread. This only mutates on the
58 // UI thread. 58 // UI thread.
59 scoped_ptr<Callback1<const std::vector<FileSystemInfo>& >::Type > 59 scoped_ptr<Callback1<const std::list<FileSystemInfo>& >::Type >
60 completion_callback_; 60 completion_callback_;
61 61
62 // Indicates whether or not we're currently fetching information: set to true 62 // Indicates whether or not we're currently fetching information: set to true
63 // when StartFetching is called on the UI thread, and reset to false when 63 // when StartFetching is called on the UI thread, and reset to false when
64 // NotifyOnUIThread triggers the success callback. 64 // NotifyOnUIThread triggers the success callback.
65 // This property only mutates on the UI thread. 65 // This property only mutates on the UI thread.
66 bool is_fetching_; 66 bool is_fetching_;
67 67
68 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperImpl); 68 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperImpl);
69 }; 69 };
70 70
71 BrowsingDataFileSystemHelperImpl::BrowsingDataFileSystemHelperImpl( 71 BrowsingDataFileSystemHelperImpl::BrowsingDataFileSystemHelperImpl(
72 Profile* profile) 72 Profile* profile)
73 : profile_(profile), 73 : profile_(profile),
74 is_fetching_(false) { 74 is_fetching_(false) {
75 DCHECK(profile_); 75 DCHECK(profile_);
76 } 76 }
77 77
78 BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() { 78 BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() {
79 } 79 }
80 80
81 void BrowsingDataFileSystemHelperImpl::StartFetching( 81 void BrowsingDataFileSystemHelperImpl::StartFetching(
82 Callback1<const std::vector<FileSystemInfo>& >::Type* callback) { 82 Callback1<const std::list<FileSystemInfo>& >::Type* callback) {
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
84 DCHECK(!is_fetching_); 84 DCHECK(!is_fetching_);
85 DCHECK(callback); 85 DCHECK(callback);
86 is_fetching_ = true; 86 is_fetching_ = true;
87 completion_callback_.reset(callback); 87 completion_callback_.reset(callback);
88 BrowserThread::PostTask( 88 BrowserThread::PostTask(
89 BrowserThread::FILE, FROM_HERE, 89 BrowserThread::FILE, FROM_HERE,
90 NewRunnableMethod( 90 NewRunnableMethod(
91 this, 91 this,
92 &BrowsingDataFileSystemHelperImpl:: 92 &BrowsingDataFileSystemHelperImpl::
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 214 }
215 215
216 void CannedBrowsingDataFileSystemHelper::AddFileSystem( 216 void CannedBrowsingDataFileSystemHelper::AddFileSystem(
217 const GURL& origin, const fileapi::FileSystemType type, const int64 size) { 217 const GURL& origin, const fileapi::FileSystemType type, const int64 size) {
218 218
219 // This canned implementation of AddFileSystem uses an O(n^2) algorithm; which 219 // This canned implementation of AddFileSystem uses an O(n^2) algorithm; which
220 // is fine, as it isn't meant for use in a high-volume context. If it turns 220 // is fine, as it isn't meant for use in a high-volume context. If it turns
221 // out that we want to start using this in a context with many, many origins, 221 // out that we want to start using this in a context with many, many origins,
222 // we should think about reworking the implementation. 222 // we should think about reworking the implementation.
223 bool duplicate_origin = false; 223 bool duplicate_origin = false;
224 for (std::vector<FileSystemInfo>::iterator 224 for (std::list<FileSystemInfo>::iterator
225 file_system = file_system_info_.begin(); 225 file_system = file_system_info_.begin();
226 file_system != file_system_info_.end(); 226 file_system != file_system_info_.end();
227 ++file_system) { 227 ++file_system) {
228 if (file_system->origin == origin) { 228 if (file_system->origin == origin) {
229 if (type == fileapi::kFileSystemTypePersistent) { 229 if (type == fileapi::kFileSystemTypePersistent) {
230 file_system->has_persistent = true; 230 file_system->has_persistent = true;
231 file_system->usage_persistent = size; 231 file_system->usage_persistent = size;
232 } else { 232 } else {
233 file_system->has_temporary = true; 233 file_system->has_temporary = true;
234 file_system->usage_temporary = size; 234 file_system->usage_temporary = size;
(...skipping 15 matching lines...) Expand all
250 250
251 void CannedBrowsingDataFileSystemHelper::Reset() { 251 void CannedBrowsingDataFileSystemHelper::Reset() {
252 file_system_info_.clear(); 252 file_system_info_.clear();
253 } 253 }
254 254
255 bool CannedBrowsingDataFileSystemHelper::empty() const { 255 bool CannedBrowsingDataFileSystemHelper::empty() const {
256 return file_system_info_.empty(); 256 return file_system_info_.empty();
257 } 257 }
258 258
259 void CannedBrowsingDataFileSystemHelper::StartFetching( 259 void CannedBrowsingDataFileSystemHelper::StartFetching(
260 Callback1<const std::vector<FileSystemInfo>& >::Type* callback) { 260 Callback1<const std::list<FileSystemInfo>& >::Type* callback) {
261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
262 DCHECK(!is_fetching_); 262 DCHECK(!is_fetching_);
263 DCHECK(callback); 263 DCHECK(callback);
264 is_fetching_ = true; 264 is_fetching_ = true;
265 completion_callback_.reset(callback); 265 completion_callback_.reset(callback);
266 266
267 BrowserThread::PostTask( 267 BrowserThread::PostTask(
268 BrowserThread::UI, FROM_HERE, 268 BrowserThread::UI, FROM_HERE,
269 NewRunnableMethod( 269 NewRunnableMethod(
270 this, &CannedBrowsingDataFileSystemHelper::NotifyOnUIThread)); 270 this, &CannedBrowsingDataFileSystemHelper::NotifyOnUIThread));
271 } 271 }
272 272
273 void CannedBrowsingDataFileSystemHelper::NotifyOnUIThread() { 273 void CannedBrowsingDataFileSystemHelper::NotifyOnUIThread() {
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
275 DCHECK(is_fetching_); 275 DCHECK(is_fetching_);
276 if (completion_callback_ != NULL) { 276 if (completion_callback_ != NULL) {
277 completion_callback_->Run(file_system_info_); 277 completion_callback_->Run(file_system_info_);
278 completion_callback_.reset(); 278 completion_callback_.reset();
279 } 279 }
280 is_fetching_ = false; 280 is_fetching_ = false;
281 } 281 }
282 282
283 void CannedBrowsingDataFileSystemHelper::CancelNotification() { 283 void CannedBrowsingDataFileSystemHelper::CancelNotification() {
284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
285 completion_callback_.reset(); 285 completion_callback_.reset();
286 } 286 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_file_system_helper.h ('k') | chrome/browser/browsing_data_file_system_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698