This source file includes following definitions.
- file_task_runner
- is_fetching_
- StartFetching
- DeleteFileSystemOrigin
- FetchFileSystemInfoInFileThread
- NotifyOnUIThread
- DeleteFileSystemOriginInFileThread
- Create
- Clone
- AddFileSystem
- Reset
- empty
- GetFileSystemCount
- StartFetching
#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "content/public/browser/browser_thread.h"
#include "webkit/browser/fileapi/file_system_context.h"
#include "webkit/browser/fileapi/file_system_quota_util.h"
#include "webkit/common/fileapi/file_system_types.h"
using content::BrowserThread;
namespace fileapi {
class FileSystemContext;
}
namespace {
class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper {
public:
explicit BrowsingDataFileSystemHelperImpl(
fileapi::FileSystemContext* filesystem_context);
virtual void StartFetching(const base::Callback<
void(const std::list<FileSystemInfo>&)>& callback) OVERRIDE;
virtual void DeleteFileSystemOrigin(const GURL& origin) OVERRIDE;
private:
virtual ~BrowsingDataFileSystemHelperImpl();
void FetchFileSystemInfoInFileThread();
void NotifyOnUIThread();
void DeleteFileSystemOriginInFileThread(const GURL& origin);
base::SequencedTaskRunner* file_task_runner() {
return filesystem_context_->default_file_task_runner();
}
scoped_refptr<fileapi::FileSystemContext> filesystem_context_;
std::list<FileSystemInfo> file_system_info_;
base::Callback<void(const std::list<FileSystemInfo>&)> completion_callback_;
bool is_fetching_;
DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperImpl);
};
BrowsingDataFileSystemHelperImpl::BrowsingDataFileSystemHelperImpl(
fileapi::FileSystemContext* filesystem_context)
: filesystem_context_(filesystem_context),
is_fetching_(false) {
DCHECK(filesystem_context_.get());
}
BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() {
}
void BrowsingDataFileSystemHelperImpl::StartFetching(
const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!is_fetching_);
DCHECK_EQ(false, callback.is_null());
is_fetching_ = true;
completion_callback_ = callback;
file_task_runner()->PostTask(
FROM_HERE,
base::Bind(
&BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread,
this));
}
void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOrigin(
const GURL& origin) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
file_task_runner()->PostTask(
FROM_HERE,
base::Bind(
&BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread,
this, origin));
}
void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() {
DCHECK(file_task_runner()->RunsTasksOnCurrentThread());
const fileapi::FileSystemType types[] = {
fileapi::kFileSystemTypeTemporary,
fileapi::kFileSystemTypePersistent,
fileapi::kFileSystemTypeSyncable,
};
typedef std::map<GURL, FileSystemInfo> OriginInfoMap;
OriginInfoMap file_system_info_map;
for (size_t i = 0; i < arraysize(types); ++i) {
fileapi::FileSystemType type = types[i];
fileapi::FileSystemQuotaUtil* quota_util =
filesystem_context_->GetQuotaUtil(type);
DCHECK(quota_util);
std::set<GURL> origins;
quota_util->GetOriginsForTypeOnFileTaskRunner(type, &origins);
for (std::set<GURL>::iterator iter = origins.begin();
iter != origins.end(); ++iter) {
const GURL& current = *iter;
if (!BrowsingDataHelper::HasWebScheme(current))
continue;
int64 usage = quota_util->GetOriginUsageOnFileTaskRunner(
filesystem_context_.get(), current, type);
OriginInfoMap::iterator inserted =
file_system_info_map.insert(
std::make_pair(current, FileSystemInfo(current))).first;
inserted->second.usage_map[type] = usage;
}
}
for (OriginInfoMap::iterator iter = file_system_info_map.begin();
iter != file_system_info_map.end(); ++iter) {
file_system_info_.push_back(iter->second);
}
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&BrowsingDataFileSystemHelperImpl::NotifyOnUIThread, this));
}
void BrowsingDataFileSystemHelperImpl::NotifyOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(is_fetching_);
completion_callback_.Run(file_system_info_);
completion_callback_.Reset();
is_fetching_ = false;
}
void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread(
const GURL& origin) {
DCHECK(file_task_runner()->RunsTasksOnCurrentThread());
filesystem_context_->DeleteDataForOriginOnFileTaskRunner(origin);
}
}
BrowsingDataFileSystemHelper::FileSystemInfo::FileSystemInfo(
const GURL& origin) : origin(origin) {}
BrowsingDataFileSystemHelper::FileSystemInfo::~FileSystemInfo() {}
BrowsingDataFileSystemHelper* BrowsingDataFileSystemHelper::Create(
fileapi::FileSystemContext* filesystem_context) {
return new BrowsingDataFileSystemHelperImpl(filesystem_context);
}
CannedBrowsingDataFileSystemHelper::CannedBrowsingDataFileSystemHelper(
Profile* profile) {
}
CannedBrowsingDataFileSystemHelper::CannedBrowsingDataFileSystemHelper() {
}
CannedBrowsingDataFileSystemHelper::~CannedBrowsingDataFileSystemHelper() {}
CannedBrowsingDataFileSystemHelper*
CannedBrowsingDataFileSystemHelper::Clone() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
CannedBrowsingDataFileSystemHelper* clone =
new CannedBrowsingDataFileSystemHelper();
clone->file_system_info_ = file_system_info_;
return clone;
}
void CannedBrowsingDataFileSystemHelper::AddFileSystem(
const GURL& origin, const fileapi::FileSystemType type, const int64 size) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
bool duplicate_origin = false;
for (std::list<FileSystemInfo>::iterator
file_system = file_system_info_.begin();
file_system != file_system_info_.end();
++file_system) {
if (file_system->origin == origin) {
file_system->usage_map[type] = size;
duplicate_origin = true;
break;
}
}
if (duplicate_origin)
return;
if (!BrowsingDataHelper::HasWebScheme(origin))
return;
FileSystemInfo info(origin);
info.usage_map[type] = size;
file_system_info_.push_back(info);
}
void CannedBrowsingDataFileSystemHelper::Reset() {
file_system_info_.clear();
}
bool CannedBrowsingDataFileSystemHelper::empty() const {
return file_system_info_.empty();
}
size_t CannedBrowsingDataFileSystemHelper::GetFileSystemCount() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
return file_system_info_.size();
}
void CannedBrowsingDataFileSystemHelper::StartFetching(
const base::Callback<void(const std::list<FileSystemInfo>&)>& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, base::Bind(callback, file_system_info_));
}