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

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

Issue 8999017: Add CreateFileSystemOperation() method to FileSystemContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased from patch 9016020 Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "net/url_request/url_request_context.h" 10 #include "net/url_request/url_request_context.h"
11 #include "webkit/fileapi/file_system_callback_dispatcher.h" 11 #include "webkit/fileapi/file_system_callback_dispatcher.h"
12 #include "webkit/fileapi/file_system_context.h" 12 #include "webkit/fileapi/file_system_context.h"
13 #include "webkit/fileapi/file_system_operation.h" 13 #include "webkit/fileapi/file_system_operation_interface.h"
14 #include "webkit/glue/webkit_glue.h" 14 #include "webkit/glue/webkit_glue.h"
15 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" 15 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
16 16
17 using fileapi::FileSystemCallbackDispatcher; 17 using fileapi::FileSystemCallbackDispatcher;
18 using fileapi::FileSystemContext; 18 using fileapi::FileSystemContext;
19 using fileapi::FileSystemOperation; 19 using fileapi::FileSystemOperationInterface;
20 using fileapi::WebFileWriterBase; 20 using fileapi::WebFileWriterBase;
21 using WebKit::WebFileWriterClient; 21 using WebKit::WebFileWriterClient;
22 using WebKit::WebString; 22 using WebKit::WebString;
23 using WebKit::WebURL; 23 using WebKit::WebURL;
24 24
25 net::URLRequestContext* SimpleFileWriter::request_context_ = NULL; 25 net::URLRequestContext* SimpleFileWriter::request_context_ = NULL;
26 26
27 // Helper class to proxy to write and truncate calls to the IO thread, 27 // Helper class to proxy to write and truncate calls to the IO thread,
28 // and to proxy the results back to the main thead. There is a one-to-one 28 // and to proxy the results back to the main thead. There is a one-to-one
29 // relationship between SimpleFileWriters and IOThreadBackends. 29 // relationship between SimpleFileWriters and IOThreadBackends.
(...skipping 15 matching lines...) Expand all
45 } 45 }
46 46
47 void Truncate(const GURL& path, int64 offset) { 47 void Truncate(const GURL& path, int64 offset) {
48 if (!io_thread_->BelongsToCurrentThread()) { 48 if (!io_thread_->BelongsToCurrentThread()) {
49 io_thread_->PostTask( 49 io_thread_->PostTask(
50 FROM_HERE, 50 FROM_HERE,
51 base::Bind(&IOThreadProxy::Truncate, this, path, offset)); 51 base::Bind(&IOThreadProxy::Truncate, this, path, offset));
52 return; 52 return;
53 } 53 }
54 DCHECK(!operation_); 54 DCHECK(!operation_);
55 operation_ = GetNewOperation(); 55 operation_ = GetNewOperation(path);
56 operation_->Truncate(path, offset); 56 operation_->Truncate(path, offset);
57 } 57 }
58 58
59 void Write(const GURL& path, const GURL& blob_url, int64 offset) { 59 void Write(const GURL& path, const GURL& blob_url, int64 offset) {
60 if (!io_thread_->BelongsToCurrentThread()) { 60 if (!io_thread_->BelongsToCurrentThread()) {
61 io_thread_->PostTask( 61 io_thread_->PostTask(
62 FROM_HERE, 62 FROM_HERE,
63 base::Bind(&IOThreadProxy::Write, this, path, blob_url, offset)); 63 base::Bind(&IOThreadProxy::Write, this, path, blob_url, offset));
64 return; 64 return;
65 } 65 }
66 DCHECK(request_context_); 66 DCHECK(request_context_);
67 DCHECK(!operation_); 67 DCHECK(!operation_);
68 operation_ = GetNewOperation(); 68 operation_ = GetNewOperation(path);
69 operation_->Write(request_context_, path, blob_url, offset); 69 operation_->Write(request_context_, path, blob_url, offset);
70 } 70 }
71 71
72 void Cancel() { 72 void Cancel() {
73 if (!io_thread_->BelongsToCurrentThread()) { 73 if (!io_thread_->BelongsToCurrentThread()) {
74 io_thread_->PostTask( 74 io_thread_->PostTask(
75 FROM_HERE, 75 FROM_HERE,
76 base::Bind(&IOThreadProxy::Cancel, this)); 76 base::Bind(&IOThreadProxy::Cancel, this));
77 return; 77 return;
78 } 78 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 virtual void DidOpenFileSystem( 121 virtual void DidOpenFileSystem(
122 const std::string& name, 122 const std::string& name,
123 const GURL& root) { 123 const GURL& root) {
124 NOTREACHED(); 124 NOTREACHED();
125 } 125 }
126 126
127 scoped_refptr<IOThreadProxy> proxy_; 127 scoped_refptr<IOThreadProxy> proxy_;
128 }; 128 };
129 129
130 FileSystemOperation* GetNewOperation() { 130 FileSystemOperationInterface* GetNewOperation(const GURL& path) {
131 // The FileSystemOperation takes ownership of the CallbackDispatcher. 131 // The FileSystemOperation takes ownership of the CallbackDispatcher.
132 return new FileSystemOperation(new CallbackDispatcher(this), 132 return file_system_context_->CreateFileSystemOperation(
133 io_thread_, file_system_context_.get()); 133 path, new CallbackDispatcher(this), io_thread_);
134 } 134 }
135 135
136 void DidSucceed() { 136 void DidSucceed() {
137 if (!main_thread_->BelongsToCurrentThread()) { 137 if (!main_thread_->BelongsToCurrentThread()) {
138 main_thread_->PostTask( 138 main_thread_->PostTask(
139 FROM_HERE, 139 FROM_HERE,
140 base::Bind(&IOThreadProxy::DidSucceed, this)); 140 base::Bind(&IOThreadProxy::DidSucceed, this));
141 return; 141 return;
142 } 142 }
143 if (simple_writer_) 143 if (simple_writer_)
(...skipping 27 matching lines...) Expand all
171 operation_ = NULL; 171 operation_ = NULL;
172 } 172 }
173 173
174 scoped_refptr<base::MessageLoopProxy> io_thread_; 174 scoped_refptr<base::MessageLoopProxy> io_thread_;
175 scoped_refptr<base::MessageLoopProxy> main_thread_; 175 scoped_refptr<base::MessageLoopProxy> main_thread_;
176 176
177 // Only used on the main thread. 177 // Only used on the main thread.
178 base::WeakPtr<SimpleFileWriter> simple_writer_; 178 base::WeakPtr<SimpleFileWriter> simple_writer_;
179 179
180 // Only used on the io thread. 180 // Only used on the io thread.
181 FileSystemOperation* operation_; 181 FileSystemOperationInterface* operation_;
182 182
183 scoped_refptr<FileSystemContext> file_system_context_; 183 scoped_refptr<FileSystemContext> file_system_context_;
184 }; 184 };
185 185
186 186
187 SimpleFileWriter::SimpleFileWriter( 187 SimpleFileWriter::SimpleFileWriter(
188 const GURL& path, 188 const GURL& path,
189 WebFileWriterClient* client, 189 WebFileWriterClient* client,
190 FileSystemContext* file_system_context) 190 FileSystemContext* file_system_context)
191 : WebFileWriterBase(path, client), 191 : WebFileWriterBase(path, client),
192 io_thread_proxy_(new IOThreadProxy(AsWeakPtr(), file_system_context)) { 192 io_thread_proxy_(new IOThreadProxy(AsWeakPtr(), file_system_context)) {
193 } 193 }
194 194
195 SimpleFileWriter::~SimpleFileWriter() { 195 SimpleFileWriter::~SimpleFileWriter() {
196 } 196 }
197 197
198 void SimpleFileWriter::DoTruncate(const GURL& path, int64 offset) { 198 void SimpleFileWriter::DoTruncate(const GURL& path, int64 offset) {
199 io_thread_proxy_->Truncate(path, offset); 199 io_thread_proxy_->Truncate(path, offset);
200 } 200 }
201 201
202 void SimpleFileWriter::DoWrite( 202 void SimpleFileWriter::DoWrite(
203 const GURL& path, const GURL& blob_url, int64 offset) { 203 const GURL& path, const GURL& blob_url, int64 offset) {
204 io_thread_proxy_->Write(path, blob_url, offset); 204 io_thread_proxy_->Write(path, blob_url, offset);
205 } 205 }
206 206
207 void SimpleFileWriter::DoCancel() { 207 void SimpleFileWriter::DoCancel() {
208 io_thread_proxy_->Cancel(); 208 io_thread_proxy_->Cancel();
209 } 209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698