summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-26 22:07:36 +0000
committermkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-26 22:07:36 +0000
commitde5480fa7532fe62b90db7f9b91b6644bfe9c865 (patch)
tree139bb51192ecb82ee2cc913d7355f0f8773039ef /chrome
parent40850a556804e6cd9c4256279296d2a0e8b69431 (diff)
downloadchromium_src-de5480fa7532fe62b90db7f9b91b6644bfe9c865.zip
chromium_src-de5480fa7532fe62b90db7f9b91b6644bfe9c865.tar.gz
chromium_src-de5480fa7532fe62b90db7f9b91b6644bfe9c865.tar.bz2
Adding `browsing_data_filesystem_helper*` as the first step towards content settings UI.
gypi files. BUG=63703 TEST=BrowsingDataFilesystemHelperTest* in `browser_tests` and `unit_tests` Review URL: http://codereview.chromium.org/7063020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86904 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/DEPS1
-rw-r--r--chrome/browser/browsing_data_file_system_helper.cc289
-rw-r--r--chrome/browser/browsing_data_file_system_helper.h143
-rw-r--r--chrome/browser/browsing_data_file_system_helper_browsertest.cc216
-rw-r--r--chrome/browser/browsing_data_file_system_helper_unittest.cc31
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/test/testing_profile.cc16
-rw-r--r--chrome/test/testing_profile.h3
9 files changed, 702 insertions, 1 deletions
diff --git a/chrome/DEPS b/chrome/DEPS
index 43bc0f4..0ceb044 100644
--- a/chrome/DEPS
+++ b/chrome/DEPS
@@ -24,6 +24,7 @@ include_rules = [
"+webkit/blob",
"+webkit/database",
"+webkit/fileapi",
+ "+webkit/quota",
# Allow inclusion of third-party code:
"+third_party/mozilla", # Mozilla interface headers.
diff --git a/chrome/browser/browsing_data_file_system_helper.cc b/chrome/browser/browsing_data_file_system_helper.cc
new file mode 100644
index 0000000..4875133
--- /dev/null
+++ b/chrome/browser/browsing_data_file_system_helper.cc
@@ -0,0 +1,289 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/browsing_data_file_system_helper.h"
+
+#include "base/file_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/profiles/profile.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_context.h"
+#include "webkit/fileapi/file_system_types.h"
+#include "webkit/fileapi/sandbox_mount_point_provider.h"
+#include "webkit/glue/webkit_glue.h"
+
+using WebKit::WebSecurityOrigin;
+
+namespace {
+
+class BrowsingDataFileSystemHelperImpl : public BrowsingDataFileSystemHelper {
+ public:
+ explicit BrowsingDataFileSystemHelperImpl(Profile* profile);
+
+ virtual void StartFetching(
+ Callback1<const std::vector<FileSystemInfo>& >::Type* callback);
+ virtual void CancelNotification();
+ virtual void DeleteFileSystemOrigin(const GURL& origin);
+
+ private:
+ virtual ~BrowsingDataFileSystemHelperImpl();
+
+ // Enumerates all filesystem files in the FILE thread.
+ void FetchFileSystemInfoInFileThread();
+ // Notifies the completion callback in the UI thread.
+ void NotifyInUIThread();
+ // Delete data for an origin on the FILE thread.
+ void DeleteFileSystemOriginInFileThread(const GURL& origin);
+
+ Profile* profile_;
+
+ // This only mutates in the FILE thread.
+ std::vector<FileSystemInfo> file_system_info_;
+
+ // This only mutates on the UI thread.
+ scoped_ptr<Callback1<const std::vector<FileSystemInfo>& >::Type >
+ completion_callback_;
+
+ // Indicates whether or not we're currently fetching information:
+ // it's true when StartFetching() is called in the UI thread, and it's reset
+ // after we notified the callback in the UI thread.
+ // This only mutates on the UI thread.
+ bool is_fetching_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperImpl);
+};
+
+BrowsingDataFileSystemHelperImpl::BrowsingDataFileSystemHelperImpl(
+ Profile* profile)
+ : profile_(profile),
+ is_fetching_(false) {
+ DCHECK(profile_);
+}
+
+BrowsingDataFileSystemHelperImpl::~BrowsingDataFileSystemHelperImpl() {
+}
+
+void BrowsingDataFileSystemHelperImpl::StartFetching(
+ Callback1<const std::vector<FileSystemInfo>& >::Type* callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!is_fetching_);
+ DCHECK(callback);
+ is_fetching_ = true;
+ completion_callback_.reset(callback);
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &BrowsingDataFileSystemHelperImpl::
+ FetchFileSystemInfoInFileThread));
+}
+
+void BrowsingDataFileSystemHelperImpl::CancelNotification() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ completion_callback_.reset(NULL);
+}
+
+void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOrigin(
+ const GURL& origin) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &BrowsingDataFileSystemHelperImpl::
+ DeleteFileSystemOriginInFileThread,
+ origin));
+}
+
+void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator>
+ origin_enumerator(profile_->GetFileSystemContext()->path_manager()->
+ sandbox_provider()->CreateOriginEnumerator());
+
+ // We don't own this pointer; deleting it would be a bad idea.
+ fileapi::FileSystemQuotaUtil* quota_util = profile_->
+ GetFileSystemContext()->GetQuotaUtil(fileapi::kFileSystemTypeTemporary);
+
+ GURL current;
+ while (!(current = origin_enumerator->Next()).is_empty()) {
+ if (current.SchemeIs(chrome::kExtensionScheme)) {
+ // Extension state is not considered browsing data.
+ continue;
+ }
+ int64 persistent_usage = quota_util->GetOriginUsageOnFileThread(current,
+ fileapi::kFileSystemTypePersistent);
+ int64 temporary_usage = quota_util->GetOriginUsageOnFileThread(current,
+ fileapi::kFileSystemTypeTemporary);
+ file_system_info_.push_back(
+ FileSystemInfo(
+ current,
+ origin_enumerator->HasFileSystemType(
+ fileapi::kFileSystemTypePersistent),
+ origin_enumerator->HasFileSystemType(
+ fileapi::kFileSystemTypeTemporary),
+ persistent_usage,
+ temporary_usage));
+ }
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ this, &BrowsingDataFileSystemHelperImpl::NotifyInUIThread));
+}
+
+void BrowsingDataFileSystemHelperImpl::NotifyInUIThread() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(is_fetching_);
+ // Note: completion_callback_ mutates only in the UI thread, so it's safe to
+ // test it here.
+ if (completion_callback_ != NULL) {
+ completion_callback_->Run(file_system_info_);
+ completion_callback_.reset();
+ }
+ is_fetching_ = false;
+}
+
+void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread(
+ const GURL& origin) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ scoped_refptr<fileapi::FileSystemContext>
+ context(profile_->GetFileSystemContext());
+ context->DeleteDataForOriginOnFileThread(origin);
+}
+
+} // namespace
+
+BrowsingDataFileSystemHelper::FileSystemInfo::FileSystemInfo(
+ const GURL& origin,
+ bool has_persistent,
+ bool has_temporary,
+ int64 usage_persistent,
+ int64 usage_temporary)
+ : origin(origin),
+ has_persistent(has_persistent),
+ has_temporary(has_temporary),
+ usage_persistent(usage_persistent),
+ usage_temporary(usage_temporary) {
+}
+
+BrowsingDataFileSystemHelper::FileSystemInfo::~FileSystemInfo() {}
+
+// static
+BrowsingDataFileSystemHelper* BrowsingDataFileSystemHelper::Create(
+ Profile* profile) {
+ return new BrowsingDataFileSystemHelperImpl(profile);
+}
+
+CannedBrowsingDataFileSystemHelper::
+PendingFileSystemInfo::PendingFileSystemInfo() {
+}
+
+CannedBrowsingDataFileSystemHelper::
+PendingFileSystemInfo::PendingFileSystemInfo(const GURL& origin,
+ const fileapi::FileSystemType type,
+ int64 size)
+ : origin(origin),
+ type(type),
+ size(size) {
+}
+
+CannedBrowsingDataFileSystemHelper::
+PendingFileSystemInfo::~PendingFileSystemInfo() {
+}
+
+CannedBrowsingDataFileSystemHelper::CannedBrowsingDataFileSystemHelper(
+ Profile* profile)
+ : profile_(profile),
+ is_fetching_(false) {
+ DCHECK(profile);
+}
+
+CannedBrowsingDataFileSystemHelper::~CannedBrowsingDataFileSystemHelper() {}
+
+CannedBrowsingDataFileSystemHelper*
+ CannedBrowsingDataFileSystemHelper::Clone() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ CannedBrowsingDataFileSystemHelper* clone =
+ new CannedBrowsingDataFileSystemHelper(profile_);
+
+ clone->pending_file_system_info_ = pending_file_system_info_;
+ clone->file_system_info_ = file_system_info_;
+ return clone;
+}
+
+void CannedBrowsingDataFileSystemHelper::AddFileSystem(
+ const GURL& origin, const fileapi::FileSystemType type, const int64 size) {
+ pending_file_system_info_.push_back(
+ PendingFileSystemInfo(origin, type, size));
+}
+
+void CannedBrowsingDataFileSystemHelper::Reset() {
+ file_system_info_.clear();
+ pending_file_system_info_.clear();
+}
+
+bool CannedBrowsingDataFileSystemHelper::empty() const {
+ return file_system_info_.empty() && pending_file_system_info_.empty();
+}
+
+void CannedBrowsingDataFileSystemHelper::StartFetching(
+ Callback1<const std::vector<FileSystemInfo>& >::Type* callback) {
+ DCHECK(!is_fetching_);
+ DCHECK(callback);
+ is_fetching_ = true;
+ completion_callback_.reset(callback);
+
+ for (std::vector<PendingFileSystemInfo>::const_iterator
+ info = pending_file_system_info_.begin();
+ info != pending_file_system_info_.end(); ++info) {
+ bool duplicate = false;
+ for (std::vector<FileSystemInfo>::iterator
+ file_system = file_system_info_.begin();
+ file_system != file_system_info_.end();
+ ++file_system) {
+ if (file_system->origin == info->origin) {
+ if (info->type == fileapi::kFileSystemTypePersistent) {
+ file_system->has_persistent = true;
+ file_system->usage_persistent = info->size;
+ } else {
+ file_system->has_temporary = true;
+ file_system->usage_temporary = info->size;
+ }
+ duplicate = true;
+ break;
+ }
+ }
+ if (duplicate)
+ continue;
+
+ file_system_info_.push_back(FileSystemInfo(
+ info->origin,
+ (info->type == fileapi::kFileSystemTypePersistent),
+ (info->type == fileapi::kFileSystemTypeTemporary),
+ (info->type == fileapi::kFileSystemTypePersistent) ? info->size : 0,
+ (info->type == fileapi::kFileSystemTypeTemporary) ? info->size : 0));
+ }
+ pending_file_system_info_.clear();
+
+ MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
+ &CannedBrowsingDataFileSystemHelper::Notify));
+}
+
+void CannedBrowsingDataFileSystemHelper::Notify() {
+ DCHECK(is_fetching_);
+ if (completion_callback_ != NULL) {
+ completion_callback_->Run(file_system_info_);
+ completion_callback_.reset();
+ }
+ is_fetching_ = false;
+}
diff --git a/chrome/browser/browsing_data_file_system_helper.h b/chrome/browser/browsing_data_file_system_helper.h
new file mode 100644
index 0000000..46b6c1a
--- /dev/null
+++ b/chrome/browser/browsing_data_file_system_helper.h
@@ -0,0 +1,143 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_
+#define CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/callback_old.h"
+#include "base/file_path.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/synchronization/lock.h"
+#include "base/time.h"
+#include "chrome/common/url_constants.h"
+#include "googleurl/src/gurl.h"
+#include "webkit/fileapi/file_system_types.h"
+
+class Profile;
+
+// BrowsingDataFileSystemHelper is an interface for classes dealing with
+// aggregating and deleting browsing data stored in local filesystems. A
+// client of this class needs to call StartFetching from the UI thread to
+// initiate the flow, and it'll be notified by the callback in its UI thread at
+// some later point. The client must call CancelNotification() if it's
+// destroyed before the callback is notified.
+class BrowsingDataFileSystemHelper
+ : public base::RefCountedThreadSafe<BrowsingDataFileSystemHelper> {
+ public:
+ // Contains detailed information about a filesystem
+ struct FileSystemInfo {
+ FileSystemInfo(
+ const GURL& origin,
+ bool has_persistent,
+ bool has_temporary,
+ int64 usage_persistent,
+ int64 usage_temporary);
+ ~FileSystemInfo();
+
+ bool IsFileSchemeData() {
+ return origin.scheme() == chrome::kFileScheme;
+ }
+
+ GURL origin;
+ bool has_persistent;
+ bool has_temporary;
+ int64 usage_persistent;
+ int64 usage_temporary;
+ };
+
+ // Create a BrowsingDataFileSystemHelper instance for the filesystems
+ // stored in |profile|'s user data directory.
+ static BrowsingDataFileSystemHelper* Create(Profile* profile);
+
+ // Starts the fetching process, which will notify its completion via
+ // callback.
+ // This must be called only in the UI thread.
+ virtual void StartFetching(
+ Callback1<const std::vector<FileSystemInfo>& >::Type* callback) = 0;
+ // Cancels the notification callback (i.e., the window that created it no
+ // longer exists).
+ // This must be called only in the UI thread.
+ virtual void CancelNotification() = 0;
+ // Requests a single filesystem to be deleted in the FILE thread.
+ virtual void DeleteFileSystemOrigin(const GURL& origin) = 0;
+
+ protected:
+ friend class base::RefCountedThreadSafe<BrowsingDataFileSystemHelper>;
+ virtual ~BrowsingDataFileSystemHelper() {}
+};
+
+// This class is an implementation of BrowsingDataFileSystemHelper that does
+// not fetch its information from the filesystem tracker, but gets it passed
+// in as a parameter.
+class CannedBrowsingDataFileSystemHelper
+ : public BrowsingDataFileSystemHelper {
+ public:
+ explicit CannedBrowsingDataFileSystemHelper(Profile* profile);
+
+ // Return a copy of the filesystem helper. Only one consumer can use the
+ // StartFetching method at a time, so we need to create a copy of the helper
+ // everytime we instantiate a cookies tree model for it.
+ CannedBrowsingDataFileSystemHelper* Clone();
+
+ // Add a filesystem to the set of canned filesystems that is
+ // returned by this helper.
+ void AddFileSystem(const GURL& origin,
+ fileapi::FileSystemType type,
+ int64 size);
+
+ // Clear the list of canned filesystems.
+ void Reset();
+
+ // True if no filesystems are currently stored.
+ bool empty() const;
+
+ // BrowsingDataFileSystemHelper methods.
+ virtual void StartFetching(
+ Callback1<const std::vector<FileSystemInfo>& >::Type* callback);
+ virtual void CancelNotification() {}
+ virtual void DeleteFileSystemOrigin(const GURL& origin) {}
+
+ private:
+ struct PendingFileSystemInfo {
+ PendingFileSystemInfo();
+ PendingFileSystemInfo(const GURL& origin,
+ fileapi::FileSystemType type,
+ int64 size);
+ ~PendingFileSystemInfo();
+
+ GURL origin;
+ fileapi::FileSystemType type;
+ int64 size;
+ };
+
+ // StartFetching's callback should be executed asynchronously, Notify handles
+ // that nicely.
+ void Notify();
+
+ virtual ~CannedBrowsingDataFileSystemHelper();
+
+ Profile* profile_;
+
+ std::vector<PendingFileSystemInfo> pending_file_system_info_;
+
+ std::vector<FileSystemInfo> file_system_info_;
+
+ scoped_ptr<Callback1<const std::vector<FileSystemInfo>& >::Type >
+ completion_callback_;
+
+ // Indicates whether or not we're currently fetching information:
+ // it's true when StartFetching() is called in the UI thread, and it's reset
+ // after we notified the callback in the UI thread.
+ // This only mutates on the UI thread.
+ bool is_fetching_;
+
+ DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataFileSystemHelper);
+};
+
+#endif // CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_
diff --git a/chrome/browser/browsing_data_file_system_helper_browsertest.cc b/chrome/browser/browsing_data_file_system_helper_browsertest.cc
new file mode 100644
index 0000000..fe4a941
--- /dev/null
+++ b/chrome/browser/browsing_data_file_system_helper_browsertest.cc
@@ -0,0 +1,216 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/file_path.h"
+#include "base/memory/ref_counted.h"
+#include "base/message_loop.h"
+#include "chrome/browser/browsing_data_file_system_helper.h"
+#include "chrome/browser/browsing_data_helper_browsertest.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/testing_profile.h"
+#include "chrome/test/ui_test_utils.h"
+#include "content/browser/browser_thread.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/fileapi/file_system_context.h"
+#include "webkit/fileapi/file_system_path_manager.h"
+#include "webkit/fileapi/file_system_types.h"
+#include "webkit/fileapi/file_system_usage_cache.h"
+#include "webkit/fileapi/sandbox_mount_point_provider.h"
+
+namespace {
+
+typedef BrowsingDataHelperCallback<BrowsingDataFileSystemHelper::FileSystemInfo>
+ TestCompletionCallback;
+
+const char kTestOrigin1[] = "http://host1:1/";
+const char kTestOrigin2[] = "http://host2:1/";
+const char kTestOrigin3[] = "http://host3:1/";
+
+const char kTestOriginExtension[] =
+ "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj:1/";
+
+const int kEmptyFileSystemSize = fileapi::FileSystemUsageCache::kUsageFileSize;
+
+class BrowsingDataFileSystemHelperTest : public InProcessBrowserTest {
+ public:
+ virtual void PopulateTestData() {
+ const GURL origin1(kTestOrigin1);
+ const GURL origin2(kTestOrigin2);
+ const GURL origin3(kTestOrigin3);
+
+ sandbox_ = testing_profile_.GetFileSystemContext()->
+ path_manager()->sandbox_provider();
+
+ CreateDirectoryForOriginAndType(origin1, fileapi::kFileSystemTypeTemporary);
+ CreateDirectoryForOriginAndType(origin2,
+ fileapi::kFileSystemTypePersistent);
+ CreateDirectoryForOriginAndType(origin3, fileapi::kFileSystemTypeTemporary);
+ CreateDirectoryForOriginAndType(origin3,
+ fileapi::kFileSystemTypePersistent);
+ }
+
+ protected:
+ void CreateDirectoryForOriginAndType(const GURL& origin,
+ fileapi::FileSystemType type) {
+ FilePath target = sandbox_->ValidateFileSystemRootAndGetPathOnFileThread(
+ origin, type, FilePath(), true);
+ ASSERT_TRUE(file_util::CreateDirectory(target));
+ }
+
+ TestingProfile testing_profile_;
+ fileapi::SandboxMountPointProvider* sandbox_;
+};
+
+// Called back by BrowsingDataFileSystemHelper on the UI thread once the
+// database information has been retrieved.
+class StopTestOnCallback {
+ public:
+ explicit StopTestOnCallback(
+ BrowsingDataFileSystemHelper* file_system_helper)
+ : file_system_helper_(file_system_helper) {
+ DCHECK(file_system_helper_);
+ }
+
+ void CallbackFetchData(
+ const std::vector<BrowsingDataFileSystemHelper::FileSystemInfo>&
+ file_system_info_list) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ EXPECT_EQ(3UL, file_system_info_list.size());
+
+ // Order is arbitrary, verify all three origins.
+ bool test_hosts_found[3] = {false, false, false};
+ for (size_t i = 0; i < file_system_info_list.size(); i++) {
+ BrowsingDataFileSystemHelper::FileSystemInfo info =
+ file_system_info_list.at(i);
+ if (info.origin == GURL(kTestOrigin1)) {
+ test_hosts_found[0] = true;
+ EXPECT_FALSE(info.has_persistent);
+ EXPECT_TRUE(info.has_temporary);
+ EXPECT_EQ(0, info.usage_persistent);
+ EXPECT_EQ(kEmptyFileSystemSize, info.usage_temporary);
+ } else if (info.origin == GURL(kTestOrigin2)) {
+ test_hosts_found[1] = true;
+ EXPECT_TRUE(info.has_persistent);
+ EXPECT_FALSE(info.has_temporary);
+ EXPECT_EQ(kEmptyFileSystemSize, info.usage_persistent);
+ EXPECT_EQ(0, info.usage_temporary);
+ } else if (info.origin == GURL(kTestOrigin3)) {
+ test_hosts_found[2] = true;
+ EXPECT_TRUE(info.has_persistent);
+ EXPECT_TRUE(info.has_temporary);
+ EXPECT_EQ(kEmptyFileSystemSize, info.usage_persistent);
+ EXPECT_EQ(kEmptyFileSystemSize, info.usage_temporary);
+ } else {
+ ADD_FAILURE() << info.origin.spec() << " isn't an origin we added.";
+ }
+ }
+ for (size_t i = 0; i < arraysize(test_hosts_found); i++) {
+ EXPECT_TRUE(test_hosts_found[i]);
+ }
+ MessageLoop::current()->Quit();
+ }
+
+ void CallbackDeleteData(
+ const std::vector<BrowsingDataFileSystemHelper::FileSystemInfo>&
+ file_system_info_list) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ EXPECT_EQ(1UL, file_system_info_list.size());
+ BrowsingDataFileSystemHelper::FileSystemInfo info =
+ file_system_info_list.at(0);
+ EXPECT_EQ(info.origin, GURL(kTestOrigin3));
+ EXPECT_TRUE(info.has_persistent);
+ EXPECT_TRUE(info.has_temporary);
+ EXPECT_EQ(kEmptyFileSystemSize, info.usage_persistent);
+ EXPECT_EQ(kEmptyFileSystemSize, info.usage_temporary);
+ MessageLoop::current()->Quit();
+ }
+
+ private:
+ BrowsingDataFileSystemHelper* file_system_helper_;
+};
+
+
+IN_PROC_BROWSER_TEST_F(BrowsingDataFileSystemHelperTest, FetchData) {
+ PopulateTestData();
+ scoped_refptr<BrowsingDataFileSystemHelper> file_system_helper(
+ BrowsingDataFileSystemHelper::Create(&testing_profile_));
+ StopTestOnCallback stop_test_on_callback(file_system_helper);
+ file_system_helper->StartFetching(
+ NewCallback(&stop_test_on_callback,
+ &StopTestOnCallback::CallbackFetchData));
+ // Blocks until StopTestOnCallback::CallbackFetchData is notified.
+ ui_test_utils::RunMessageLoop();
+}
+
+IN_PROC_BROWSER_TEST_F(BrowsingDataFileSystemHelperTest, DeleteData) {
+ PopulateTestData();
+ scoped_refptr<BrowsingDataFileSystemHelper> file_system_helper(
+ BrowsingDataFileSystemHelper::Create(&testing_profile_));
+ StopTestOnCallback stop_test_on_callback(file_system_helper);
+ file_system_helper->DeleteFileSystemOrigin(GURL(kTestOrigin1));
+ file_system_helper->DeleteFileSystemOrigin(GURL(kTestOrigin2));
+ file_system_helper->StartFetching(
+ NewCallback(&stop_test_on_callback,
+ &StopTestOnCallback::CallbackDeleteData));
+ // Blocks until StopTestOnCallback::CallbackDeleteData is notified.
+ ui_test_utils::RunMessageLoop();
+}
+
+IN_PROC_BROWSER_TEST_F(BrowsingDataFileSystemHelperTest, CannedAddFileSystem) {
+ const GURL origin1(kTestOrigin1);
+ const GURL origin2(kTestOrigin2);
+
+ scoped_refptr<CannedBrowsingDataFileSystemHelper> helper(
+ new CannedBrowsingDataFileSystemHelper(&testing_profile_));
+ helper->AddFileSystem(origin1, fileapi::kFileSystemTypePersistent, 200);
+ helper->AddFileSystem(origin2, fileapi::kFileSystemTypeTemporary, 100);
+
+ TestCompletionCallback callback;
+ helper->StartFetching(
+ NewCallback(&callback, &TestCompletionCallback::callback));
+
+ std::vector<BrowsingDataFileSystemHelper::FileSystemInfo> result =
+ callback.result();
+
+ EXPECT_EQ(2U, result.size());
+ EXPECT_EQ(origin1, result[0].origin);
+ EXPECT_TRUE(result[0].has_persistent);
+ EXPECT_FALSE(result[0].has_temporary);
+ EXPECT_EQ(200, result[0].usage_persistent);
+ EXPECT_EQ(0, result[0].usage_temporary);
+ EXPECT_EQ(origin2, result[1].origin);
+ EXPECT_FALSE(result[1].has_persistent);
+ EXPECT_TRUE(result[1].has_temporary);
+ EXPECT_EQ(0, result[1].usage_persistent);
+ EXPECT_EQ(100, result[1].usage_temporary);
+}
+
+IN_PROC_BROWSER_TEST_F(BrowsingDataFileSystemHelperTest, CannedUnique) {
+ const GURL origin3(kTestOrigin3);
+
+ scoped_refptr<CannedBrowsingDataFileSystemHelper> helper(
+ new CannedBrowsingDataFileSystemHelper(&testing_profile_));
+ helper->AddFileSystem(origin3, fileapi::kFileSystemTypePersistent, 200);
+ helper->AddFileSystem(origin3, fileapi::kFileSystemTypeTemporary, 100);
+
+ TestCompletionCallback callback;
+ helper->StartFetching(
+ NewCallback(&callback, &TestCompletionCallback::callback));
+
+ std::vector<BrowsingDataFileSystemHelper::FileSystemInfo> result =
+ callback.result();
+
+ EXPECT_EQ(1U, result.size());
+ EXPECT_EQ(origin3, result[0].origin);
+ EXPECT_TRUE(result[0].has_persistent);
+ EXPECT_TRUE(result[0].has_temporary);
+ EXPECT_EQ(200, result[0].usage_persistent);
+ EXPECT_EQ(100, result[0].usage_temporary);
+}
+
+} // namespace
diff --git a/chrome/browser/browsing_data_file_system_helper_unittest.cc b/chrome/browser/browsing_data_file_system_helper_unittest.cc
new file mode 100644
index 0000000..06cdca6
--- /dev/null
+++ b/chrome/browser/browsing_data_file_system_helper_unittest.cc
@@ -0,0 +1,31 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/browsing_data_file_system_helper.h"
+#include "chrome/test/testing_browser_process_test.h"
+#include "chrome/test/testing_profile.h"
+
+namespace {
+
+typedef TestingBrowserProcessTest CannedBrowsingDataFileSystemHelperTest;
+
+TEST_F(CannedBrowsingDataFileSystemHelperTest, Empty) {
+ TestingProfile profile;
+
+ const GURL origin("http://host1:1/");
+
+ scoped_refptr<CannedBrowsingDataFileSystemHelper> helper(
+ new CannedBrowsingDataFileSystemHelper(&profile));
+
+ ASSERT_TRUE(helper->empty());
+ helper->AddFileSystem(origin, fileapi::kFileSystemTypeTemporary, 0);
+ ASSERT_FALSE(helper->empty());
+ helper->Reset();
+ ASSERT_TRUE(helper->empty());
+}
+
+} // namespace
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index ca4feed..326ba11 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -322,6 +322,8 @@
'browser/browsing_data_appcache_helper.h',
'browser/browsing_data_database_helper.cc',
'browser/browsing_data_database_helper.h',
+ 'browser/browsing_data_file_system_helper.cc',
+ 'browser/browsing_data_file_system_helper.h',
'browser/browsing_data_indexed_db_helper.cc',
'browser/browsing_data_indexed_db_helper.h',
'browser/browsing_data_local_storage_helper.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 1d5f6ee..2e824e7 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1271,6 +1271,7 @@
'browser/browser_url_handler_unittest.cc',
'browser/browsing_data_appcache_helper_unittest.cc',
'browser/browsing_data_database_helper_unittest.cc',
+ 'browser/browsing_data_file_system_helper_unittest.cc',
'browser/browsing_data_indexed_db_helper_unittest.cc',
'browser/browsing_data_local_storage_helper_unittest.cc',
'browser/chrome_browser_application_mac_unittest.mm',
@@ -2244,6 +2245,7 @@
'browser/automation/automation_tab_helper_browsertest.cc',
'browser/browser_browsertest.cc',
'browser/browsing_data_database_helper_browsertest.cc',
+ 'browser/browsing_data_file_system_helper_browsertest.cc',
'browser/browsing_data_helper_browsertest.h',
'browser/browsing_data_indexed_db_helper_browsertest.cc',
'browser/browsing_data_local_storage_helper_browsertest.cc',
diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc
index 2c1d98c..0ae4404 100644
--- a/chrome/test/testing_profile.cc
+++ b/chrome/test/testing_profile.cc
@@ -59,6 +59,8 @@
#include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "webkit/database/database_tracker.h"
+#include "webkit/fileapi/file_system_context.h"
+#include "webkit/quota/quota_manager.h"
using base::Time;
using testing::NiceMock;
@@ -514,7 +516,19 @@ PersonalDataManager* TestingProfile::GetPersonalDataManager() {
}
fileapi::FileSystemContext* TestingProfile::GetFileSystemContext() {
- return NULL;
+ if (!file_system_context_) {
+ file_system_context_ = new fileapi::FileSystemContext(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
+ GetExtensionSpecialStoragePolicy(),
+ NULL,
+ GetPath(),
+ IsOffTheRecord(),
+ true, // Allow file access from files.
+ true, // Unlimited quota.
+ NULL);
+ }
+ return file_system_context_.get();
}
quota::QuotaManager* TestingProfile::GetQuotaManager() {
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index 18f925a..4614c8a 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -382,6 +382,9 @@ class TestingProfile : public Profile {
scoped_refptr<ExtensionSpecialStoragePolicy>
extension_special_storage_policy_;
+ // FileSystemContext. Created lazily by GetFileSystemContext().
+ scoped_refptr<fileapi::FileSystemContext> file_system_context_;
+
// The proxy prefs tracker.
scoped_refptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;