summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/syncable
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-30 16:01:04 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-30 16:01:04 +0000
commitdf2e46d111eb84b7ba1e77315a90e23ff0b957ee (patch)
tree622352915964e644559c3ff7f985b449fa0608ff /webkit/fileapi/syncable
parentb183f217e4b7eb2260f62855dd34f455f2bf6f2b (diff)
downloadchromium_src-df2e46d111eb84b7ba1e77315a90e23ff0b957ee.zip
chromium_src-df2e46d111eb84b7ba1e77315a90e23ff0b957ee.tar.gz
chromium_src-df2e46d111eb84b7ba1e77315a90e23ff0b957ee.tar.bz2
Fix SyncableFileSystem initialization order
BUG=158490 TEST=SyncableFileSystemUtilTest.SerializeBeforeOpenFileSystem Review URL: https://codereview.chromium.org/11342036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164933 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/syncable')
-rw-r--r--webkit/fileapi/syncable/canned_syncable_file_system.cc1
-rw-r--r--webkit/fileapi/syncable/local_file_sync_context.cc13
-rw-r--r--webkit/fileapi/syncable/local_file_sync_context.h8
-rw-r--r--webkit/fileapi/syncable/syncable_file_system_util_unittest.cc52
4 files changed, 62 insertions, 12 deletions
diff --git a/webkit/fileapi/syncable/canned_syncable_file_system.cc b/webkit/fileapi/syncable/canned_syncable_file_system.cc
index 374a1f9..427e612 100644
--- a/webkit/fileapi/syncable/canned_syncable_file_system.cc
+++ b/webkit/fileapi/syncable/canned_syncable_file_system.cc
@@ -209,6 +209,7 @@ SyncStatusCode CannedSyncableFileSystem::MaybeInitializeFileSystemContext(
VerifySameTaskRunner(io_task_runner_, sync_context->io_task_runner_);
sync_context->MaybeInitializeFileSystemContext(
test_helper_.origin(),
+ service_name_,
file_system_context_,
base::Bind(&CannedSyncableFileSystem::DidInitializeFileSystemContext,
base::Unretained(this)));
diff --git a/webkit/fileapi/syncable/local_file_sync_context.cc b/webkit/fileapi/syncable/local_file_sync_context.cc
index 1445bf5..9355997 100644
--- a/webkit/fileapi/syncable/local_file_sync_context.cc
+++ b/webkit/fileapi/syncable/local_file_sync_context.cc
@@ -37,6 +37,7 @@ LocalFileSyncContext::LocalFileSyncContext(
void LocalFileSyncContext::MaybeInitializeFileSystemContext(
const GURL& source_url,
+ const std::string& service_name,
FileSystemContext* file_system_context,
const StatusCallback& callback) {
DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
@@ -56,7 +57,8 @@ void LocalFileSyncContext::MaybeInitializeFileSystemContext(
io_task_runner_->PostTask(
FROM_HERE,
base::Bind(&LocalFileSyncContext::InitializeFileSystemContextOnIOThread,
- this, source_url, make_scoped_refptr(file_system_context)));
+ this, source_url, service_name,
+ make_scoped_refptr(file_system_context)));
}
void LocalFileSyncContext::ShutdownOnUIThread() {
@@ -202,10 +204,13 @@ void LocalFileSyncContext::ShutdownOnIOThread() {
void LocalFileSyncContext::InitializeFileSystemContextOnIOThread(
const GURL& source_url,
+ const std::string& service_name,
FileSystemContext* file_system_context) {
DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
DCHECK(file_system_context);
if (!file_system_context->change_tracker()) {
+ // First registers the service name.
+ RegisterSyncableFileSystem(service_name);
// Create and initialize LocalFileChangeTracker and call back this method
// later again.
scoped_ptr<LocalFileChangeTracker>* tracker_ptr(
@@ -218,7 +223,7 @@ void LocalFileSyncContext::InitializeFileSystemContextOnIOThread(
make_scoped_refptr(file_system_context)),
base::Bind(&LocalFileSyncContext::DidInitializeChangeTracker, this,
base::Owned(tracker_ptr),
- source_url,
+ source_url, service_name,
make_scoped_refptr(file_system_context)));
return;
}
@@ -248,6 +253,7 @@ SyncStatusCode LocalFileSyncContext::InitializeChangeTrackerOnFileThread(
void LocalFileSyncContext::DidInitializeChangeTracker(
scoped_ptr<LocalFileChangeTracker>* tracker_ptr,
const GURL& source_url,
+ const std::string& service_name,
FileSystemContext* file_system_context,
SyncStatusCode status) {
DCHECK(file_system_context);
@@ -256,7 +262,8 @@ void LocalFileSyncContext::DidInitializeChangeTracker(
return;
}
file_system_context->SetLocalFileChangeTracker(tracker_ptr->Pass());
- InitializeFileSystemContextOnIOThread(source_url, file_system_context);
+ InitializeFileSystemContextOnIOThread(source_url, service_name,
+ file_system_context);
}
void LocalFileSyncContext::DidInitialize(
diff --git a/webkit/fileapi/syncable/local_file_sync_context.h b/webkit/fileapi/syncable/local_file_sync_context.h
index e6d1447..ef7eacef 100644
--- a/webkit/fileapi/syncable/local_file_sync_context.h
+++ b/webkit/fileapi/syncable/local_file_sync_context.h
@@ -8,6 +8,7 @@
#include <deque>
#include <map>
#include <set>
+#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
@@ -51,11 +52,12 @@ class WEBKIT_STORAGE_EXPORT LocalFileSyncContext
LocalFileSyncContext(base::SingleThreadTaskRunner* ui_task_runner,
base::SingleThreadTaskRunner* io_task_runner);
- // Initializes |file_system_context| for syncable file operations and
- // registers the it into the internal map.
+ // Initializes |file_system_context| for syncable file operations for
+ // |service_name| and registers the it into the internal map.
// Calling this multiple times for the same file_system_context is valid.
// This method must be called on UI thread.
void MaybeInitializeFileSystemContext(const GURL& source_url,
+ const std::string& service_name,
FileSystemContext* file_system_context,
const StatusCallback& callback);
@@ -117,6 +119,7 @@ class WEBKIT_STORAGE_EXPORT LocalFileSyncContext
// Helper routines for MaybeInitializeFileSystemContext.
void InitializeFileSystemContextOnIOThread(
const GURL& source_url,
+ const std::string& service_name,
FileSystemContext* file_system_context);
SyncStatusCode InitializeChangeTrackerOnFileThread(
scoped_ptr<LocalFileChangeTracker>* tracker_ptr,
@@ -124,6 +127,7 @@ class WEBKIT_STORAGE_EXPORT LocalFileSyncContext
void DidInitializeChangeTracker(
scoped_ptr<LocalFileChangeTracker>* tracker_ptr,
const GURL& source_url,
+ const std::string& service_name,
FileSystemContext* file_system_context,
SyncStatusCode status);
void DidInitialize(
diff --git a/webkit/fileapi/syncable/syncable_file_system_util_unittest.cc b/webkit/fileapi/syncable/syncable_file_system_util_unittest.cc
index a17a639..f6a909c 100644
--- a/webkit/fileapi/syncable/syncable_file_system_util_unittest.cc
+++ b/webkit/fileapi/syncable/syncable_file_system_util_unittest.cc
@@ -5,8 +5,12 @@
#include "webkit/fileapi/syncable/syncable_file_system_util.h"
#include "base/logging.h"
+#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/fileapi/isolated_context.h"
+#include "webkit/fileapi/syncable/canned_syncable_file_system.h"
+#include "webkit/fileapi/syncable/local_file_sync_context.h"
namespace fileapi {
@@ -33,15 +37,13 @@ FilePath CreateNormalizedFilePath(const FilePath::CharType* path) {
} // namespace
-class SyncableFileSystemUtilTest : public testing::Test {};
-
-TEST_F(SyncableFileSystemUtilTest, GetSyncableFileSystemRootURI) {
+TEST(SyncableFileSystemUtilTest, GetSyncableFileSystemRootURI) {
const GURL root = GetSyncableFileSystemRootURI(GURL(kOrigin), kServiceName);
EXPECT_TRUE(root.is_valid());
EXPECT_EQ(GURL(kSyncableFileSystemRootURI), root);
}
-TEST_F(SyncableFileSystemUtilTest, CreateSyncableFileSystemURL) {
+TEST(SyncableFileSystemUtilTest, CreateSyncableFileSystemURL) {
ScopedExternalFileSystem scoped_fs(
kServiceName, kFileSystemTypeSyncable, FilePath());
@@ -55,7 +57,7 @@ TEST_F(SyncableFileSystemUtilTest, CreateSyncableFileSystemURL) {
EXPECT_EQ(expected_url, url);
}
-TEST_F(SyncableFileSystemUtilTest,
+TEST(SyncableFileSystemUtilTest,
SerializeAndDesirializeSyncableFileSystemURL) {
ScopedExternalFileSystem scoped_fs(
kServiceName, kFileSystemTypeSyncable, FilePath());
@@ -76,8 +78,8 @@ TEST_F(SyncableFileSystemUtilTest,
EXPECT_EQ(expected_url, deserialized);
}
-TEST_F(SyncableFileSystemUtilTest,
- FailInSerializingAndDeserializingSyncableFileSystemURL) {
+TEST(SyncableFileSystemUtilTest,
+ FailInSerializingAndDeserializingSyncableFileSystemURL) {
ScopedExternalFileSystem scoped_fs(
kServiceName, kFileSystemTypeSyncable, FilePath());
@@ -104,4 +106,40 @@ TEST_F(SyncableFileSystemUtilTest,
non_syncable_url, &deserialized));
}
+TEST(SyncableFileSystemUtilTest, SerializeBeforeOpenFileSystem) {
+ const std::string serialized = kSyncableFileSystemRootURI +
+ CreateNormalizedFilePath(kPath).AsUTF8Unsafe();
+ FileSystemURL deserialized;
+ MessageLoop message_loop;
+
+ // Setting up a full syncable filesystem environment.
+ CannedSyncableFileSystem file_system(GURL(kOrigin), kServiceName,
+ base::MessageLoopProxy::current(),
+ base::MessageLoopProxy::current());
+ file_system.SetUp();
+ scoped_refptr<LocalFileSyncContext> sync_context =
+ new LocalFileSyncContext(base::MessageLoopProxy::current(),
+ base::MessageLoopProxy::current());
+
+ // Before calling initialization we would not be able to get a valid
+ // deserialized URL.
+ EXPECT_FALSE(DeserializeSyncableFileSystemURL(serialized, &deserialized));
+ EXPECT_FALSE(deserialized.is_valid());
+
+ ASSERT_EQ(SYNC_STATUS_OK,
+ file_system.MaybeInitializeFileSystemContext(sync_context));
+
+ // After initialization this should be ok (even before opening the file
+ // system).
+ EXPECT_TRUE(DeserializeSyncableFileSystemURL(serialized, &deserialized));
+ EXPECT_TRUE(deserialized.is_valid());
+
+ // Shutting down.
+ file_system.TearDown();
+ RevokeSyncableFileSystem(kServiceName);
+ sync_context->ShutdownOnUIThread();
+ sync_context = NULL;
+ MessageLoop::current()->RunAllPending();
+}
+
} // namespace fileapi