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

Side by Side Diff: webkit/fileapi/file_system_url_request_job.cc

Issue 9380040: Revert 121620 - Refactor FileSystemOperation to take callback for each method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 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/fileapi/file_system_url_request_job.h" 5 #include "webkit/fileapi/file_system_url_request_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util_proxy.h" 10 #include "base/file_util_proxy.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/platform_file.h" 12 #include "base/platform_file.h"
13 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "net/base/file_stream.h" 16 #include "net/base/file_stream.h"
17 #include "net/base/io_buffer.h" 17 #include "net/base/io_buffer.h"
18 #include "net/base/mime_util.h" 18 #include "net/base/mime_util.h"
19 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
20 #include "net/base/net_util.h" 20 #include "net/base/net_util.h"
21 #include "net/http/http_response_headers.h" 21 #include "net/http/http_response_headers.h"
22 #include "net/http/http_response_info.h" 22 #include "net/http/http_response_info.h"
23 #include "net/http/http_util.h" 23 #include "net/http/http_util.h"
24 #include "net/url_request/url_request.h" 24 #include "net/url_request/url_request.h"
25 #include "webkit/fileapi/file_system_callback_dispatcher.h"
25 #include "webkit/fileapi/file_system_context.h" 26 #include "webkit/fileapi/file_system_context.h"
26 #include "webkit/fileapi/file_system_operation.h" 27 #include "webkit/fileapi/file_system_operation.h"
27 #include "webkit/fileapi/file_system_util.h" 28 #include "webkit/fileapi/file_system_util.h"
28 29
29 using net::URLRequest; 30 using net::URLRequest;
30 using net::URLRequestJob; 31 using net::URLRequestJob;
31 using net::URLRequestStatus; 32 using net::URLRequestStatus;
32 33
33 namespace fileapi { 34 namespace fileapi {
34 35
(...skipping 10 matching lines...) Expand all
45 new net::HttpResponseHeaders(std::string(kStatus, kStatusLen)); 46 new net::HttpResponseHeaders(std::string(kStatus, kStatusLen));
46 47
47 // Tell WebKit never to cache this content. 48 // Tell WebKit never to cache this content.
48 std::string cache_control(net::HttpRequestHeaders::kCacheControl); 49 std::string cache_control(net::HttpRequestHeaders::kCacheControl);
49 cache_control.append(": no-cache"); 50 cache_control.append(": no-cache");
50 headers->AddHeader(cache_control); 51 headers->AddHeader(cache_control);
51 52
52 return headers; 53 return headers;
53 } 54 }
54 55
56 class FileSystemURLRequestJob::CallbackDispatcher
57 : public FileSystemCallbackDispatcher {
58 public:
59 // An instance of this class must be created by Create()
60 // (so that we do not leak ownerships).
61 static scoped_ptr<FileSystemCallbackDispatcher> Create(
62 FileSystemURLRequestJob* job) {
63 return scoped_ptr<FileSystemCallbackDispatcher>(
64 new CallbackDispatcher(job));
65 }
66
67 // fileapi::FileSystemCallbackDispatcher overrides.
68 virtual void DidSucceed() OVERRIDE {
69 NOTREACHED();
70 }
71
72 virtual void DidReadMetadata(const base::PlatformFileInfo& file_info,
73 const FilePath& platform_path) OVERRIDE {
74 job_->DidGetMetadata(file_info, platform_path);
75 }
76
77 virtual void DidReadDirectory(
78 const std::vector<base::FileUtilProxy::Entry>& entries,
79 bool has_more) OVERRIDE {
80 NOTREACHED();
81 }
82
83 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE {
84 NOTREACHED();
85 }
86
87 virtual void DidOpenFileSystem(const std::string& name,
88 const GURL& root_path) OVERRIDE {
89 NOTREACHED();
90 }
91
92 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE {
93 int rv = net::ERR_FILE_NOT_FOUND;
94 if (error_code == base::PLATFORM_FILE_ERROR_INVALID_URL)
95 rv = net::ERR_INVALID_URL;
96 job_->NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
97 }
98
99 private:
100 explicit CallbackDispatcher(FileSystemURLRequestJob* job) : job_(job) {
101 DCHECK(job_);
102 }
103
104 // TODO(adamk): Get rid of the need for refcounting here by
105 // allowing FileSystemOperations to be cancelled.
106 scoped_refptr<FileSystemURLRequestJob> job_;
107 DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher);
108 };
109
55 FileSystemURLRequestJob::FileSystemURLRequestJob( 110 FileSystemURLRequestJob::FileSystemURLRequestJob(
56 URLRequest* request, FileSystemContext* file_system_context, 111 URLRequest* request, FileSystemContext* file_system_context,
57 scoped_refptr<base::MessageLoopProxy> file_thread_proxy) 112 scoped_refptr<base::MessageLoopProxy> file_thread_proxy)
58 : URLRequestJob(request), 113 : URLRequestJob(request),
59 file_system_context_(file_system_context), 114 file_system_context_(file_system_context),
60 file_thread_proxy_(file_thread_proxy), 115 file_thread_proxy_(file_thread_proxy),
61 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 116 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
62 stream_(NULL), 117 stream_(NULL),
63 is_directory_(false), 118 is_directory_(false),
64 remaining_bytes_(0) { 119 remaining_bytes_(0) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 return 200; 223 return 200;
169 return URLRequestJob::GetResponseCode(); 224 return URLRequestJob::GetResponseCode();
170 } 225 }
171 226
172 void FileSystemURLRequestJob::StartAsync() { 227 void FileSystemURLRequestJob::StartAsync() {
173 if (!request_) 228 if (!request_)
174 return; 229 return;
175 FileSystemOperationInterface* operation = 230 FileSystemOperationInterface* operation =
176 file_system_context_->CreateFileSystemOperation( 231 file_system_context_->CreateFileSystemOperation(
177 request_->url(), 232 request_->url(),
233 CallbackDispatcher::Create(this),
178 file_thread_proxy_); 234 file_thread_proxy_);
179 if (!operation) { 235 if (!operation) {
180 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 236 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
181 net::ERR_INVALID_URL)); 237 net::ERR_INVALID_URL));
182 return; 238 return;
183 } 239 }
184 operation->GetMetadata( 240 operation->GetMetadata(request_->url());
185 request_->url(),
186 base::Bind(&FileSystemURLRequestJob::DidGetMetadata, this));
187 } 241 }
188 242
189 void FileSystemURLRequestJob::DidGetMetadata( 243 void FileSystemURLRequestJob::DidGetMetadata(
190 base::PlatformFileError error_code,
191 const base::PlatformFileInfo& file_info, 244 const base::PlatformFileInfo& file_info,
192 const FilePath& platform_path) { 245 const FilePath& platform_path) {
193 if (error_code != base::PLATFORM_FILE_OK) {
194 NotifyFailed(error_code == base::PLATFORM_FILE_ERROR_INVALID_URL ?
195 net::ERR_INVALID_URL : net::ERR_FILE_NOT_FOUND);
196 return;
197 }
198
199 // We may have been orphaned... 246 // We may have been orphaned...
200 if (!request_) 247 if (!request_)
201 return; 248 return;
202 249
203 is_directory_ = file_info.is_directory; 250 is_directory_ = file_info.is_directory;
204 251
205 if (!byte_range_.ComputeBounds(file_info.size)) { 252 if (!byte_range_.ComputeBounds(file_info.size)) {
206 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); 253 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
207 return; 254 return;
208 } 255 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 326 }
280 327
281 return false; 328 return false;
282 } 329 }
283 330
284 void FileSystemURLRequestJob::NotifyFailed(int rv) { 331 void FileSystemURLRequestJob::NotifyFailed(int rv) {
285 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); 332 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
286 } 333 }
287 334
288 } // namespace fileapi 335 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_url_request_job.h ('k') | webkit/fileapi/file_writer_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698