| OLD | NEW |
| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" |
| 8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "content/browser/browser_thread.h" | 15 #include "content/browser/browser_thread.h" |
| 15 #include "webkit/fileapi/file_system_quota_util.h" | 16 #include "webkit/fileapi/file_system_quota_util.h" |
| 16 #include "webkit/fileapi/file_system_context.h" | 17 #include "webkit/fileapi/file_system_context.h" |
| 17 #include "webkit/fileapi/file_system_types.h" | 18 #include "webkit/fileapi/file_system_types.h" |
| 18 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 19 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // An implementation of the BrowsingDataFileSystemHelper interface that pulls | 23 // An implementation of the BrowsingDataFileSystemHelper interface that pulls |
| 23 // data from a given |profile| and returns a list of FileSystemInfo items to a | 24 // data from a given |profile| and returns a list of FileSystemInfo items to a |
| 24 // client. | 25 // client. |
| 25 class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper { | 26 class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper { |
| 26 public: | 27 public: |
| 27 // BrowsingDataFileSystemHelper implementation | 28 // BrowsingDataFileSystemHelper implementation |
| 28 explicit BrowsingDataFileSystemHelperImpl(Profile* profile); | 29 explicit BrowsingDataFileSystemHelperImpl(Profile* profile); |
| 29 virtual void StartFetching( | 30 virtual void StartFetching(const base::Callback< |
| 30 Callback1<const std::list<FileSystemInfo>& >::Type* callback); | 31 void(const std::list<FileSystemInfo>&)>& callback) OVERRIDE; |
| 31 virtual void CancelNotification(); | 32 virtual void CancelNotification() OVERRIDE; |
| 32 virtual void DeleteFileSystemOrigin(const GURL& origin); | 33 virtual void DeleteFileSystemOrigin(const GURL& origin) OVERRIDE; |
| 33 | 34 |
| 34 private: | 35 private: |
| 35 virtual ~BrowsingDataFileSystemHelperImpl(); | 36 virtual ~BrowsingDataFileSystemHelperImpl(); |
| 36 | 37 |
| 37 // Enumerates all filesystem files, storing the resulting list into | 38 // Enumerates all filesystem files, storing the resulting list into |
| 38 // file_system_file_ for later use. This must be called on the FILE thread. | 39 // file_system_file_ for later use. This must be called on the FILE thread. |
| 39 void FetchFileSystemInfoInFileThread(); | 40 void FetchFileSystemInfoInFileThread(); |
| 40 | 41 |
| 41 // Triggers the success callback as the end of a StartFetching workflow. This | 42 // Triggers the success callback as the end of a StartFetching workflow. This |
| 42 // must be called on the UI thread. | 43 // must be called on the UI thread. |
| 43 void NotifyOnUIThread(); | 44 void NotifyOnUIThread(); |
| 44 | 45 |
| 45 // Deletes all file systems associated with |origin|. This must be called on | 46 // Deletes all file systems associated with |origin|. This must be called on |
| 46 // the FILE thread. | 47 // the FILE thread. |
| 47 void DeleteFileSystemOriginInFileThread(const GURL& origin); | 48 void DeleteFileSystemOriginInFileThread(const GURL& origin); |
| 48 | 49 |
| 49 // We don't own the Profile object. Clients are responsible for destroying the | 50 // We don't own the Profile object. Clients are responsible for destroying the |
| 50 // object when it's no longer used. | 51 // object when it's no longer used. |
| 51 Profile* profile_; | 52 Profile* profile_; |
| 52 | 53 |
| 53 // Holds the current list of file systems returned to the client after | 54 // Holds the current list of file systems returned to the client after |
| 54 // StartFetching is called. This only mutates in the FILE thread. | 55 // StartFetching is called. This only mutates in the FILE thread. |
| 55 std::list<FileSystemInfo> file_system_info_; | 56 std::list<FileSystemInfo> file_system_info_; |
| 56 | 57 |
| 57 // Holds the callback passed in at the beginning of the StartFetching workflow | 58 // Holds the callback passed in at the beginning of the StartFetching workflow |
| 58 // so that it can be triggered via NotifyOnUIThread. This only mutates on the | 59 // so that it can be triggered via NotifyOnUIThread. This only mutates on the |
| 59 // UI thread. | 60 // UI thread. |
| 60 scoped_ptr<Callback1<const std::list<FileSystemInfo>& >::Type > | 61 base::Callback<void(const std::list<FileSystemInfo>&)> completion_callback_; |
| 61 completion_callback_; | |
| 62 | 62 |
| 63 // Indicates whether or not we're currently fetching information: set to true | 63 // Indicates whether or not we're currently fetching information: set to true |
| 64 // when StartFetching is called on the UI thread, and reset to false when | 64 // when StartFetching is called on the UI thread, and reset to false when |
| 65 // NotifyOnUIThread triggers the success callback. | 65 // NotifyOnUIThread triggers the success callback. |
| 66 // This property only mutates on the UI thread. | 66 // This property only mutates on the UI thread. |
| 67 bool is_fetching_; | 67 bool is_fetching_; |
| 68 | 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperImpl); | 69 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperImpl); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 BrowsingDataFileSystemHelperImpl::BrowsingDataFileSystemHelperImpl( | 72 BrowsingDataFileSystemHelperImpl::BrowsingDataFileSystemHelperImpl( |
| 73 Profile* profile) | 73 Profile* profile) |
| 74 : profile_(profile), | 74 : profile_(profile), |
| 75 is_fetching_(false) { | 75 is_fetching_(false) { |
| 76 DCHECK(profile_); | 76 DCHECK(profile_); |
| 77 } | 77 } |
| 78 | 78 |
| 79 BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() { | 79 BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() { |
| 80 } | 80 } |
| 81 | 81 |
| 82 void BrowsingDataFileSystemHelperImpl::StartFetching( | 82 void BrowsingDataFileSystemHelperImpl::StartFetching( |
| 83 Callback1<const std::list<FileSystemInfo>& >::Type* callback) { | 83 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { |
| 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 85 DCHECK(!is_fetching_); | 85 DCHECK(!is_fetching_); |
| 86 DCHECK(callback); | 86 DCHECK_EQ(false, callback.is_null()); |
| 87 is_fetching_ = true; | 87 is_fetching_ = true; |
| 88 completion_callback_.reset(callback); | 88 completion_callback_ = callback; |
| 89 BrowserThread::PostTask( | 89 BrowserThread::PostTask( |
| 90 BrowserThread::FILE, FROM_HERE, | 90 BrowserThread::FILE, FROM_HERE, |
| 91 base::Bind( | 91 base::Bind( |
| 92 &BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread, | 92 &BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread, |
| 93 this)); | 93 this)); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void BrowsingDataFileSystemHelperImpl::CancelNotification() { | 96 void BrowsingDataFileSystemHelperImpl::CancelNotification() { |
| 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 98 completion_callback_.reset(); | 98 completion_callback_.Reset(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOrigin( | 101 void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOrigin( |
| 102 const GURL& origin) { | 102 const GURL& origin) { |
| 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 104 BrowserThread::PostTask( | 104 BrowserThread::PostTask( |
| 105 BrowserThread::FILE, FROM_HERE, | 105 BrowserThread::FILE, FROM_HERE, |
| 106 base::Bind( | 106 base::Bind( |
| 107 &BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread, | 107 &BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread, |
| 108 this, origin)); | 108 this, origin)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 BrowserThread::PostTask( | 145 BrowserThread::PostTask( |
| 146 BrowserThread::UI, FROM_HERE, | 146 BrowserThread::UI, FROM_HERE, |
| 147 base::Bind(&BrowsingDataFileSystemHelperImpl::NotifyOnUIThread, this)); | 147 base::Bind(&BrowsingDataFileSystemHelperImpl::NotifyOnUIThread, this)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void BrowsingDataFileSystemHelperImpl::NotifyOnUIThread() { | 150 void BrowsingDataFileSystemHelperImpl::NotifyOnUIThread() { |
| 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 152 DCHECK(is_fetching_); | 152 DCHECK(is_fetching_); |
| 153 // completion_callback_ mutates only in the UI thread, so we're safe to test | 153 // completion_callback_ mutates only in the UI thread, so we're safe to test |
| 154 // it here. | 154 // it here. |
| 155 if (completion_callback_ != NULL) { | 155 if (!completion_callback_.is_null()) { |
| 156 completion_callback_->Run(file_system_info_); | 156 completion_callback_.Run(file_system_info_); |
| 157 completion_callback_.reset(); | 157 completion_callback_.Reset(); |
| 158 } | 158 } |
| 159 is_fetching_ = false; | 159 is_fetching_ = false; |
| 160 } | 160 } |
| 161 | 161 |
| 162 void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread( | 162 void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread( |
| 163 const GURL& origin) { | 163 const GURL& origin) { |
| 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 165 profile_->GetFileSystemContext()->DeleteDataForOriginOnFileThread(origin); | 165 profile_->GetFileSystemContext()->DeleteDataForOriginOnFileThread(origin); |
| 166 } | 166 } |
| 167 | 167 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 247 |
| 248 void CannedBrowsingDataFileSystemHelper::Reset() { | 248 void CannedBrowsingDataFileSystemHelper::Reset() { |
| 249 file_system_info_.clear(); | 249 file_system_info_.clear(); |
| 250 } | 250 } |
| 251 | 251 |
| 252 bool CannedBrowsingDataFileSystemHelper::empty() const { | 252 bool CannedBrowsingDataFileSystemHelper::empty() const { |
| 253 return file_system_info_.empty(); | 253 return file_system_info_.empty(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void CannedBrowsingDataFileSystemHelper::StartFetching( | 256 void CannedBrowsingDataFileSystemHelper::StartFetching( |
| 257 Callback1<const std::list<FileSystemInfo>& >::Type* callback) { | 257 const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) { |
| 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 259 DCHECK(!is_fetching_); | 259 DCHECK(!is_fetching_); |
| 260 DCHECK(callback); | 260 DCHECK_EQ(false, callback.is_null()); |
| 261 is_fetching_ = true; | 261 is_fetching_ = true; |
| 262 completion_callback_.reset(callback); | 262 completion_callback_ = callback; |
| 263 | 263 |
| 264 BrowserThread::PostTask( | 264 BrowserThread::PostTask( |
| 265 BrowserThread::UI, FROM_HERE, | 265 BrowserThread::UI, FROM_HERE, |
| 266 base::Bind(&CannedBrowsingDataFileSystemHelper::NotifyOnUIThread, this)); | 266 base::Bind(&CannedBrowsingDataFileSystemHelper::NotifyOnUIThread, this)); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void CannedBrowsingDataFileSystemHelper::NotifyOnUIThread() { | 269 void CannedBrowsingDataFileSystemHelper::NotifyOnUIThread() { |
| 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 271 DCHECK(is_fetching_); | 271 DCHECK(is_fetching_); |
| 272 if (completion_callback_ != NULL) { | 272 if (!completion_callback_.is_null()) { |
| 273 completion_callback_->Run(file_system_info_); | 273 completion_callback_.Run(file_system_info_); |
| 274 completion_callback_.reset(); | 274 completion_callback_.Reset(); |
| 275 } | 275 } |
| 276 is_fetching_ = false; | 276 is_fetching_ = false; |
| 277 } | 277 } |
| 278 | 278 |
| 279 void CannedBrowsingDataFileSystemHelper::CancelNotification() { | 279 void CannedBrowsingDataFileSystemHelper::CancelNotification() { |
| 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 281 completion_callback_.reset(); | 281 completion_callback_.Reset(); |
| 282 } | 282 } |
| OLD | NEW |