Commit f7505cba authored by mkwst@chromium.org's avatar mkwst@chromium.org

Stylistic fixes for BrowsingDataFileSystemHelper.

The only functional change is to drop the `profile_` property from the
CannedBrowsingDataFileSystemHelper, which just stored it without ever
touching it.  I don't like keeping pointers around if I don't need them, so
I'm dropping it here.

BUG=None
TEST=Read the code. Can you understand it?


Review URL: http://codereview.chromium.org/7104026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88647 0039d316-1c4b-4281-b951-d872f2087c98
parent 6c0c9d3f
...@@ -11,24 +11,20 @@ ...@@ -11,24 +11,20 @@
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "content/browser/browser_thread.h" #include "content/browser/browser_thread.h"
#include "content/browser/in_process_webkit/webkit_context.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "webkit/fileapi/file_system_quota_util.h" #include "webkit/fileapi/file_system_quota_util.h"
#include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_types.h" #include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h" #include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/glue/webkit_glue.h"
using WebKit::WebSecurityOrigin;
namespace { namespace {
// An implementation of the BrowsingDataFileSystemHelper interface that pulls
// data from a given |profile| and returns a list of FileSystemInfo items to a
// client.
class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper { class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper {
public: public:
// BrowsingDataFileSystemHelper implementation
explicit BrowsingDataFileSystemHelperImpl(Profile* profile); explicit BrowsingDataFileSystemHelperImpl(Profile* profile);
virtual void StartFetching( virtual void StartFetching(
Callback1<const std::vector<FileSystemInfo>& >::Type* callback); Callback1<const std::vector<FileSystemInfo>& >::Type* callback);
virtual void CancelNotification(); virtual void CancelNotification();
...@@ -37,26 +33,36 @@ class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper { ...@@ -37,26 +33,36 @@ class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper {
private: private:
virtual ~BrowsingDataFileSystemHelperImpl(); virtual ~BrowsingDataFileSystemHelperImpl();
// Enumerates all filesystem files in the FILE thread. // Enumerates all filesystem files, storing the resulting list into
// file_system_file_ for later use. This must be called on the FILE thread.
void FetchFileSystemInfoInFileThread(); void FetchFileSystemInfoInFileThread();
// Notifies the completion callback in the UI thread.
void NotifyInUIThread(); // Triggers the success callback as the end of a StartFetching workflow. This
// Delete data for an origin on the FILE thread. // must be called on the UI thread.
void NotifyOnUIThread();
// Deletes all file systems associated with |origin|. This must be called on
// the FILE thread.
void DeleteFileSystemOriginInFileThread(const GURL& origin); void DeleteFileSystemOriginInFileThread(const GURL& origin);
// We don't own the Profile object. Clients are responsible for destroying the
// object when it's no longer used.
Profile* profile_; Profile* profile_;
// This only mutates in the FILE thread. // Holds the current list of file systems returned to the client after
// StartFetching is called. This only mutates in the FILE thread.
std::vector<FileSystemInfo> file_system_info_; std::vector<FileSystemInfo> file_system_info_;
// This only mutates on the UI thread. // Holds the callback passed in at the beginning of the StartFetching workflow
// so that it can be triggered via NotifyOnUIThread. This only mutates on the
// UI thread.
scoped_ptr<Callback1<const std::vector<FileSystemInfo>& >::Type > scoped_ptr<Callback1<const std::vector<FileSystemInfo>& >::Type >
completion_callback_; completion_callback_;
// Indicates whether or not we're currently fetching information: // Indicates whether or not we're currently fetching information: set to true
// it's true when StartFetching() is called in the UI thread, and it's reset // when StartFetching is called on the UI thread, and reset to false when
// after we notified the callback in the UI thread. // NotifyOnUIThread triggers the success callback.
// This only mutates on the UI thread. // This property only mutates on the UI thread.
bool is_fetching_; bool is_fetching_;
DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperImpl); DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperImpl);
...@@ -109,7 +115,9 @@ void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() { ...@@ -109,7 +115,9 @@ void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() {
scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator> scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator>
origin_enumerator(profile_->GetFileSystemContext()->path_manager()-> origin_enumerator(profile_->GetFileSystemContext()->path_manager()->
sandbox_provider()->CreateOriginEnumerator()); sandbox_provider()->CreateOriginEnumerator());
// We don't own this pointer; deleting it would be a bad idea.
// We don't own this pointer; it's a magic singleton generated by the
// profile's FileSystemContext. Deleting it would be a bad idea.
fileapi::FileSystemQuotaUtil* quota_util = profile_-> fileapi::FileSystemQuotaUtil* quota_util = profile_->
GetFileSystemContext()->GetQuotaUtil(fileapi::kFileSystemTypeTemporary); GetFileSystemContext()->GetQuotaUtil(fileapi::kFileSystemTypeTemporary);
...@@ -119,6 +127,8 @@ void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() { ...@@ -119,6 +127,8 @@ void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() {
// Extension state is not considered browsing data. // Extension state is not considered browsing data.
continue; continue;
} }
// We can call these synchronous methods as we've already verified that
// we're running on the FILE thread.
int64 persistent_usage = quota_util->GetOriginUsageOnFileThread(current, int64 persistent_usage = quota_util->GetOriginUsageOnFileThread(current,
fileapi::kFileSystemTypePersistent); fileapi::kFileSystemTypePersistent);
int64 temporary_usage = quota_util->GetOriginUsageOnFileThread(current, int64 temporary_usage = quota_util->GetOriginUsageOnFileThread(current,
...@@ -137,14 +147,14 @@ void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() { ...@@ -137,14 +147,14 @@ void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
NewRunnableMethod( NewRunnableMethod(
this, &BrowsingDataFileSystemHelperImpl::NotifyInUIThread)); this, &BrowsingDataFileSystemHelperImpl::NotifyOnUIThread));
} }
void BrowsingDataFileSystemHelperImpl::NotifyInUIThread() { void BrowsingDataFileSystemHelperImpl::NotifyOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(is_fetching_); DCHECK(is_fetching_);
// Note: completion_callback_ mutates only in the UI thread, so it's safe to // completion_callback_ mutates only in the UI thread, so we're safe to test
// test it here. // it here.
if (completion_callback_ != NULL) { if (completion_callback_ != NULL) {
completion_callback_->Run(file_system_info_); completion_callback_->Run(file_system_info_);
completion_callback_.reset(); completion_callback_.reset();
...@@ -182,27 +192,30 @@ BrowsingDataFileSystemHelper* BrowsingDataFileSystemHelper::Create( ...@@ -182,27 +192,30 @@ BrowsingDataFileSystemHelper* BrowsingDataFileSystemHelper::Create(
} }
CannedBrowsingDataFileSystemHelper:: CannedBrowsingDataFileSystemHelper::
PendingFileSystemInfo::PendingFileSystemInfo() { PendingFileSystemInfo::PendingFileSystemInfo() {
} }
CannedBrowsingDataFileSystemHelper:: CannedBrowsingDataFileSystemHelper::
PendingFileSystemInfo::PendingFileSystemInfo(const GURL& origin, PendingFileSystemInfo::PendingFileSystemInfo(
const fileapi::FileSystemType type, const GURL& origin,
int64 size) const fileapi::FileSystemType type,
int64 size)
: origin(origin), : origin(origin),
type(type), type(type),
size(size) { size(size) {
} }
CannedBrowsingDataFileSystemHelper:: CannedBrowsingDataFileSystemHelper::
PendingFileSystemInfo::~PendingFileSystemInfo() { PendingFileSystemInfo::~PendingFileSystemInfo() {
} }
CannedBrowsingDataFileSystemHelper::CannedBrowsingDataFileSystemHelper( CannedBrowsingDataFileSystemHelper::CannedBrowsingDataFileSystemHelper(
Profile* profile) Profile* /* profile */)
: profile_(profile), : is_fetching_(false) {
is_fetching_(false) { }
DCHECK(profile);
CannedBrowsingDataFileSystemHelper::CannedBrowsingDataFileSystemHelper()
: is_fetching_(false) {
} }
CannedBrowsingDataFileSystemHelper::~CannedBrowsingDataFileSystemHelper() {} CannedBrowsingDataFileSystemHelper::~CannedBrowsingDataFileSystemHelper() {}
...@@ -211,8 +224,7 @@ CannedBrowsingDataFileSystemHelper* ...@@ -211,8 +224,7 @@ CannedBrowsingDataFileSystemHelper*
CannedBrowsingDataFileSystemHelper::Clone() { CannedBrowsingDataFileSystemHelper::Clone() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
CannedBrowsingDataFileSystemHelper* clone = CannedBrowsingDataFileSystemHelper* clone =
new CannedBrowsingDataFileSystemHelper(profile_); new CannedBrowsingDataFileSystemHelper();
clone->pending_file_system_info_ = pending_file_system_info_; clone->pending_file_system_info_ = pending_file_system_info_;
clone->file_system_info_ = file_system_info_; clone->file_system_info_ = file_system_info_;
return clone; return clone;
...@@ -242,8 +254,9 @@ void CannedBrowsingDataFileSystemHelper::StartFetching( ...@@ -242,8 +254,9 @@ void CannedBrowsingDataFileSystemHelper::StartFetching(
completion_callback_.reset(callback); completion_callback_.reset(callback);
for (std::vector<PendingFileSystemInfo>::const_iterator for (std::vector<PendingFileSystemInfo>::const_iterator
info = pending_file_system_info_.begin(); info = pending_file_system_info_.begin();
info != pending_file_system_info_.end(); ++info) { info != pending_file_system_info_.end();
++info) {
bool duplicate = false; bool duplicate = false;
for (std::vector<FileSystemInfo>::iterator for (std::vector<FileSystemInfo>::iterator
file_system = file_system_info_.begin(); file_system = file_system_info_.begin();
...@@ -273,16 +286,13 @@ void CannedBrowsingDataFileSystemHelper::StartFetching( ...@@ -273,16 +286,13 @@ void CannedBrowsingDataFileSystemHelper::StartFetching(
} }
pending_file_system_info_.clear(); pending_file_system_info_.clear();
// MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
// &CannedBrowsingDataFileSystemHelper::Notify));
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
NewRunnableMethod( NewRunnableMethod(
this, &CannedBrowsingDataFileSystemHelper::Notify)); this, &CannedBrowsingDataFileSystemHelper::NotifyOnUIThread));
} }
void CannedBrowsingDataFileSystemHelper::Notify() { void CannedBrowsingDataFileSystemHelper::NotifyOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(is_fetching_); DCHECK(is_fetching_);
if (completion_callback_ != NULL) { if (completion_callback_ != NULL) {
......
...@@ -21,16 +21,18 @@ ...@@ -21,16 +21,18 @@
class Profile; class Profile;
// BrowsingDataFileSystemHelper is an interface for classes dealing with // Defines an interface for classes that deal with aggregating and deleting
// aggregating and deleting browsing data stored in local filesystems. A // browsing data stored in an origin's file systems. Clients of this interface
// client of this class needs to call StartFetching from the UI thread to // must call StartFetching from the UI thread to initiate the flow, and will
// initiate the flow, and it'll be notified by the callback in its UI thread at // be notified via a callback at some later point (also in the UI thread). If
// some later point. The client must call CancelNotification() if it's // the client is destroyed before the callback is triggered, it must call
// destroyed before the callback is notified. // CancelNotification.
class BrowsingDataFileSystemHelper class BrowsingDataFileSystemHelper
: public base::RefCountedThreadSafe<BrowsingDataFileSystemHelper> { : public base::RefCountedThreadSafe<BrowsingDataFileSystemHelper> {
public: public:
// Contains detailed information about a filesystem // Detailed information about a file system, including it's origin GURL,
// the presence or absence of persistent and temporary storage, and the
// amount of data (in bytes) each contains.
struct FileSystemInfo { struct FileSystemInfo {
FileSystemInfo( FileSystemInfo(
const GURL& origin, const GURL& origin,
...@@ -40,10 +42,6 @@ class BrowsingDataFileSystemHelper ...@@ -40,10 +42,6 @@ class BrowsingDataFileSystemHelper
int64 usage_temporary); int64 usage_temporary);
~FileSystemInfo(); ~FileSystemInfo();
bool IsFileSchemeData() {
return origin.scheme() == chrome::kFileScheme;
}
GURL origin; GURL origin;
bool has_persistent; bool has_persistent;
bool has_temporary; bool has_temporary;
...@@ -51,20 +49,23 @@ class BrowsingDataFileSystemHelper ...@@ -51,20 +49,23 @@ class BrowsingDataFileSystemHelper
int64 usage_temporary; int64 usage_temporary;
}; };
// Create a BrowsingDataFileSystemHelper instance for the filesystems // Create a BrowsingDataFileSystemHelper instance for the file systems
// stored in |profile|'s user data directory. // stored in |profile|'s user data directory.
static BrowsingDataFileSystemHelper* Create(Profile* profile); static BrowsingDataFileSystemHelper* Create(Profile* profile);
// Starts the fetching process, which will notify its completion via // Starts the process of fetching file system data, which will call |callback|
// callback. // upon completion, passing it a constant vector of FileSystemInfo objects.
// This must be called only in the UI thread. // This must be called only in the UI thread.
virtual void StartFetching( virtual void StartFetching(
Callback1<const std::vector<FileSystemInfo>& >::Type* callback) = 0; Callback1<const std::vector<FileSystemInfo>& >::Type* callback) = 0;
// Cancels the notification callback (i.e., the window that created it no
// longer exists). // Cancels the notification callback associated with StartFetching. Clients
// This must be called only in the UI thread. // that are destroyed before the callback is triggered must call this, and
// it must be called only on the UI thread.
virtual void CancelNotification() = 0; virtual void CancelNotification() = 0;
// Requests a single filesystem to be deleted in the FILE thread.
// Deletes all file systems associated with |origin|. The deletion will occur
// on the FILE thread, but this function must be called only on the UI thread.
virtual void DeleteFileSystemOrigin(const GURL& origin) = 0; virtual void DeleteFileSystemOrigin(const GURL& origin) = 0;
protected: protected:
...@@ -72,26 +73,31 @@ class BrowsingDataFileSystemHelper ...@@ -72,26 +73,31 @@ class BrowsingDataFileSystemHelper
virtual ~BrowsingDataFileSystemHelper() {} virtual ~BrowsingDataFileSystemHelper() {}
}; };
// This class is an implementation of BrowsingDataFileSystemHelper that does // An implementation of the BrowsingDataFileSystemHelper interface that can
// not fetch its information from the filesystem tracker, but gets it passed // be manually populated with data, rather than fetching data from the file
// in as a parameter. // systems created in a particular Profile.
class CannedBrowsingDataFileSystemHelper class CannedBrowsingDataFileSystemHelper
: public BrowsingDataFileSystemHelper { : public BrowsingDataFileSystemHelper {
public: public:
// |profile| is unused in this canned implementation, but it's the interface
// we're writing to, so we'll accept it, but not store it.
explicit CannedBrowsingDataFileSystemHelper(Profile* profile); explicit CannedBrowsingDataFileSystemHelper(Profile* profile);
// Return a copy of the filesystem helper. Only one consumer can use the // Creates a copy of the file system helper. StartFetching can only respond
// StartFetching method at a time, so we need to create a copy of the helper // to one client at a time; we need to be able to act on multiple parallel
// everytime we instantiate a cookies tree model for it. // requests in certain situations (see CookiesTreeModel and its clients). For
// these cases, simply clone the object and fire off another fetching process.
CannedBrowsingDataFileSystemHelper* Clone(); CannedBrowsingDataFileSystemHelper* Clone();
// Add a filesystem to the set of canned filesystems that is // Manually add a filesystem to the set of canned file systems that this
// returned by this helper. // helper returns via StartFetching. If an origin contains both a temporary
// and a persistent filesystem, AddFileSystem must be called twice (once for
// each file system type).
void AddFileSystem(const GURL& origin, void AddFileSystem(const GURL& origin,
fileapi::FileSystemType type, fileapi::FileSystemType type,
int64 size); int64 size);
// Clear the list of canned filesystems. // Clear this helper's list of canned filesystems.
void Reset(); void Reset();
// True if no filesystems are currently stored. // True if no filesystems are currently stored.
...@@ -104,6 +110,14 @@ class CannedBrowsingDataFileSystemHelper ...@@ -104,6 +110,14 @@ class CannedBrowsingDataFileSystemHelper
virtual void DeleteFileSystemOrigin(const GURL& origin) {} virtual void DeleteFileSystemOrigin(const GURL& origin) {}
private: private:
// Used by Clone() to create an object without a Profile
CannedBrowsingDataFileSystemHelper();
virtual ~CannedBrowsingDataFileSystemHelper();
// AddFileSystem doesn't store file systems directly, but holds them until
// StartFetching is called. At that point, the pending file system data is
// merged with the current file system data before being returned to the
// client.
struct PendingFileSystemInfo { struct PendingFileSystemInfo {
PendingFileSystemInfo(); PendingFileSystemInfo();
PendingFileSystemInfo(const GURL& origin, PendingFileSystemInfo(const GURL& origin,
...@@ -116,25 +130,27 @@ class CannedBrowsingDataFileSystemHelper ...@@ -116,25 +130,27 @@ class CannedBrowsingDataFileSystemHelper
int64 size; int64 size;
}; };
// StartFetching's callback should be executed asynchronously, Notify handles // Triggers the success callback as the end of a StartFetching workflow. This
// that nicely. // must be called on the UI thread.
void Notify(); void NotifyOnUIThread();
virtual ~CannedBrowsingDataFileSystemHelper();
Profile* profile_;
// Holds file systems that have been added to the helper until StartFetching
// is called.
std::vector<PendingFileSystemInfo> pending_file_system_info_; std::vector<PendingFileSystemInfo> pending_file_system_info_;
// Holds the current list of file systems returned to the client after
// StartFetching is called.
std::vector<FileSystemInfo> file_system_info_; std::vector<FileSystemInfo> file_system_info_;
// Holds the callback passed in at the beginning of the StartFetching workflow
// so that it can be triggered via NotifyOnUIThread.
scoped_ptr<Callback1<const std::vector<FileSystemInfo>& >::Type > scoped_ptr<Callback1<const std::vector<FileSystemInfo>& >::Type >
completion_callback_; completion_callback_;
// Indicates whether or not we're currently fetching information: // Indicates whether or not we're currently fetching information: set to true
// it's true when StartFetching() is called in the UI thread, and it's reset // when StartFetching is called on the UI thread, and reset to false when
// after we notified the callback in the UI thread. // NotifyOnUIThread triggers the success callback.
// This only mutates on the UI thread. // This property only mutates on the UI thread.
bool is_fetching_; bool is_fetching_;
DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataFileSystemHelper); DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataFileSystemHelper);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment