OLD | NEW |
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/tools/test_shell/simple_file_system.h" | 5 #include "webkit/tools/test_shell/simple_file_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } else { | 84 } else { |
85 LOG(WARNING) << "Failed to create a temp dir for the filesystem." | 85 LOG(WARNING) << "Failed to create a temp dir for the filesystem." |
86 "FileSystem feature will be disabled."; | 86 "FileSystem feature will be disabled."; |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 SimpleFileSystem::~SimpleFileSystem() { | 90 SimpleFileSystem::~SimpleFileSystem() { |
91 } | 91 } |
92 | 92 |
93 void SimpleFileSystem::OpenFileSystem( | 93 void SimpleFileSystem::OpenFileSystem( |
94 WebFrame* frame, WebFileSystem::Type web_filesystem_type, | 94 WebFrame* frame, WebFileSystem::Type type, |
95 long long, bool create, | 95 long long, bool create, |
96 WebFileSystemCallbacks* callbacks) { | 96 WebFileSystemCallbacks* callbacks) { |
97 if (!frame || !file_system_context_.get()) { | 97 if (!frame || !file_system_context_.get()) { |
98 // The FileSystem temp directory was not initialized successfully. | 98 // The FileSystem temp directory was not initialized successfully. |
99 callbacks->didFail(WebKit::WebFileErrorSecurity); | 99 callbacks->didFail(WebKit::WebFileErrorSecurity); |
100 return; | 100 return; |
101 } | 101 } |
102 | 102 |
103 fileapi::FileSystemType type; | 103 GURL origin_url(frame->document().securityOrigin().toString()); |
104 if (web_filesystem_type == WebFileSystem::TypeTemporary) | 104 file_system_context_->OpenFileSystem( |
105 type = fileapi::kFileSystemTypeTemporary; | 105 origin_url, static_cast<fileapi::FileSystemType>(type), create, |
106 else if (web_filesystem_type == WebFileSystem::TypePersistent) | 106 OpenFileSystemHandler(callbacks)); |
107 type = fileapi::kFileSystemTypePersistent; | 107 } |
108 else if (web_filesystem_type == WebFileSystem::TypeExternal) | 108 |
109 type = fileapi::kFileSystemTypeExternal; | 109 void SimpleFileSystem::DeleteFileSystem( |
110 else { | 110 WebFrame* frame, WebFileSystem::Type type, |
111 // Unknown type filesystem is requested. | 111 WebFileSystemCallbacks* callbacks) { |
| 112 if (!frame || !file_system_context_.get()) { |
112 callbacks->didFail(WebKit::WebFileErrorSecurity); | 113 callbacks->didFail(WebKit::WebFileErrorSecurity); |
113 return; | 114 return; |
114 } | 115 } |
115 | 116 |
116 GURL origin_url(frame->document().securityOrigin().toString()); | 117 GURL origin_url(frame->document().securityOrigin().toString()); |
117 file_system_context_->OpenFileSystem( | 118 file_system_context_->DeleteFileSystem( |
118 origin_url, type, create, OpenFileSystemHandler(callbacks)); | 119 origin_url, static_cast<fileapi::FileSystemType>(type), |
| 120 DeleteFileSystemHandler(callbacks)); |
119 } | 121 } |
120 | 122 |
121 void SimpleFileSystem::move( | 123 void SimpleFileSystem::move( |
122 const WebURL& src_path, | 124 const WebURL& src_path, |
123 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { | 125 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { |
124 FileSystemURL src_url(src_path); | 126 FileSystemURL src_url(src_path); |
125 FileSystemURL dest_url(dest_path); | 127 FileSystemURL dest_url(dest_path); |
126 if (!HasFilePermission(src_url, FILE_PERMISSION_WRITE) || | 128 if (!HasFilePermission(src_url, FILE_PERMISSION_WRITE) || |
127 !HasFilePermission(dest_url, FILE_PERMISSION_CREATE)) { | 129 !HasFilePermission(dest_url, FILE_PERMISSION_CREATE)) { |
128 callbacks->didFail(WebKit::WebFileErrorSecurity); | 130 callbacks->didFail(WebKit::WebFileErrorSecurity); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 return base::Bind(&SimpleFileSystem::DidGetMetadata, | 291 return base::Bind(&SimpleFileSystem::DidGetMetadata, |
290 AsWeakPtr(), base::Unretained(callbacks)); | 292 AsWeakPtr(), base::Unretained(callbacks)); |
291 } | 293 } |
292 | 294 |
293 FileSystemContext::OpenFileSystemCallback | 295 FileSystemContext::OpenFileSystemCallback |
294 SimpleFileSystem::OpenFileSystemHandler(WebFileSystemCallbacks* callbacks) { | 296 SimpleFileSystem::OpenFileSystemHandler(WebFileSystemCallbacks* callbacks) { |
295 return base::Bind(&SimpleFileSystem::DidOpenFileSystem, | 297 return base::Bind(&SimpleFileSystem::DidOpenFileSystem, |
296 AsWeakPtr(), base::Unretained(callbacks)); | 298 AsWeakPtr(), base::Unretained(callbacks)); |
297 } | 299 } |
298 | 300 |
| 301 FileSystemContext::DeleteFileSystemCallback |
| 302 SimpleFileSystem::DeleteFileSystemHandler(WebFileSystemCallbacks* callbacks) { |
| 303 return base::Bind(&SimpleFileSystem::DidDeleteFileSystem, |
| 304 AsWeakPtr(), callbacks); |
| 305 } |
| 306 |
299 FileSystemOperationInterface::SnapshotFileCallback | 307 FileSystemOperationInterface::SnapshotFileCallback |
300 SimpleFileSystem::SnapshotFileHandler(const GURL& blob_url, | 308 SimpleFileSystem::SnapshotFileHandler(const GURL& blob_url, |
301 WebFileSystemCallbacks* callbacks) { | 309 WebFileSystemCallbacks* callbacks) { |
302 return base::Bind(&SimpleFileSystem::DidCreateSnapshotFile, | 310 return base::Bind(&SimpleFileSystem::DidCreateSnapshotFile, |
303 AsWeakPtr(), blob_url, base::Unretained(callbacks)); | 311 AsWeakPtr(), blob_url, base::Unretained(callbacks)); |
304 } | 312 } |
305 | 313 |
306 void SimpleFileSystem::DidFinish(WebFileSystemCallbacks* callbacks, | 314 void SimpleFileSystem::DidFinish(WebFileSystemCallbacks* callbacks, |
307 base::PlatformFileError result) { | 315 base::PlatformFileError result) { |
308 if (result == base::PLATFORM_FILE_OK) | 316 if (result == base::PLATFORM_FILE_OK) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 if (result == base::PLATFORM_FILE_OK) { | 365 if (result == base::PLATFORM_FILE_OK) { |
358 if (!root.is_valid()) | 366 if (!root.is_valid()) |
359 callbacks->didFail(WebKit::WebFileErrorSecurity); | 367 callbacks->didFail(WebKit::WebFileErrorSecurity); |
360 else | 368 else |
361 callbacks->didOpenFileSystem(WebString::fromUTF8(name), root); | 369 callbacks->didOpenFileSystem(WebString::fromUTF8(name), root); |
362 } else { | 370 } else { |
363 callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result)); | 371 callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result)); |
364 } | 372 } |
365 } | 373 } |
366 | 374 |
| 375 void SimpleFileSystem::DidDeleteFileSystem( |
| 376 WebFileSystemCallbacks* callbacks, |
| 377 base::PlatformFileError result) { |
| 378 if (result == base::PLATFORM_FILE_OK) |
| 379 callbacks->didSucceed(); |
| 380 else |
| 381 callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result)); |
| 382 } |
| 383 |
367 void SimpleFileSystem::DidCreateSnapshotFile( | 384 void SimpleFileSystem::DidCreateSnapshotFile( |
368 const GURL& blob_url, | 385 const GURL& blob_url, |
369 WebFileSystemCallbacks* callbacks, | 386 WebFileSystemCallbacks* callbacks, |
370 base::PlatformFileError result, | 387 base::PlatformFileError result, |
371 const base::PlatformFileInfo& info, | 388 const base::PlatformFileInfo& info, |
372 const FilePath& platform_path, | 389 const FilePath& platform_path, |
373 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 390 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
374 DCHECK(g_io_thread); | 391 DCHECK(g_io_thread); |
375 if (result == base::PLATFORM_FILE_OK) { | 392 if (result == base::PLATFORM_FILE_OK) { |
376 g_io_thread->PostTask( | 393 g_io_thread->PostTask( |
377 FROM_HERE, | 394 FROM_HERE, |
378 base::Bind(&RegisterBlob, blob_url, platform_path)); | 395 base::Bind(&RegisterBlob, blob_url, platform_path)); |
379 } | 396 } |
380 DidGetMetadata(callbacks, result, info, platform_path); | 397 DidGetMetadata(callbacks, result, info, platform_path); |
381 } | 398 } |
OLD | NEW |