Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: webkit/fileapi/syncable/canned_syncable_file_system.cc

Issue 11090019: Add LocalFileSyncContext class which wires up profile-owned service and FileSystemContext(s) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments #4 Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/fileapi/syncable/canned_syncable_file_system.h" 5 #include "webkit/fileapi/syncable/canned_syncable_file_system.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "webkit/fileapi/file_system_context.h" 11 #include "webkit/fileapi/file_system_context.h"
12 #include "webkit/fileapi/file_system_operation_context.h" 12 #include "webkit/fileapi/file_system_operation_context.h"
13 #include "webkit/fileapi/file_system_task_runners.h" 13 #include "webkit/fileapi/file_system_task_runners.h"
14 #include "webkit/fileapi/file_system_util.h" 14 #include "webkit/fileapi/file_system_util.h"
15 #include "webkit/fileapi/isolated_context.h" 15 #include "webkit/fileapi/isolated_context.h"
16 #include "webkit/fileapi/local_file_system_operation.h" 16 #include "webkit/fileapi/local_file_system_operation.h"
17 #include "webkit/fileapi/mock_file_system_options.h" 17 #include "webkit/fileapi/mock_file_system_options.h"
18 #include "webkit/fileapi/syncable/local_file_sync_context.h"
18 #include "webkit/quota/mock_special_storage_policy.h" 19 #include "webkit/quota/mock_special_storage_policy.h"
19 #include "webkit/quota/quota_manager.h" 20 #include "webkit/quota/quota_manager.h"
20 21
21 using base::PlatformFileError; 22 using base::PlatformFileError;
22 using quota::QuotaManager; 23 using quota::QuotaManager;
23 24
24 namespace fileapi { 25 namespace fileapi {
25 26
26 CannedSyncableFileSystem::CannedSyncableFileSystem( 27 CannedSyncableFileSystem::CannedSyncableFileSystem(
27 const GURL& origin, const std::string& service) 28 const GURL& origin, const std::string& service)
28 : service_name_(service), 29 : service_name_(service),
29 test_helper_(origin, kFileSystemTypeSyncable), 30 test_helper_(origin, kFileSystemTypeSyncable),
30 result_(base::PLATFORM_FILE_OK), 31 result_(base::PLATFORM_FILE_OK),
31 sync_status_(SYNC_STATUS_OK), 32 sync_status_(SYNC_STATUS_OK),
33 is_filesystem_set_up_(false),
34 is_filesystem_opened_(false),
32 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 35 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
33 } 36 }
34 37
35 CannedSyncableFileSystem::~CannedSyncableFileSystem() {} 38 CannedSyncableFileSystem::~CannedSyncableFileSystem() {}
36 39
37 void CannedSyncableFileSystem::SetUp() { 40 void CannedSyncableFileSystem::SetUp() {
41 ASSERT_FALSE(is_filesystem_set_up_);
38 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 42 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
39 43
40 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = 44 scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
41 new quota::MockSpecialStoragePolicy(); 45 new quota::MockSpecialStoragePolicy();
42 46
43 quota_manager_ = new QuotaManager( 47 quota_manager_ = new QuotaManager(
44 false /* is_incognito */, 48 false /* is_incognito */,
45 data_dir_.path(), 49 data_dir_.path(),
46 base::MessageLoopProxy::current(), 50 base::MessageLoopProxy::current(),
47 base::MessageLoopProxy::current(), 51 base::MessageLoopProxy::current(),
48 storage_policy); 52 storage_policy);
49 53
50 file_system_context_ = new FileSystemContext( 54 file_system_context_ = new FileSystemContext(
51 FileSystemTaskRunners::CreateMockTaskRunners(), 55 FileSystemTaskRunners::CreateMockTaskRunners(),
52 storage_policy, 56 storage_policy,
53 quota_manager_->proxy(), 57 quota_manager_->proxy(),
54 data_dir_.path(), 58 data_dir_.path(),
55 CreateAllowFileAccessOptions()); 59 CreateAllowFileAccessOptions());
56 60
57 test_helper_.SetUp(file_system_context_.get(), NULL); 61 test_helper_.SetUp(file_system_context_.get(), NULL);
62 is_filesystem_set_up_ = true;
58 } 63 }
59 64
60 void CannedSyncableFileSystem::TearDown() { 65 void CannedSyncableFileSystem::TearDown() {
61 quota_manager_ = NULL; 66 quota_manager_ = NULL;
62 test_helper_.TearDown(); 67 test_helper_.TearDown();
63 } 68 }
64 69
65 FileSystemURL CannedSyncableFileSystem::URL(const std::string& path) const { 70 FileSystemURL CannedSyncableFileSystem::URL(const std::string& path) const {
71 EXPECT_TRUE(is_filesystem_set_up_);
72 EXPECT_TRUE(is_filesystem_opened_);
66 return FileSystemURL(GURL(root_url_.spec() + path)); 73 return FileSystemURL(GURL(root_url_.spec() + path));
67 } 74 }
68 75
69 PlatformFileError CannedSyncableFileSystem::OpenFileSystem() { 76 PlatformFileError CannedSyncableFileSystem::OpenFileSystem() {
77 EXPECT_TRUE(is_filesystem_set_up_);
78 EXPECT_FALSE(is_filesystem_opened_);
70 file_system_context_->OpenSyncableFileSystem( 79 file_system_context_->OpenSyncableFileSystem(
71 service_name_, 80 service_name_,
72 test_helper_.origin(), test_helper_.type(), 81 test_helper_.origin(), test_helper_.type(),
73 true /* create */, 82 true /* create */,
74 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, 83 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem,
75 weak_factory_.GetWeakPtr())); 84 weak_factory_.GetWeakPtr()));
76 MessageLoop::current()->RunAllPending(); 85 MessageLoop::current()->RunAllPending();
77 return result_; 86 return result_;
78 } 87 }
79 88
89 SyncStatusCode CannedSyncableFileSystem::MaybeInitializeFileSystemContext(
90 LocalFileSyncContext* sync_context) {
91 DCHECK(sync_context);
92 sync_status_ = SYNC_STATUS_UNKNOWN;
93 sync_context->MaybeInitializeFileSystemContext(
94 test_helper_.origin(),
95 file_system_context_,
96 base::Bind(&CannedSyncableFileSystem::DidInitializeFileSystemContext,
97 base::Unretained(this)));
98 MessageLoop::current()->Run();
99 return sync_status_;
100 }
101
80 PlatformFileError CannedSyncableFileSystem::CreateDirectory( 102 PlatformFileError CannedSyncableFileSystem::CreateDirectory(
81 const FileSystemURL& url) { 103 const FileSystemURL& url) {
104 EXPECT_TRUE(is_filesystem_opened_);
82 result_ = base::PLATFORM_FILE_ERROR_FAILED; 105 result_ = base::PLATFORM_FILE_ERROR_FAILED;
83 test_helper_.NewOperation()->CreateDirectory( 106 test_helper_.NewOperation()->CreateDirectory(
84 url, false /* exclusive */, false /* recursive */, 107 url, false /* exclusive */, false /* recursive */,
85 base::Bind(&CannedSyncableFileSystem::StatusCallback, 108 base::Bind(&CannedSyncableFileSystem::StatusCallback,
86 weak_factory_.GetWeakPtr())); 109 weak_factory_.GetWeakPtr()));
87 MessageLoop::current()->RunAllPending(); 110 MessageLoop::current()->RunAllPending();
88 return result_; 111 return result_;
89 } 112 }
90 113
91 PlatformFileError CannedSyncableFileSystem::CreateFile( 114 PlatformFileError CannedSyncableFileSystem::CreateFile(
92 const FileSystemURL& url) { 115 const FileSystemURL& url) {
116 EXPECT_TRUE(is_filesystem_opened_);
93 result_ = base::PLATFORM_FILE_ERROR_FAILED; 117 result_ = base::PLATFORM_FILE_ERROR_FAILED;
94 test_helper_.NewOperation()->CreateFile( 118 test_helper_.NewOperation()->CreateFile(
95 url, false /* exclusive */, 119 url, false /* exclusive */,
96 base::Bind(&CannedSyncableFileSystem::StatusCallback, 120 base::Bind(&CannedSyncableFileSystem::StatusCallback,
97 weak_factory_.GetWeakPtr())); 121 weak_factory_.GetWeakPtr()));
98 MessageLoop::current()->RunAllPending(); 122 MessageLoop::current()->RunAllPending();
99 return result_; 123 return result_;
100 } 124 }
101 125
102 PlatformFileError CannedSyncableFileSystem::Copy( 126 PlatformFileError CannedSyncableFileSystem::Copy(
(...skipping 13 matching lines...) Expand all
116 test_helper_.NewOperation()->Move( 140 test_helper_.NewOperation()->Move(
117 src_url, dest_url, 141 src_url, dest_url,
118 base::Bind(&CannedSyncableFileSystem::StatusCallback, 142 base::Bind(&CannedSyncableFileSystem::StatusCallback,
119 weak_factory_.GetWeakPtr())); 143 weak_factory_.GetWeakPtr()));
120 MessageLoop::current()->RunAllPending(); 144 MessageLoop::current()->RunAllPending();
121 return result_; 145 return result_;
122 } 146 }
123 147
124 PlatformFileError CannedSyncableFileSystem::TruncateFile( 148 PlatformFileError CannedSyncableFileSystem::TruncateFile(
125 const FileSystemURL& url, int64 size) { 149 const FileSystemURL& url, int64 size) {
150 EXPECT_TRUE(is_filesystem_opened_);
126 result_ = base::PLATFORM_FILE_ERROR_FAILED; 151 result_ = base::PLATFORM_FILE_ERROR_FAILED;
127 test_helper_.NewOperation()->Truncate( 152 test_helper_.NewOperation()->Truncate(
128 url, size, 153 url, size,
129 base::Bind(&CannedSyncableFileSystem::StatusCallback, 154 base::Bind(&CannedSyncableFileSystem::StatusCallback,
130 weak_factory_.GetWeakPtr())); 155 weak_factory_.GetWeakPtr()));
131 MessageLoop::current()->RunAllPending(); 156 MessageLoop::current()->RunAllPending();
132 return result_; 157 return result_;
133 } 158 }
134 159
135 PlatformFileError CannedSyncableFileSystem::Remove( 160 PlatformFileError CannedSyncableFileSystem::Remove(
136 const FileSystemURL& url, bool recursive) { 161 const FileSystemURL& url, bool recursive) {
162 EXPECT_TRUE(is_filesystem_opened_);
137 result_ = base::PLATFORM_FILE_ERROR_FAILED; 163 result_ = base::PLATFORM_FILE_ERROR_FAILED;
138 test_helper_.NewOperation()->Remove( 164 test_helper_.NewOperation()->Remove(
139 url, recursive, 165 url, recursive,
140 base::Bind(&CannedSyncableFileSystem::StatusCallback, 166 base::Bind(&CannedSyncableFileSystem::StatusCallback,
141 weak_factory_.GetWeakPtr())); 167 weak_factory_.GetWeakPtr()));
142 MessageLoop::current()->RunAllPending(); 168 MessageLoop::current()->RunAllPending();
143 return result_; 169 return result_;
144 } 170 }
145 171
146 PlatformFileError CannedSyncableFileSystem::DeleteFileSystem() { 172 PlatformFileError CannedSyncableFileSystem::DeleteFileSystem() {
173 EXPECT_TRUE(is_filesystem_set_up_);
147 file_system_context_->DeleteFileSystem( 174 file_system_context_->DeleteFileSystem(
148 test_helper_.origin(), test_helper_.type(), 175 test_helper_.origin(), test_helper_.type(),
149 base::Bind(&CannedSyncableFileSystem::StatusCallback, 176 base::Bind(&CannedSyncableFileSystem::StatusCallback,
150 weak_factory_.GetWeakPtr())); 177 weak_factory_.GetWeakPtr()));
151 MessageLoop::current()->RunAllPending(); 178 MessageLoop::current()->RunAllPending();
152 return result_; 179 return result_;
153 } 180 }
154 181
155 void CannedSyncableFileSystem::DidOpenFileSystem( 182 void CannedSyncableFileSystem::DidOpenFileSystem(
156 PlatformFileError result, const std::string& name, const GURL& root) { 183 PlatformFileError result, const std::string& name, const GURL& root) {
157 result_ = result; 184 result_ = result;
158 root_url_ = root; 185 root_url_ = root;
186 is_filesystem_opened_ = true;
187 }
188
189 void CannedSyncableFileSystem::DidInitializeFileSystemContext(
190 SyncStatusCode status) {
191 sync_status_ = status;
192 MessageLoop::current()->Quit();
159 } 193 }
160 194
161 void CannedSyncableFileSystem::StatusCallback(PlatformFileError result) { 195 void CannedSyncableFileSystem::StatusCallback(PlatformFileError result) {
162 result_ = result; 196 result_ = result;
163 } 197 }
164 198
165 FileSystemOperationContext* CannedSyncableFileSystem::NewOperationContext() { 199 FileSystemOperationContext* CannedSyncableFileSystem::NewOperationContext() {
166 FileSystemOperationContext* context = test_helper_.NewOperationContext(); 200 FileSystemOperationContext* context = test_helper_.NewOperationContext();
167 context->set_allowed_bytes_growth(kint64max); 201 context->set_allowed_bytes_growth(kint64max);
168 return context; 202 return context;
169 } 203 }
170 204
171 } // namespace fileapi 205 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/syncable/canned_syncable_file_system.h ('k') | webkit/fileapi/syncable/local_file_sync_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698