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_writer.h" | 5 #include "webkit/tools/test_shell/simple_file_writer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
11 #include "net/url_request/url_request_context.h" | 11 #include "net/url_request/url_request_context.h" |
| 12 #include "webkit/blob/blob_storage_context.h" |
12 #include "webkit/fileapi/file_system_context.h" | 13 #include "webkit/fileapi/file_system_context.h" |
13 #include "webkit/fileapi/file_system_operation.h" | 14 #include "webkit/fileapi/file_system_operation.h" |
14 #include "webkit/fileapi/file_system_types.h" | 15 #include "webkit/fileapi/file_system_types.h" |
15 #include "webkit/fileapi/file_system_url.h" | 16 #include "webkit/fileapi/file_system_url.h" |
16 #include "webkit/glue/webkit_glue.h" | 17 #include "webkit/glue/webkit_glue.h" |
17 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" | 18 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" |
18 | 19 |
19 using fileapi::FileSystemURL; | 20 using fileapi::FileSystemURL; |
20 using fileapi::FileSystemContext; | 21 using fileapi::FileSystemContext; |
21 using fileapi::FileSystemOperation; | 22 using fileapi::FileSystemOperation; |
22 using fileapi::WebFileWriterBase; | 23 using fileapi::WebFileWriterBase; |
23 using WebKit::WebFileWriterClient; | 24 using WebKit::WebFileWriterClient; |
24 using WebKit::WebString; | 25 using WebKit::WebString; |
25 using WebKit::WebURL; | 26 using WebKit::WebURL; |
26 | 27 |
27 net::URLRequestContext* SimpleFileWriter::request_context_ = NULL; | 28 net::URLRequestContext* SimpleFileWriter::request_context_; |
| 29 webkit_blob::BlobStorageContext* SimpleFileWriter::blob_storage_context_; |
28 | 30 |
29 // Helper class to proxy to write and truncate calls to the IO thread, | 31 // Helper class to proxy to write and truncate calls to the IO thread, |
30 // and to proxy the results back to the main thead. There is a one-to-one | 32 // and to proxy the results back to the main thead. There is a one-to-one |
31 // relationship between SimpleFileWriters and IOThreadBackends. | 33 // relationship between SimpleFileWriters and IOThreadBackends. |
32 class SimpleFileWriter::IOThreadProxy | 34 class SimpleFileWriter::IOThreadProxy |
33 : public base::RefCountedThreadSafe<SimpleFileWriter::IOThreadProxy> { | 35 : public base::RefCountedThreadSafe<SimpleFileWriter::IOThreadProxy> { |
34 public: | 36 public: |
35 IOThreadProxy(const base::WeakPtr<SimpleFileWriter>& simple_writer, | 37 IOThreadProxy(const base::WeakPtr<SimpleFileWriter>& simple_writer, |
36 FileSystemContext* file_system_context) | 38 FileSystemContext* file_system_context) |
37 : simple_writer_(simple_writer), | 39 : simple_writer_(simple_writer), |
(...skipping 13 matching lines...) Expand all Loading... |
51 return; | 53 return; |
52 } | 54 } |
53 if (FailIfNotWritable(url)) | 55 if (FailIfNotWritable(url)) |
54 return; | 56 return; |
55 DCHECK(!operation_); | 57 DCHECK(!operation_); |
56 operation_ = GetNewOperation(url); | 58 operation_ = GetNewOperation(url); |
57 operation_->Truncate(url, offset, | 59 operation_->Truncate(url, offset, |
58 base::Bind(&IOThreadProxy::DidFinish, this)); | 60 base::Bind(&IOThreadProxy::DidFinish, this)); |
59 } | 61 } |
60 | 62 |
61 void Write(const FileSystemURL& url, const GURL& blob_url, int64 offset) { | 63 void Write(const FileSystemURL& url, |
| 64 const std::string& blob_uuid, |
| 65 int64 offset) { |
62 if (!io_thread_->BelongsToCurrentThread()) { | 66 if (!io_thread_->BelongsToCurrentThread()) { |
63 io_thread_->PostTask( | 67 io_thread_->PostTask( |
64 FROM_HERE, | 68 FROM_HERE, |
65 base::Bind(&IOThreadProxy::Write, this, url, blob_url, offset)); | 69 base::Bind(&IOThreadProxy::Write, this, url, blob_uuid, offset)); |
66 return; | 70 return; |
67 } | 71 } |
68 if (FailIfNotWritable(url)) | 72 if (FailIfNotWritable(url)) |
69 return; | 73 return; |
70 DCHECK(request_context_); | 74 DCHECK(request_context_); |
71 DCHECK(!operation_); | 75 DCHECK(!operation_); |
72 operation_ = GetNewOperation(url); | 76 operation_ = GetNewOperation(url); |
73 operation_->Write(request_context_, url, blob_url, offset, | 77 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle = |
| 78 blob_storage_context_->GetBlobDataFromUUID(blob_uuid); |
| 79 operation_->Write(request_context_, url, blob_data_handle.Pass(), offset, |
74 base::Bind(&IOThreadProxy::DidWrite, this)); | 80 base::Bind(&IOThreadProxy::DidWrite, this)); |
75 } | 81 } |
76 | 82 |
77 void Cancel() { | 83 void Cancel() { |
78 if (!io_thread_->BelongsToCurrentThread()) { | 84 if (!io_thread_->BelongsToCurrentThread()) { |
79 io_thread_->PostTask( | 85 io_thread_->PostTask( |
80 FROM_HERE, | 86 FROM_HERE, |
81 base::Bind(&IOThreadProxy::Cancel, this)); | 87 base::Bind(&IOThreadProxy::Cancel, this)); |
82 return; | 88 return; |
83 } | 89 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 194 |
189 SimpleFileWriter::~SimpleFileWriter() { | 195 SimpleFileWriter::~SimpleFileWriter() { |
190 } | 196 } |
191 | 197 |
192 void SimpleFileWriter::DoTruncate(const GURL& path, int64 offset) { | 198 void SimpleFileWriter::DoTruncate(const GURL& path, int64 offset) { |
193 FileSystemURL url = file_system_context_->CrackURL(path); | 199 FileSystemURL url = file_system_context_->CrackURL(path); |
194 io_thread_proxy_->Truncate(url, offset); | 200 io_thread_proxy_->Truncate(url, offset); |
195 } | 201 } |
196 | 202 |
197 void SimpleFileWriter::DoWrite( | 203 void SimpleFileWriter::DoWrite( |
198 const GURL& path, const GURL& blob_url, int64 offset) { | 204 const GURL& path, const std::string& blob_uuid, int64 offset) { |
199 FileSystemURL url = file_system_context_->CrackURL(path); | 205 FileSystemURL url = file_system_context_->CrackURL(path); |
200 io_thread_proxy_->Write(url, blob_url, offset); | 206 io_thread_proxy_->Write(url, blob_uuid, offset); |
201 } | 207 } |
202 | 208 |
203 void SimpleFileWriter::DoCancel() { | 209 void SimpleFileWriter::DoCancel() { |
204 io_thread_proxy_->Cancel(); | 210 io_thread_proxy_->Cancel(); |
205 } | 211 } |
OLD | NEW |