Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync_file_system / local / canned_syncable_file_system.cc
index 4da0015..c636e35 100644 (file)
@@ -9,13 +9,13 @@
 
 #include "base/bind.h"
 #include "base/bind_helpers.h"
-#include "base/file_util.h"
 #include "base/files/file.h"
+#include "base/files/file_util.h"
 #include "base/guid.h"
-#include "base/message_loop/message_loop_proxy.h"
 #include "base/run_loop.h"
 #include "base/single_thread_task_runner.h"
 #include "base/task_runner_util.h"
+#include "base/thread_task_runner_handle.h"
 #include "chrome/browser/sync_file_system/file_change.h"
 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
 #include "content/public/test/mock_blob_url_request_context.h"
 #include "content/public/test/mock_special_storage_policy.h"
 #include "content/public/test/test_file_system_options.h"
+#include "storage/browser/fileapi/external_mount_points.h"
+#include "storage/browser/fileapi/file_system_backend.h"
+#include "storage/browser/fileapi/file_system_context.h"
+#include "storage/browser/fileapi/file_system_operation_context.h"
+#include "storage/browser/fileapi/file_system_operation_runner.h"
+#include "storage/browser/quota/quota_manager.h"
+#include "storage/common/blob/shareable_file_reference.h"
 #include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/browser/fileapi/external_mount_points.h"
-#include "webkit/browser/fileapi/file_system_backend.h"
-#include "webkit/browser/fileapi/file_system_context.h"
-#include "webkit/browser/fileapi/file_system_operation_context.h"
-#include "webkit/browser/fileapi/file_system_operation_runner.h"
-#include "webkit/browser/quota/quota_manager.h"
-#include "webkit/common/blob/shareable_file_reference.h"
 
 using base::File;
-using fileapi::FileSystemContext;
-using fileapi::FileSystemOperationRunner;
-using fileapi::FileSystemURL;
-using fileapi::FileSystemURLSet;
-using quota::QuotaManager;
+using storage::FileSystemContext;
+using storage::FileSystemOperationRunner;
+using storage::FileSystemURL;
+using storage::FileSystemURLSet;
+using storage::QuotaManager;
 using content::MockBlobURLRequestContext;
 using content::ScopedTextBlob;
 
