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

Side by Side Diff: webkit/tools/test_shell/simple_file_system.cc

Issue 9557010: Fix SimpleFileSystem to register a Blob when performing the CreateSnapshotFile function. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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/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"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "net/base/mime_util.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback s.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback s.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemEntry.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemEntry.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
23 #include "webkit/blob/blob_storage_controller.h"
22 #include "webkit/fileapi/mock_file_system_options.h" 24 #include "webkit/fileapi/mock_file_system_options.h"
23 #include "webkit/glue/webkit_glue.h" 25 #include "webkit/glue/webkit_glue.h"
24 #include "webkit/tools/test_shell/simple_file_writer.h" 26 #include "webkit/tools/test_shell/simple_file_writer.h"
25 27
26 using base::WeakPtr; 28 using base::WeakPtr;
27 29
28 using WebKit::WebFileInfo; 30 using WebKit::WebFileInfo;
29 using WebKit::WebFileSystem; 31 using WebKit::WebFileSystem;
30 using WebKit::WebFileSystemCallbacks; 32 using WebKit::WebFileSystemCallbacks;
31 using WebKit::WebFileSystemEntry; 33 using WebKit::WebFileSystemEntry;
32 using WebKit::WebFileWriter; 34 using WebKit::WebFileWriter;
33 using WebKit::WebFileWriterClient; 35 using WebKit::WebFileWriterClient;
34 using WebKit::WebFrame; 36 using WebKit::WebFrame;
35 using WebKit::WebSecurityOrigin; 37 using WebKit::WebSecurityOrigin;
36 using WebKit::WebString; 38 using WebKit::WebString;
37 using WebKit::WebURL; 39 using WebKit::WebURL;
38 using WebKit::WebVector; 40 using WebKit::WebVector;
39 41
42 using webkit_blob::BlobData;
43 using webkit_blob::BlobStorageController;
40 using fileapi::FileSystemContext; 44 using fileapi::FileSystemContext;
41 using fileapi::FileSystemOperationInterface; 45 using fileapi::FileSystemOperationInterface;
42 46
47 namespace {
48 MessageLoop* g_io_thread;
49 webkit_blob::BlobStorageController* g_blob_storage_controller;
50
51 void RegisterBlob(const GURL& blob_url, const FilePath& file_path) {
52 DCHECK(g_blob_storage_controller);
53
54 FilePath::StringType extension = file_path.Extension();
55 if (!extension.empty())
56 extension = extension.substr(1); // Strip leading ".".
57
58 // This may fail, but then we'll be just setting the empty mime type.
59 std::string mime_type;
60 net::GetWellKnownMimeTypeFromExtension(extension, &mime_type);
61
62 BlobData::Item item;
63 item.SetToFile(file_path, 0, -1, base::Time());
64 g_blob_storage_controller->StartBuildingBlob(blob_url);
65 g_blob_storage_controller->AppendBlobDataItem(blob_url, item);
66 g_blob_storage_controller->FinishBuildingBlob(blob_url, mime_type);
67 }
68
69 } // namespace
70
43 SimpleFileSystem::SimpleFileSystem() { 71 SimpleFileSystem::SimpleFileSystem() {
44 if (file_system_dir_.CreateUniqueTempDir()) { 72 if (file_system_dir_.CreateUniqueTempDir()) {
45 file_system_context_ = new FileSystemContext( 73 file_system_context_ = new FileSystemContext(
46 base::MessageLoopProxy::current(), 74 base::MessageLoopProxy::current(),
47 base::MessageLoopProxy::current(), 75 base::MessageLoopProxy::current(),
48 NULL /* special storage policy */, 76 NULL /* special storage policy */,
49 NULL /* quota manager */, 77 NULL /* quota manager */,
50 file_system_dir_.path(), 78 file_system_dir_.path(),
51 fileapi::CreateAllowFileAccessOptions()); 79 fileapi::CreateAllowFileAccessOptions());
52 } else { 80 } else {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 173
146 WebFileWriter* SimpleFileSystem::createFileWriter( 174 WebFileWriter* SimpleFileSystem::createFileWriter(
147 const WebURL& path, WebFileWriterClient* client) { 175 const WebURL& path, WebFileWriterClient* client) {
148 return new SimpleFileWriter(path, client, file_system_context_.get()); 176 return new SimpleFileWriter(path, client, file_system_context_.get());
149 } 177 }
150 178
151 void SimpleFileSystem::createSnapshotFileAndReadMetadata( 179 void SimpleFileSystem::createSnapshotFileAndReadMetadata(
152 const WebURL& blobURL, 180 const WebURL& blobURL,
153 const WebURL& path, 181 const WebURL& path,
154 WebFileSystemCallbacks* callbacks) { 182 WebFileSystemCallbacks* callbacks) {
155 // TODO(michaeln): Register the blobURL with the blob storage contoller.
156 GetNewOperation(path)->CreateSnapshotFile( 183 GetNewOperation(path)->CreateSnapshotFile(
157 path, SnapshotFileHandler(callbacks)); 184 path, SnapshotFileHandler(blobURL, callbacks));
185 }
186
187 // static
188 void SimpleFileSystem::InitializeOnIOThread(
189 webkit_blob::BlobStorageController* blob_storage_controller) {
190 g_io_thread = MessageLoop::current();
191 g_blob_storage_controller = blob_storage_controller;
192 }
193
194 // static
195 void SimpleFileSystem::CleanupOnIOThread() {
196 g_io_thread = NULL;
197 g_blob_storage_controller = NULL;
158 } 198 }
159 199
160 FileSystemOperationInterface* SimpleFileSystem::GetNewOperation( 200 FileSystemOperationInterface* SimpleFileSystem::GetNewOperation(
161 const WebURL& url) { 201 const WebURL& url) {
162 return file_system_context_->CreateFileSystemOperation( 202 return file_system_context_->CreateFileSystemOperation(
163 GURL(url), 203 GURL(url),
164 base::MessageLoopProxy::current()); 204 base::MessageLoopProxy::current());
165 } 205 }
166 206
167 FileSystemOperationInterface::StatusCallback 207 FileSystemOperationInterface::StatusCallback
(...skipping 14 matching lines...) Expand all
182 AsWeakPtr(), base::Unretained(callbacks)); 222 AsWeakPtr(), base::Unretained(callbacks));
183 } 223 }
184 224
185 FileSystemContext::OpenFileSystemCallback 225 FileSystemContext::OpenFileSystemCallback
186 SimpleFileSystem::OpenFileSystemHandler(WebFileSystemCallbacks* callbacks) { 226 SimpleFileSystem::OpenFileSystemHandler(WebFileSystemCallbacks* callbacks) {
187 return base::Bind(&SimpleFileSystem::DidOpenFileSystem, 227 return base::Bind(&SimpleFileSystem::DidOpenFileSystem,
188 AsWeakPtr(), base::Unretained(callbacks)); 228 AsWeakPtr(), base::Unretained(callbacks));
189 } 229 }
190 230
191 FileSystemOperationInterface::SnapshotFileCallback 231 FileSystemOperationInterface::SnapshotFileCallback
192 SimpleFileSystem::SnapshotFileHandler(WebFileSystemCallbacks* callbacks) { 232 SimpleFileSystem::SnapshotFileHandler(const GURL& blob_url,
233 WebFileSystemCallbacks* callbacks) {
193 return base::Bind(&SimpleFileSystem::DidCreateSnapshotFile, 234 return base::Bind(&SimpleFileSystem::DidCreateSnapshotFile,
194 AsWeakPtr(), base::Unretained(callbacks)); 235 AsWeakPtr(), blob_url, base::Unretained(callbacks));
195 } 236 }
196 237
197 void SimpleFileSystem::DidFinish(WebFileSystemCallbacks* callbacks, 238 void SimpleFileSystem::DidFinish(WebFileSystemCallbacks* callbacks,
198 base::PlatformFileError result) { 239 base::PlatformFileError result) {
199 if (result == base::PLATFORM_FILE_OK) 240 if (result == base::PLATFORM_FILE_OK)
200 callbacks->didSucceed(); 241 callbacks->didSucceed();
201 else 242 else
202 callbacks->didFail(webkit_glue::PlatformFileErrorToWebFileError(result)); 243 callbacks->didFail(webkit_glue::PlatformFileErrorToWebFileError(result));
203 } 244 }
204 245
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 if (!root.is_valid()) 290 if (!root.is_valid())
250 callbacks->didFail(WebKit::WebFileErrorSecurity); 291 callbacks->didFail(WebKit::WebFileErrorSecurity);
251 else 292 else
252 callbacks->didOpenFileSystem(WebString::fromUTF8(name), root); 293 callbacks->didOpenFileSystem(WebString::fromUTF8(name), root);
253 } else { 294 } else {
254 callbacks->didFail(webkit_glue::PlatformFileErrorToWebFileError(result)); 295 callbacks->didFail(webkit_glue::PlatformFileErrorToWebFileError(result));
255 } 296 }
256 } 297 }
257 298
258 void SimpleFileSystem::DidCreateSnapshotFile( 299 void SimpleFileSystem::DidCreateSnapshotFile(
300 const GURL& blob_url,
259 WebFileSystemCallbacks* callbacks, 301 WebFileSystemCallbacks* callbacks,
260 base::PlatformFileError result, 302 base::PlatformFileError result,
261 const base::PlatformFileInfo& info, 303 const base::PlatformFileInfo& info,
262 const FilePath& platform_path, 304 const FilePath& platform_path,
263 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { 305 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
306
kinuko 2012/03/01 02:31:54 DCHECK(g_io_thread) maybe?
michaeln 2012/03/01 02:38:07 Done.
307 if (result == base::PLATFORM_FILE_OK && g_io_thread) {
308 g_io_thread->PostTask(
309 FROM_HERE,
310 base::Bind(&RegisterBlob, blob_url, platform_path));
311 }
312
264 DidGetMetadata(callbacks, result, info, platform_path); 313 DidGetMetadata(callbacks, result, info, platform_path);
265 } 314 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/simple_file_system.h ('k') | webkit/tools/test_shell/simple_resource_loader_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698