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" |
(...skipping 73 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 bool SyncFileSystemBackend::HasInplaceCopyImplementation( | 177 bool SyncFileSystemBackend::HasInplaceCopyImplementation( |
180 fileapi::FileSystemType type) const { | 178 storage::FileSystemType type) const { |
181 return false; | 179 return false; |
182 } | 180 } |
183 | 181 |
184 scoped_ptr<webkit_blob::FileStreamReader> | 182 scoped_ptr<storage::FileStreamReader> |
185 SyncFileSystemBackend::CreateFileStreamReader( | 183 SyncFileSystemBackend::CreateFileStreamReader( |
186 const fileapi::FileSystemURL& url, | 184 const storage::FileSystemURL& url, |
187 int64 offset, | 185 int64 offset, |
188 const base::Time& expected_modification_time, | 186 const base::Time& expected_modification_time, |
189 fileapi::FileSystemContext* context) const { | 187 storage::FileSystemContext* context) const { |
190 DCHECK(CanHandleType(url.type())); | 188 DCHECK(CanHandleType(url.type())); |
191 return GetDelegate()->CreateFileStreamReader( | 189 return GetDelegate()->CreateFileStreamReader( |
192 url, offset, expected_modification_time, context); | 190 url, offset, expected_modification_time, context); |
193 } | 191 } |
194 | 192 |
195 scoped_ptr<fileapi::FileStreamWriter> | 193 scoped_ptr<storage::FileStreamWriter> |
196 SyncFileSystemBackend::CreateFileStreamWriter( | 194 SyncFileSystemBackend::CreateFileStreamWriter( |
197 const fileapi::FileSystemURL& url, | 195 const storage::FileSystemURL& url, |
198 int64 offset, | 196 int64 offset, |
199 fileapi::FileSystemContext* context) const { | 197 storage::FileSystemContext* context) const { |
200 DCHECK(CanHandleType(url.type())); | 198 DCHECK(CanHandleType(url.type())); |
201 return GetDelegate()->CreateFileStreamWriter( | 199 return GetDelegate()->CreateFileStreamWriter( |
202 url, offset, context, fileapi::kFileSystemTypeSyncableForInternalSync); | 200 url, offset, context, storage::kFileSystemTypeSyncableForInternalSync); |
203 } | 201 } |
204 | 202 |
205 fileapi::FileSystemQuotaUtil* SyncFileSystemBackend::GetQuotaUtil() { | 203 storage::FileSystemQuotaUtil* SyncFileSystemBackend::GetQuotaUtil() { |
206 return GetDelegate(); | 204 return GetDelegate(); |
207 } | 205 } |
208 | 206 |
209 // static | 207 // static |
210 SyncFileSystemBackend* SyncFileSystemBackend::GetBackend( | 208 SyncFileSystemBackend* SyncFileSystemBackend::GetBackend( |
211 const fileapi::FileSystemContext* file_system_context) { | 209 const storage::FileSystemContext* file_system_context) { |
212 DCHECK(file_system_context); | 210 DCHECK(file_system_context); |
213 return static_cast<SyncFileSystemBackend*>( | 211 return static_cast<SyncFileSystemBackend*>( |
214 file_system_context->GetFileSystemBackend( | 212 file_system_context->GetFileSystemBackend( |
215 fileapi::kFileSystemTypeSyncable)); | 213 storage::kFileSystemTypeSyncable)); |
216 } | 214 } |
217 | 215 |
218 void SyncFileSystemBackend::SetLocalFileChangeTracker( | 216 void SyncFileSystemBackend::SetLocalFileChangeTracker( |
219 scoped_ptr<LocalFileChangeTracker> tracker) { | 217 scoped_ptr<LocalFileChangeTracker> tracker) { |
220 DCHECK(!change_tracker_); | 218 DCHECK(!change_tracker_); |
221 DCHECK(tracker); | 219 DCHECK(tracker); |
222 change_tracker_ = tracker.Pass(); | 220 change_tracker_ = tracker.Pass(); |
223 | 221 |
224 fileapi::SandboxFileSystemBackendDelegate* delegate = GetDelegate(); | 222 storage::SandboxFileSystemBackendDelegate* delegate = GetDelegate(); |
225 delegate->AddFileUpdateObserver( | 223 delegate->AddFileUpdateObserver(storage::kFileSystemTypeSyncable, |
226 fileapi::kFileSystemTypeSyncable, | 224 change_tracker_.get(), |
227 change_tracker_.get(), | 225 delegate->file_task_runner()); |
228 delegate->file_task_runner()); | 226 delegate->AddFileChangeObserver(storage::kFileSystemTypeSyncable, |
229 delegate->AddFileChangeObserver( | 227 change_tracker_.get(), |
230 fileapi::kFileSystemTypeSyncable, | 228 delegate->file_task_runner()); |
231 change_tracker_.get(), | |
232 delegate->file_task_runner()); | |
233 } | 229 } |
234 | 230 |
235 void SyncFileSystemBackend::set_sync_context( | 231 void SyncFileSystemBackend::set_sync_context( |
236 LocalFileSyncContext* sync_context) { | 232 LocalFileSyncContext* sync_context) { |
237 DCHECK(!sync_context_); | 233 DCHECK(!sync_context_); |
238 sync_context_ = sync_context; | 234 sync_context_ = sync_context; |
239 } | 235 } |
240 | 236 |
241 fileapi::SandboxFileSystemBackendDelegate* | 237 storage::SandboxFileSystemBackendDelegate* SyncFileSystemBackend::GetDelegate() |
242 SyncFileSystemBackend::GetDelegate() const { | 238 const { |
243 DCHECK(context_); | 239 DCHECK(context_); |
244 DCHECK(context_->sandbox_delegate()); | 240 DCHECK(context_->sandbox_delegate()); |
245 return context_->sandbox_delegate(); | 241 return context_->sandbox_delegate(); |
246 } | 242 } |
247 | 243 |
248 void SyncFileSystemBackend::InitializeSyncFileSystemService( | 244 void SyncFileSystemBackend::InitializeSyncFileSystemService( |
249 const GURL& origin_url, | 245 const GURL& origin_url, |
250 const SyncStatusCallback& callback) { | 246 const SyncStatusCallback& callback) { |
251 // Repost to switch from IO thread to UI thread. | 247 // Repost to switch from IO thread to UI thread. |
252 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 248 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
(...skipping 12 matching lines...) Expand all Loading... |
265 return; | 261 return; |
266 } | 262 } |
267 | 263 |
268 SyncFileSystemService* service = SyncFileSystemServiceFactory::GetForProfile( | 264 SyncFileSystemService* service = SyncFileSystemServiceFactory::GetForProfile( |
269 profile_holder_->GetProfile()); | 265 profile_holder_->GetProfile()); |
270 DCHECK(service); | 266 DCHECK(service); |
271 service->InitializeForApp(context_, origin_url, callback); | 267 service->InitializeForApp(context_, origin_url, callback); |
272 } | 268 } |
273 | 269 |
274 void SyncFileSystemBackend::DidInitializeSyncFileSystemService( | 270 void SyncFileSystemBackend::DidInitializeSyncFileSystemService( |
275 fileapi::FileSystemContext* context, | 271 storage::FileSystemContext* context, |
276 const GURL& origin_url, | 272 const GURL& origin_url, |
277 fileapi::FileSystemType type, | 273 storage::FileSystemType type, |
278 fileapi::OpenFileSystemMode mode, | 274 storage::OpenFileSystemMode mode, |
279 const OpenFileSystemCallback& callback, | 275 const OpenFileSystemCallback& callback, |
280 SyncStatusCode status) { | 276 SyncStatusCode status) { |
281 // Repost to switch from UI thread to IO thread. | 277 // Repost to switch from UI thread to IO thread. |
282 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 278 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
284 // It is safe to pass Unretained(this) since |context| owns it. | 280 // It is safe to pass Unretained(this) since |context| owns it. |
285 BrowserThread::PostTask( | 281 BrowserThread::PostTask( |
286 BrowserThread::IO, FROM_HERE, | 282 BrowserThread::IO, FROM_HERE, |
287 base::Bind(&SyncFileSystemBackend::DidInitializeSyncFileSystemService, | 283 base::Bind(&SyncFileSystemBackend::DidInitializeSyncFileSystemService, |
288 base::Unretained(this), make_scoped_refptr(context), | 284 base::Unretained(this), make_scoped_refptr(context), |
289 origin_url, type, mode, callback, status)); | 285 origin_url, type, mode, callback, status)); |
290 return; | 286 return; |
291 } | 287 } |
292 | 288 |
293 if (status != sync_file_system::SYNC_STATUS_OK) { | 289 if (status != sync_file_system::SYNC_STATUS_OK) { |
294 callback.Run(GURL(), std::string(), | 290 callback.Run(GURL(), std::string(), |
295 SyncStatusCodeToFileError(status)); | 291 SyncStatusCodeToFileError(status)); |
296 return; | 292 return; |
297 } | 293 } |
298 | 294 |
299 callback.Run(GetSyncableFileSystemRootURI(origin_url), | 295 callback.Run(GetSyncableFileSystemRootURI(origin_url), |
300 GetFileSystemName(origin_url, type), | 296 GetFileSystemName(origin_url, type), |
301 base::File::FILE_OK); | 297 base::File::FILE_OK); |
302 } | 298 } |
303 | 299 |
304 } // namespace sync_file_system | 300 } // namespace sync_file_system |
OLD | NEW |