@@ -46,14 +46,13 @@ namespace sync_file_system {
 
 namespace {
 
-void Quit() { base::MessageLoop::current()->Quit(); }
-
 template <typename R>
 void AssignAndQuit(base::TaskRunner* original_task_runner,
+                   const base::Closure& quit_closure,
                    R* result_out, R result) {
   DCHECK(result_out);
   *result_out = result;
-  original_task_runner->PostTask(FROM_HERE, base::Bind(&Quit));
+  original_task_runner->PostTask(FROM_HERE, quit_closure);
 }
 
 template <typename R>
@@ -62,25 +61,28 @@ R RunOnThread(
     const tracked_objects::Location& location,
     const base::Callback<void(const base::Callback<void(R)>& callback)>& task) {
   R result;
+  base::RunLoop run_loop;
   task_runner->PostTask(
       location,
       base::Bind(task, base::Bind(&AssignAndQuit<R>,
-                                  base::MessageLoopProxy::current(),
+                                  base::ThreadTaskRunnerHandle::Get(),
+                                  run_loop.QuitClosure(),
                                   &result)));
-  base::MessageLoop::current()->Run();
+  run_loop.Run();
   return result;
 }
 
 void RunOnThread(base::SingleThreadTaskRunner* task_runner,
                  const tracked_objects::Location& location,
                  const base::Closure& task) {
+  base::RunLoop run_loop;
   task_runner->PostTaskAndReply(
       location, task,
       base::Bind(base::IgnoreResult(
-          base::Bind(&base::MessageLoopProxy::PostTask,
-                     base::MessageLoopProxy::current(),
-                     FROM_HERE, base::Bind(&Quit)))));
-  base::MessageLoop::current()->Run();
+          base::Bind(&base::SingleThreadTaskRunner::PostTask,
+                     base::ThreadTaskRunnerHandle::Get(),
+                     FROM_HERE, run_loop.QuitClosure()))));
+  run_loop.Run();
 }
 
 void EnsureRunningOn(base::SingleThreadTaskRunner* runner) {
@@ -90,8 +92,8 @@ void EnsureRunningOn(base::SingleThreadTaskRunner* runner) {
 void VerifySameTaskRunner(
     base::SingleThreadTaskRunner* runner1,
     base::SingleThreadTaskRunner* runner2) {
-  ASSERT_TRUE(runner1 != NULL);
-  ASSERT_TRUE(runner2 != NULL);
+  ASSERT_TRUE(runner1 != nullptr);
+  ASSERT_TRUE(runner2 != nullptr);
   runner1->PostTask(FROM_HERE,
                     base::Bind(&EnsureRunningOn, make_scoped_refptr(runner2)));
 }
@@ -102,7 +104,7 @@ void OnCreateSnapshotFileAndVerifyData(
     base::File::Error result,
     const base::File::Info& file_info,
     const base::FilePath& platform_path,
-    const scoped_refptr<webkit_blob::ShareableFileReference>& /* file_ref */) {
+    const scoped_refptr<storage::ShareableFileReference>& /* file_ref */) {
   if (result != base::File::FILE_OK) {
     callback.Run(result);
     return;
@@ -122,7 +124,7 @@ void OnCreateSnapshotFile(
     base::File::Error result,
     const base::File::Info& file_info,
     const base::FilePath& platform_path,
-    const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
+    const scoped_refptr<storage::ShareableFileReference>& file_ref) {
   DCHECK(!file_ref.get());
   DCHECK(file_info_out);
   DCHECK(platform_path_out);
@@ -131,12 +133,11 @@ void OnCreateSnapshotFile(
   callback.Run(result);
 }
 
-void OnReadDirectory(
-    CannedSyncableFileSystem::FileEntryList* entries_out,
-    const CannedSyncableFileSystem::StatusCallback& callback,
-    base::File::Error error,
-    const fileapi::FileSystemOperation::FileEntryList& entries,
-    bool has_more) {
+void OnReadDirectory(CannedSyncableFileSystem::FileEntryList* entries_out,
+                     const CannedSyncableFileSystem::StatusCallback& callback,
+                     base::File::Error error,
+                     const storage::FileSystemOperation::FileEntryList& entries,
+                     bool has_more) {
   DCHECK(entries_out);
   entries_out->reserve(entries_out->size() + entries.size());
   std::copy(entries.begin(), entries.end(), std::back_inserter(*entries_out));
@@ -159,8 +160,8 @@ class WriteHelper {
 
   ~WriteHelper() {
     if (request_context_) {
-      base::MessageLoop::current()->DeleteSoon(FROM_HERE,
-                                               request_context_.release());
+      base::ThreadTaskRunnerHandle::Get()->DeleteSoon(
+          FROM_HERE, request_context_.release());
     }
   }
 
@@ -185,10 +186,12 @@ class WriteHelper {
   DISALLOW_COPY_AND_ASSIGN(WriteHelper);
 };
 
-void DidGetUsageAndQuota(const quota::StatusCallback& callback,
-                         int64* usage_out, int64* quota_out,
-                         quota::QuotaStatusCode status,
-                         int64 usage, int64 quota) {
+void DidGetUsageAndQuota(const storage::StatusCallback& callback,
+                         int64* usage_out,
+                         int64* quota_out,
+                         storage::QuotaStatusCode status,
+                         int64 usage,
+                         int64 quota) {
   *usage_out = usage;
   *quota_out = quota;
   callback.Run(status);
@@ -206,10 +209,10 @@ void EnsureLastTaskRuns(base::SingleThreadTaskRunner* runner) {
 CannedSyncableFileSystem::CannedSyncableFileSystem(
     const GURL& origin,
     leveldb::Env* env_override,
-    base::SingleThreadTaskRunner* io_task_runner,
-    base::SingleThreadTaskRunner* file_task_runner)
+    const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
+    const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner)
     : origin_(origin),
-      type_(fileapi::kFileSystemTypeSyncable),
+      type_(storage::kFileSystemTypeSyncable),
       result_(base::File::FILE_OK),
       sync_status_(sync_file_system::SYNC_STATUS_OK),
       env_override_(env_override),
@@ -226,43 +229,44 @@ void CannedSyncableFileSystem::SetUp(QuotaMode quota_mode) {
   ASSERT_FALSE(is_filesystem_set_up_);
   ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
 
-  scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
+  scoped_refptr<storage::SpecialStoragePolicy> storage_policy =
       new content::MockSpecialStoragePolicy();
 
   if (quota_mode == QUOTA_ENABLED) {
     quota_manager_ = new QuotaManager(false /* is_incognito */,
                                       data_dir_.path(),
                                       io_task_runner_.get(),
-                                      base::MessageLoopProxy::current().get(),
+                                      base::ThreadTaskRunnerHandle::Get().get(),
                                       storage_policy.get());
   }
 
   std::vector<std::string> additional_allowed_schemes;
   additional_allowed_schemes.push_back(origin_.scheme());
-  fileapi::FileSystemOptions options(
-      fileapi::FileSystemOptions::PROFILE_MODE_NORMAL,
+  storage::FileSystemOptions options(
+      storage::FileSystemOptions::PROFILE_MODE_NORMAL,
       additional_allowed_schemes,
       env_override_);
 
-  ScopedVector<fileapi::FileSystemBackend> additional_backends;
+  ScopedVector<storage::FileSystemBackend> additional_backends;
   additional_backends.push_back(SyncFileSystemBackend::CreateForTesting());
 
   file_system_context_ = new FileSystemContext(
       io_task_runner_.get(),
       file_task_runner_.get(),
-      fileapi::ExternalMountPoints::CreateRefCounted().get(),
+      storage::ExternalMountPoints::CreateRefCounted().get(),
       storage_policy.get(),
-      quota_manager_ ? quota_manager_->proxy() : NULL,
+      quota_manager_.get() ? quota_manager_->proxy() : nullptr,
       additional_backends.Pass(),
-      std::vector<fileapi::URLRequestAutoMountHandler>(),
-      data_dir_.path(), options);
+      std::vector<storage::URLRequestAutoMountHandler>(),
+      data_dir_.path(),
+      options);
 
   is_filesystem_set_up_ = true;
 }
 
 void CannedSyncableFileSystem::TearDown() {
-  quota_manager_ = NULL;
-  file_system_context_ = NULL;
+  quota_manager_ = nullptr;
+  file_system_context_ = nullptr;
 
   // Make sure we give some more time to finish tasks on other threads.
   EnsureLastTaskRuns(io_task_runner_.get());
@@ -280,14 +284,16 @@ FileSystemURL CannedSyncableFileSystem::URL(const std::string& path) const {
 File::Error CannedSyncableFileSystem::OpenFileSystem() {
   EXPECT_TRUE(is_filesystem_set_up_);
 
+  base::RunLoop run_loop;
   io_task_runner_->PostTask(
       FROM_HERE,
       base::Bind(&CannedSyncableFileSystem::DoOpenFileSystem,
                  base::Unretained(this),
                  base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem,
                             base::Unretained(this),
-                            base::MessageLoopProxy::current())));
-  base::MessageLoop::current()->Run();
+                            base::ThreadTaskRunnerHandle::Get(),
+                            run_loop.QuitClosure())));
+  run_loop.Run();
 
   if (backend()->sync_context()) {
     // Register 'this' as a sync status observer.
@@ -313,6 +319,7 @@ void CannedSyncableFileSystem::RemoveSyncStatusObserver(
 SyncStatusCode CannedSyncableFileSystem::MaybeInitializeFileSystemContext(
     LocalFileSyncContext* sync_context) {
   DCHECK(sync_context);
+  base::RunLoop run_loop;
   sync_status_ = sync_file_system::SYNC_STATUS_UNKNOWN;
   VerifySameTaskRunner(io_task_runner_.get(),
                        sync_context->io_task_runner_.get());
@@ -320,8 +327,9 @@ SyncStatusCode CannedSyncableFileSystem::MaybeInitializeFileSystemContext(
       origin_,
       file_system_context_.get(),
       base::Bind(&CannedSyncableFileSystem::DidInitializeFileSystemContext,
-                 base::Unretained(this)));
-  base::MessageLoop::current()->Run();
+                 base::Unretained(this),
+                 run_loop.QuitClosure()));
+  run_loop.Run();
   return sync_status_;
 }
 
@@ -346,24 +354,22 @@ File::Error CannedSyncableFileSystem::CreateFile(const FileSystemURL& url) {
 
 File::Error CannedSyncableFileSystem::Copy(
     const FileSystemURL& src_url, const FileSystemURL& dest_url) {
-  return RunOnThread<File::Error>(
-      io_task_runner_.get(),
-      FROM_HERE,
-      base::Bind(&CannedSyncableFileSystem::DoCopy,
-                 base::Unretained(this),
-                 src_url,
-                 dest_url));
+  return RunOnThread<File::Error>(io_task_runner_.get(),
+                                  FROM_HERE,
+                                  base::Bind(&CannedSyncableFileSystem::DoCopy,
+                                             base::Unretained(this),
+                                             src_url,
+                                             dest_url));
 }
 
 File::Error CannedSyncableFileSystem::Move(
     const FileSystemURL& src_url, const FileSystemURL& dest_url) {
-  return RunOnThread<File::Error>(
-      io_task_runner_.get(),
-      FROM_HERE,
-      base::Bind(&CannedSyncableFileSystem::DoMove,
-                 base::Unretained(this),
-                 src_url,
-                 dest_url));
+  return RunOnThread<File::Error>(io_task_runner_.get(),
+                                  FROM_HERE,
+                                  base::Bind(&CannedSyncableFileSystem::DoMove,
+                                             base::Unretained(this),
+                                             src_url,
+                                             dest_url));
 }
 
 File::Error CannedSyncableFileSystem::TruncateFile(
@@ -449,21 +455,21 @@ File::Error CannedSyncableFileSystem::GetMetadataAndPlatformPath(
 }
 
 File::Error CannedSyncableFileSystem::ReadDirectory(
-    const fileapi::FileSystemURL& url,
+    const storage::FileSystemURL& url,
     FileEntryList* entries) {
   return RunOnThread<File::Error>(
       io_task_runner_.get(),
       FROM_HERE,
       base::Bind(&CannedSyncableFileSystem::DoReadDirectory,
-          base::Unretained(this),
-          url,
-          entries));
+                 base::Unretained(this),
+                 url,
+                 entries));
 }
 
 int64 CannedSyncableFileSystem::Write(
     net::URLRequestContext* url_request_context,
     const FileSystemURL& url,
-    scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle) {
+    scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
   return RunOnThread<int64>(io_task_runner_.get(),
                             FROM_HERE,
                             base::Bind(&CannedSyncableFileSystem::DoWrite,
@@ -494,9 +500,10 @@ File::Error CannedSyncableFileSystem::DeleteFileSystem() {
                  type_));
 }
 
-quota::QuotaStatusCode CannedSyncableFileSystem::GetUsageAndQuota(
-    int64* usage, int64* quota) {
-  return RunOnThread<quota::QuotaStatusCode>(
+storage::QuotaStatusCode CannedSyncableFileSystem::GetUsageAndQuota(
+    int64* usage,
+    int64* quota) {
+  return RunOnThread<storage::QuotaStatusCode>(
       io_task_runner_.get(),
       FROM_HERE,
       base::Bind(&CannedSyncableFileSystem::DoGetUsageAndQuota,
@@ -507,37 +514,35 @@ quota::QuotaStatusCode CannedSyncableFileSystem::GetUsageAndQuota(
 
 void CannedSyncableFileSystem::GetChangedURLsInTracker(
     FileSystemURLSet* urls) {
-  RunOnThread(
-      file_task_runner_.get(),
-      FROM_HERE,
-      base::Bind(&LocalFileChangeTracker::GetAllChangedURLs,
-                 base::Unretained(backend()->change_tracker()),
-                 urls));
+  RunOnThread(file_task_runner_.get(),
+              FROM_HERE,
+              base::Bind(&LocalFileChangeTracker::GetAllChangedURLs,
+                         base::Unretained(backend()->change_tracker()),
+                         urls));
 }
 
 void CannedSyncableFileSystem::ClearChangeForURLInTracker(
     const FileSystemURL& url) {
-  RunOnThread(
-      file_task_runner_.get(),
-      FROM_HERE,
-      base::Bind(&LocalFileChangeTracker::ClearChangesForURL,
-                 base::Unretained(backend()->change_tracker()),
-                 url));
+  RunOnThread(file_task_runner_.get(),
+              FROM_HERE,
+              base::Bind(&LocalFileChangeTracker::ClearChangesForURL,
+                         base::Unretained(backend()->change_tracker()),
+                         url));
 }
 
 void CannedSyncableFileSystem::GetChangesForURLInTracker(
     const FileSystemURL& url,
     FileChangeList* changes) {
-  RunOnThread(
-      file_task_runner_.get(),
-      FROM_HERE,
-      base::Bind(&LocalFileChangeTracker::GetChangesForURL,
-                 base::Unretained(backend()->change_tracker()),
-                 url, changes));
+  RunOnThread(file_task_runner_.get(),
+              FROM_HERE,
+              base::Bind(&LocalFileChangeTracker::GetChangesForURL,
+                         base::Unretained(backend()->change_tracker()),
+                         url,
+                         changes));
 }
 
 SyncFileSystemBackend* CannedSyncableFileSystem::backend() {
-  return SyncFileSystemBackend::GetBackend(file_system_context_);
+  return SyncFileSystemBackend::GetBackend(file_system_context_.get());
 }
 
 FileSystemOperationRunner* CannedSyncableFileSystem::operation_runner() {
@@ -559,8 +564,9 @@ void CannedSyncableFileSystem::DoOpenFileSystem(
   EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread());
   EXPECT_FALSE(is_filesystem_opened_);
   file_system_context_->OpenFileSystem(
-      origin_, type_,
-      fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
+      origin_,
+      type_,
+      storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
       callback);
 }
 
@@ -588,9 +594,11 @@ void CannedSyncableFileSystem::DoCopy(
   EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread());
   EXPECT_TRUE(is_filesystem_opened_);
   operation_runner()->Copy(
-      src_url, dest_url,
-      fileapi::FileSystemOperation::OPTION_NONE,
-      fileapi::FileSystemOperationRunner::CopyProgressCallback(), callback);
+      src_url,
+      dest_url,
+      storage::FileSystemOperation::OPTION_NONE,
+      storage::FileSystemOperationRunner::CopyProgressCallback(),
+      callback);
 }
 
 void CannedSyncableFileSystem::DoMove(
@@ -600,7 +608,7 @@ void CannedSyncableFileSystem::DoMove(
   EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread());
   EXPECT_TRUE(is_filesystem_opened_);
   operation_runner()->Move(
-      src_url, dest_url, fileapi::FileSystemOperation::OPTION_NONE, callback);
+      src_url, dest_url, storage::FileSystemOperation::OPTION_NONE, callback);
 }
 
 void CannedSyncableFileSystem::DoTruncateFile(
@@ -679,7 +687,7 @@ void CannedSyncableFileSystem::DoReadDirectory(
 void CannedSyncableFileSystem::DoWrite(
     net::URLRequestContext* url_request_context,
     const FileSystemURL& url,
-    scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle,
+    scoped_ptr<storage::BlobDataHandle> blob_data_handle,
     const WriteCallback& callback) {
   EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread());
   EXPECT_TRUE(is_filesystem_opened_);
@@ -708,10 +716,10 @@ void CannedSyncableFileSystem::DoWriteString(
 void CannedSyncableFileSystem::DoGetUsageAndQuota(
     int64* usage,
     int64* quota,
-    const quota::StatusCallback& callback) {
+    const storage::StatusCallback& callback) {
   EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread());
   EXPECT_TRUE(is_filesystem_opened_);
-  DCHECK(quota_manager_);
+  DCHECK(quota_manager_.get());
   quota_manager_->GetUsageAndQuota(
       origin_, storage_type(),
       base::Bind(&DidGetUsageAndQuota, callback, usage, quota));
@@ -719,6 +727,7 @@ void CannedSyncableFileSystem::DoGetUsageAndQuota(
 
 void CannedSyncableFileSystem::DidOpenFileSystem(
     base::SingleThreadTaskRunner* original_task_runner,
+    const base::Closure& quit_closure,
     const GURL& root,
     const std::string& name,
     File::Error result) {
@@ -733,18 +742,20 @@ void CannedSyncableFileSystem::DidOpenFileSystem(
         base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem,
                    base::Unretained(this),
                    make_scoped_refptr(original_task_runner),
+                   quit_closure,
                    root, name, result));
     return;
   }
   result_ = result;
   root_url_ = root;
-  base::MessageLoop::current()->Quit();
+  quit_closure.Run();
 }
 
 void CannedSyncableFileSystem::DidInitializeFileSystemContext(
+    const base::Closure& quit_closure,
     SyncStatusCode status) {
   sync_status_ = status;
-  base::MessageLoop::current()->Quit();
+  quit_closure.Run();
 }
 
 void CannedSyncableFileSystem::InitializeSyncStatusObserver() {