OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/sync_file_system/local/sync_file_system_backend.h" | 5 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" | 9 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" |
10 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" | 10 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" |
11 #include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h
" | 11 #include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h
" |
12 #include "chrome/browser/sync_file_system/sync_file_system_service.h" | 12 #include "chrome/browser/sync_file_system/sync_file_system_service.h" |
13 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h" | 13 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h" |
14 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 14 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
17 #include "webkit/browser/blob/file_stream_reader.h" | 17 #include "storage/browser/blob/file_stream_reader.h" |
18 #include "webkit/browser/fileapi/file_stream_writer.h" | 18 #include "storage/browser/fileapi/file_stream_writer.h" |
19 #include "webkit/browser/fileapi/file_system_context.h" | 19 #include "storage/browser/fileapi/file_system_context.h" |
20 #include "webkit/browser/fileapi/file_system_operation.h" | 20 #include "storage/browser/fileapi/file_system_operation.h" |
21 #include "webkit/common/fileapi/file_system_util.h" | 21 #include "storage/common/fileapi/file_system_util.h" |
22 | 22 |
23 using content::BrowserThread; | 23 using content::BrowserThread; |
24 | 24 |
25 namespace sync_file_system { | 25 namespace sync_file_system { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 bool CalledOnUIThread() { | 29 bool CalledOnUIThread() { |
30 // Ensure that these methods are called on the UI thread, except for unittests | 30 // Ensure that these methods are called on the UI thread, except for unittests |
31 // where a UI thread might not have been created. | 31 // where a UI thread might not have been created. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 84 } |
85 | 85 |
86 // static | 86 // static |
87 SyncFileSystemBackend* SyncFileSystemBackend::CreateForTesting() { | 87 SyncFileSystemBackend* SyncFileSystemBackend::CreateForTesting() { |
88 DCHECK(CalledOnUIThread()); | 88 DCHECK(CalledOnUIThread()); |
89 SyncFileSystemBackend* backend = new SyncFileSystemBackend(NULL); | 89 SyncFileSystemBackend* backend = new SyncFileSystemBackend(NULL); |
90 backend->skip_initialize_syncfs_service_for_testing_ = true; | 90 backend->skip_initialize_syncfs_service_for_testing_ = true; |
91 return backend; | 91 return backend; |
92 } | 92 } |
93 | 93 |
94 bool SyncFileSystemBackend::CanHandleType( | 94 bool SyncFileSystemBackend::CanHandleType(storage::FileSystemType type) const { |
95 fileapi::FileSystemType type) const { | 95 return type == storage::kFileSystemTypeSyncable || |
96 return type == fileapi::kFileSystemTypeSyncable || | 96 type == storage::kFileSystemTypeSyncableForInternalSync; |
97 type == fileapi::kFileSystemTypeSyncableForInternalSync; | |
98 } | 97 } |
99 | 98 |
100 void SyncFileSystemBackend::Initialize(fileapi::FileSystemContext* context) { | 99 void SyncFileSystemBackend::Initialize(storage::FileSystemContext* context) { |
101 DCHECK(context); | 100 DCHECK(context); |
102 DCHECK(!context_); | 101 DCHECK(!context_); |
103 context_ = context; | 102 context_ = context; |
104 | 103 |
105 fileapi::SandboxFileSystemBackendDelegate* delegate = GetDelegate(); | 104 storage::SandboxFileSystemBackendDelegate* delegate = GetDelegate(); |
106 delegate->RegisterQuotaUpdateObserver(fileapi::kFileSystemTypeSyncable); | 105 delegate->RegisterQuotaUpdateObserver(storage::kFileSystemTypeSyncable); |
107 delegate->RegisterQuotaUpdateObserver( | 106 delegate->RegisterQuotaUpdateObserver( |
108 fileapi::kFileSystemTypeSyncableForInternalSync); | 107 storage::kFileSystemTypeSyncableForInternalSync); |
109 } | 108 } |
110 | 109 |
111 void SyncFileSystemBackend::ResolveURL(const fileapi::FileSystemURL& url, | 110 void SyncFileSystemBackend::ResolveURL(const storage::FileSystemURL& url, |
112 fileapi::OpenFileSystemMode mode, | 111 storage::OpenFileSystemMode mode, |
113 const OpenFileSystemCallback& callback) { | 112 const OpenFileSystemCallback& callback) { |
114 DCHECK(CanHandleType(url.type())); | 113 DCHECK(CanHandleType(url.type())); |
115 | 114 |
116 if (skip_initialize_syncfs_service_for_testing_) { | 115 if (skip_initialize_syncfs_service_for_testing_) { |
117 GetDelegate()->OpenFileSystem(url.origin(), | 116 GetDelegate()->OpenFileSystem(url.origin(), |
118 url.type(), | 117 url.type(), |
119 mode, | 118 mode, |
120 callback, | 119 callback, |
121 GetSyncableFileSystemRootURI(url.origin())); | 120 GetSyncableFileSystemRootURI(url.origin())); |
122 return; | 121 return; |
123 } | 122 } |
124 | 123 |
125 // It is safe to pass Unretained(this) since |context_| owns it. | 124 // It is safe to pass Unretained(this) since |context_| owns it. |
126 SyncStatusCallback initialize_callback = | 125 SyncStatusCallback initialize_callback = |
127 base::Bind(&SyncFileSystemBackend::DidInitializeSyncFileSystemService, | 126 base::Bind(&SyncFileSystemBackend::DidInitializeSyncFileSystemService, |
128 base::Unretained(this), | 127 base::Unretained(this), |
129 make_scoped_refptr(context_), | 128 make_scoped_refptr(context_), |
130 url.origin(), | 129 url.origin(), |
131 url.type(), | 130 url.type(), |
132 mode, | 131 mode, |
133 callback); | 132 callback); |
134 InitializeSyncFileSystemService(url.origin(), initialize_callback); | 133 InitializeSyncFileSystemService(url.origin(), initialize_callback); |
135 } | 134 } |
136 | 135 |
137 fileapi::AsyncFileUtil* SyncFileSystemBackend::GetAsyncFileUtil( | 136 storage::AsyncFileUtil* SyncFileSystemBackend::GetAsyncFileUtil( |
138 fileapi::FileSystemType type) { | 137 storage::FileSystemType type) { |
139 return GetDelegate()->file_util(); | 138 return GetDelegate()->file_util(); |
140 } | 139 } |
141 | 140 |
142 fileapi::CopyOrMoveFileValidatorFactory* | 141 storage::CopyOrMoveFileValidatorFactory* |
143 SyncFileSystemBackend::GetCopyOrMoveFileValidatorFactory( | 142 SyncFileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
144 fileapi::FileSystemType type, | 143 storage::FileSystemType type, |
145 base::File::Error* error_code) { | 144 base::File::Error* error_code) { |
146 DCHECK(error_code); | 145 DCHECK(error_code); |
147 *error_code = base::File::FILE_OK; | 146 *error_code = base::File::FILE_OK; |
148 return NULL; | 147 return NULL; |
149 } | 148 } |
150 | 149 |
151 fileapi::FileSystemOperation* | 150 storage::FileSystemOperation* SyncFileSystemBackend::CreateFileSystemOperation( |
152 SyncFileSystemBackend::CreateFileSystemOperation( | 151 const storage::FileSystemURL& url, |
153 const fileapi::FileSystemURL& url, | 152 storage::FileSystemContext* context, |
154 fileapi::FileSystemContext* context, | |
155 base::File::Error* error_code) const { | 153 base::File::Error* error_code) const { |
156 DCHECK(CanHandleType(url.type())); | 154 DCHECK(CanHandleType(url.type())); |
157 DCHECK(context); | 155 DCHECK(context); |
158 DCHECK(error_code); | 156 DCHECK(error_code); |
159 | 157 |
160 scoped_ptr<fileapi::FileSystemOperationContext> operation_context = | 158 scoped_ptr<storage::FileSystemOperationContext> operation_context = |
161 GetDelegate()->CreateFileSystemOperationContext(url, context, error_code); | 159 GetDelegate()->CreateFileSystemOperationContext(url, context, error_code); |
162 if (!operation_context) | 160 if (!operation_context) |
163 return NULL; | 161 return NULL; |
164 | 162 |
165 if (url.type() == fileapi::kFileSystemTypeSyncableForInternalSync) { | 163 if (url.type() == storage::kFileSystemTypeSyncableForInternalSync) { |
166 return fileapi::FileSystemOperation::Create( | 164 return storage::FileSystemOperation::Create( |
167 url, context, operation_context.Pass()); | 165 url, context, operation_context.Pass()); |
168 } | 166 } |
169 | 167 |
170 return new SyncableFileSystemOperation( | 168 return new SyncableFileSystemOperation( |
171 url, context, operation_context.Pass()); | 169 url, context, operation_context.Pass()); |
172 } | 170 } |
173 | 171 |
174 bool SyncFileSystemBackend::SupportsStreaming( | 172 bool SyncFileSystemBackend::SupportsStreaming( |
175 const fileapi::FileSystemURL& url) const { | 173 const storage::FileSystemURL& url) const { |
176 return false; | 174 return false; |
177 } | 175 } |
178 | 176 |
179 scoped_ptr<webkit_blob::FileStreamReader> | 177 scoped_ptr<storage::FileStreamReader> |
180 SyncFileSystemBackend::CreateFileStreamReader( | 178 SyncFileSystemBackend::CreateFileStreamReader( |
181 const fileapi::FileSystemURL& url, | 179 const storage::FileSystemURL& url, |
182 int64 offset, | 180 int64 offset, |
183 const base::Time& expected_modification_time, | 181 const base::Time& expected_modification_time, |
184 fileapi::FileSystemContext* context) const { | 182 storage::FileSystemContext* context) const { |
185 DCHECK(CanHandleType(url.type())); | 183 DCHECK(CanHandleType(url.type())); |
186 return GetDelegate()->CreateFileStreamReader( | 184 return GetDelegate()->CreateFileStreamReader( |
187 url, offset, expected_modification_time, context); | 185 url, offset, expected_modification_time, context); |
188 } | 186 } |
189 | 187 |
190 scoped_ptr<fileapi::FileStreamWriter> | 188 scoped_ptr<storage::FileStreamWriter> |
191 SyncFileSystemBackend::CreateFileStreamWriter( | 189 SyncFileSystemBackend::CreateFileStreamWriter( |
192 const fileapi::FileSystemURL& url, | 190 const storage::FileSystemURL& url, |
193 int64 offset, | 191 int64 offset, |
194 fileapi::FileSystemContext* context) const { | 192 storage::FileSystemContext* context) const { |
195 DCHECK(CanHandleType(url.type())); | 193 DCHECK(CanHandleType(url.type())); |
196 return GetDelegate()->CreateFileStreamWriter( | 194 return GetDelegate()->CreateFileStreamWriter( |
197 url, offset, context, fileapi::kFileSystemTypeSyncableForInternalSync); | 195 url, offset, context, storage::kFileSystemTypeSyncableForInternalSync); |
198 } | 196 } |
199 | 197 |
200 fileapi::FileSystemQuotaUtil* SyncFileSystemBackend::GetQuotaUtil() { | 198 storage::FileSystemQuotaUtil* SyncFileSystemBackend::GetQuotaUtil() { |
201 return GetDelegate(); | 199 return GetDelegate(); |
202 } | 200 } |
203 | 201 |
204 // static | 202 // static |
205 SyncFileSystemBackend* SyncFileSystemBackend::GetBackend( | 203 SyncFileSystemBackend* SyncFileSystemBackend::GetBackend( |
206 const fileapi::FileSystemContext* file_system_context) { | 204 const storage::FileSystemContext* file_system_context) { |
207 DCHECK(file_system_context); | 205 DCHECK(file_system_context); |
208 return static_cast<SyncFileSystemBackend*>( | 206 return static_cast<SyncFileSystemBackend*>( |
209 file_system_context->GetFileSystemBackend( | 207 file_system_context->GetFileSystemBackend( |
210 fileapi::kFileSystemTypeSyncable)); | 208 storage::kFileSystemTypeSyncable)); |
211 } | 209 } |
212 | 210 |
213 void SyncFileSystemBackend::SetLocalFileChangeTracker( | 211 void SyncFileSystemBackend::SetLocalFileChangeTracker( |
214 scoped_ptr<LocalFileChangeTracker> tracker) { | 212 scoped_ptr<LocalFileChangeTracker> tracker) { |
215 DCHECK(!change_tracker_); | 213 DCHECK(!change_tracker_); |
216 DCHECK(tracker); | 214 DCHECK(tracker); |
217 change_tracker_ = tracker.Pass(); | 215 change_tracker_ = tracker.Pass(); |
218 | 216 |
219 fileapi::SandboxFileSystemBackendDelegate* delegate = GetDelegate(); | 217 storage::SandboxFileSystemBackendDelegate* delegate = GetDelegate(); |
220 delegate->AddFileUpdateObserver( | 218 delegate->AddFileUpdateObserver(storage::kFileSystemTypeSyncable, |
221 fileapi::kFileSystemTypeSyncable, | 219 change_tracker_.get(), |
222 change_tracker_.get(), | 220 delegate->file_task_runner()); |
223 delegate->file_task_runner()); | 221 delegate->AddFileChangeObserver(storage::kFileSystemTypeSyncable, |
224 delegate->AddFileChangeObserver( | 222 change_tracker_.get(), |
225 fileapi::kFileSystemTypeSyncable, | 223 delegate->file_task_runner()); |
226 change_tracker_.get(), | |
227 delegate->file_task_runner()); | |
228 } | 224 } |
229 | 225 |
230 void SyncFileSystemBackend::set_sync_context( | 226 void SyncFileSystemBackend::set_sync_context( |
231 LocalFileSyncContext* sync_context) { | 227 LocalFileSyncContext* sync_context) { |
232 DCHECK(!sync_context_); | 228 DCHECK(!sync_context_); |
233 sync_context_ = sync_context; | 229 sync_context_ = sync_context; |
234 } | 230 } |
235 | 231 |
236 fileapi::SandboxFileSystemBackendDelegate* | 232 storage::SandboxFileSystemBackendDelegate* SyncFileSystemBackend::GetDelegate() |
237 SyncFileSystemBackend::GetDelegate() const { | 233 const { |
238 DCHECK(context_); | 234 DCHECK(context_); |
239 DCHECK(context_->sandbox_delegate()); | 235 DCHECK(context_->sandbox_delegate()); |
240 return context_->sandbox_delegate(); | 236 return context_->sandbox_delegate(); |
241 } | 237 } |
242 | 238 |
243 void SyncFileSystemBackend::InitializeSyncFileSystemService( | 239 void SyncFileSystemBackend::InitializeSyncFileSystemService( |
244 const GURL& origin_url, | 240 const GURL& origin_url, |
245 const SyncStatusCallback& callback) { | 241 const SyncStatusCallback& callback) { |
246 // Repost to switch from IO thread to UI thread. | 242 // Repost to switch from IO thread to UI thread. |
247 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 243 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
(...skipping 12 matching lines...) Expand all Loading... |
260 return; | 256 return; |
261 } | 257 } |
262 | 258 |
263 SyncFileSystemService* service = SyncFileSystemServiceFactory::GetForProfile( | 259 SyncFileSystemService* service = SyncFileSystemServiceFactory::GetForProfile( |
264 profile_holder_->GetProfile()); | 260 profile_holder_->GetProfile()); |
265 DCHECK(service); | 261 DCHECK(service); |
266 service->InitializeForApp(context_, origin_url, callback); | 262 service->InitializeForApp(context_, origin_url, callback); |
267 } | 263 } |
268 | 264 |
269 void SyncFileSystemBackend::DidInitializeSyncFileSystemService( | 265 void SyncFileSystemBackend::DidInitializeSyncFileSystemService( |
270 fileapi::FileSystemContext* context, | 266 storage::FileSystemContext* context, |
271 const GURL& origin_url, | 267 const GURL& origin_url, |
272 fileapi::FileSystemType type, | 268 storage::FileSystemType type, |
273 fileapi::OpenFileSystemMode mode, | 269 storage::OpenFileSystemMode mode, |
274 const OpenFileSystemCallback& callback, | 270 const OpenFileSystemCallback& callback, |
275 SyncStatusCode status) { | 271 SyncStatusCode status) { |
276 // Repost to switch from UI thread to IO thread. | 272 // Repost to switch from UI thread to IO thread. |
277 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 273 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
279 // It is safe to pass Unretained(this) since |context| owns it. | 275 // It is safe to pass Unretained(this) since |context| owns it. |
280 BrowserThread::PostTask( | 276 BrowserThread::PostTask( |
281 BrowserThread::IO, FROM_HERE, | 277 BrowserThread::IO, FROM_HERE, |
282 base::Bind(&SyncFileSystemBackend::DidInitializeSyncFileSystemService, | 278 base::Bind(&SyncFileSystemBackend::DidInitializeSyncFileSystemService, |
283 base::Unretained(this), make_scoped_refptr(context), | 279 base::Unretained(this), make_scoped_refptr(context), |
284 origin_url, type, mode, callback, status)); | 280 origin_url, type, mode, callback, status)); |
285 return; | 281 return; |
286 } | 282 } |
287 | 283 |
288 if (status != sync_file_system::SYNC_STATUS_OK) { | 284 if (status != sync_file_system::SYNC_STATUS_OK) { |
289 callback.Run(GURL(), std::string(), | 285 callback.Run(GURL(), std::string(), |
290 SyncStatusCodeToFileError(status)); | 286 SyncStatusCodeToFileError(status)); |
291 return; | 287 return; |
292 } | 288 } |
293 | 289 |
294 callback.Run(GetSyncableFileSystemRootURI(origin_url), | 290 callback.Run(GetSyncableFileSystemRootURI(origin_url), |
295 GetFileSystemName(origin_url, type), | 291 GetFileSystemName(origin_url, type), |
296 base::File::FILE_OK); | 292 base::File::FILE_OK); |
297 } | 293 } |
298 | 294 |
299 } // namespace sync_file_system | 295 } // namespace sync_file_system |
OLD | NEW |