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/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" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 #include "webkit/fileapi/file_system_util.h" | 28 #include "webkit/fileapi/file_system_util.h" |
29 | 29 |
30 using net::URLRequest; | 30 using net::URLRequest; |
31 using net::URLRequestJob; | 31 using net::URLRequestJob; |
32 using net::URLRequestStatus; | 32 using net::URLRequestStatus; |
33 | 33 |
34 namespace fileapi { | 34 namespace fileapi { |
35 | 35 |
36 static const int kFileFlags = base::PLATFORM_FILE_OPEN | | 36 static const int kFileFlags = base::PLATFORM_FILE_OPEN | |
37 base::PLATFORM_FILE_READ | | 37 base::PLATFORM_FILE_READ | |
38 base::PLATFORM_FILE_ASYNC; | 38 base::PLATFORM_FILE_ASYNC; |
satorux1
2012/02/07 18:06:27
async.
| |
39 | 39 |
40 static net::HttpResponseHeaders* CreateHttpResponseHeaders() { | 40 static net::HttpResponseHeaders* CreateHttpResponseHeaders() { |
41 // HttpResponseHeaders expects its input string to be terminated by two NULs. | 41 // HttpResponseHeaders expects its input string to be terminated by two NULs. |
42 static const char kStatus[] = "HTTP/1.1 200 OK\0"; | 42 static const char kStatus[] = "HTTP/1.1 200 OK\0"; |
43 static const size_t kStatusLen = arraysize(kStatus); | 43 static const size_t kStatusLen = arraysize(kStatus); |
44 | 44 |
45 net::HttpResponseHeaders* headers = | 45 net::HttpResponseHeaders* headers = |
46 new net::HttpResponseHeaders(std::string(kStatus, kStatusLen)); | 46 new net::HttpResponseHeaders(std::string(kStatus, kStatusLen)); |
47 | 47 |
48 // Tell WebKit never to cache this content. | 48 // Tell WebKit never to cache this content. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 116 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
117 stream_(NULL), | 117 stream_(NULL), |
118 is_directory_(false), | 118 is_directory_(false), |
119 remaining_bytes_(0) { | 119 remaining_bytes_(0) { |
120 } | 120 } |
121 | 121 |
122 FileSystemURLRequestJob::~FileSystemURLRequestJob() { | 122 FileSystemURLRequestJob::~FileSystemURLRequestJob() { |
123 // Since we use the two-arg constructor of FileStream, we need to call Close() | 123 // Since we use the two-arg constructor of FileStream, we need to call Close() |
124 // manually: ~FileStream won't call it for us. | 124 // manually: ~FileStream won't call it for us. |
125 if (stream_ != NULL) | 125 if (stream_ != NULL) |
126 stream_->Close(); | 126 stream_->CloseSync(); |
127 } | 127 } |
128 | 128 |
129 void FileSystemURLRequestJob::Start() { | 129 void FileSystemURLRequestJob::Start() { |
130 MessageLoop::current()->PostTask( | 130 MessageLoop::current()->PostTask( |
131 FROM_HERE, | 131 FROM_HERE, |
132 base::Bind(&FileSystemURLRequestJob::StartAsync, | 132 base::Bind(&FileSystemURLRequestJob::StartAsync, |
133 weak_factory_.GetWeakPtr())); | 133 weak_factory_.GetWeakPtr())); |
134 } | 134 } |
135 | 135 |
136 void FileSystemURLRequestJob::Kill() { | 136 void FileSystemURLRequestJob::Kill() { |
137 if (stream_ != NULL) { | 137 if (stream_ != NULL) { |
138 stream_->Close(); | 138 stream_->CloseSync(); |
139 stream_.reset(NULL); | 139 stream_.reset(NULL); |
140 } | 140 } |
141 URLRequestJob::Kill(); | 141 URLRequestJob::Kill(); |
142 weak_factory_.InvalidateWeakPtrs(); | 142 weak_factory_.InvalidateWeakPtrs(); |
143 } | 143 } |
144 | 144 |
145 bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, | 145 bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, |
146 int *bytes_read) { | 146 int *bytes_read) { |
147 DCHECK_NE(dest_size, 0); | 147 DCHECK_NE(dest_size, 0); |
148 DCHECK(bytes_read); | 148 DCHECK(bytes_read); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 } | 260 } |
261 | 261 |
262 void FileSystemURLRequestJob::DidOpen(base::PlatformFileError error_code, | 262 void FileSystemURLRequestJob::DidOpen(base::PlatformFileError error_code, |
263 base::PassPlatformFile file, | 263 base::PassPlatformFile file, |
264 bool created) { | 264 bool created) { |
265 if (error_code != base::PLATFORM_FILE_OK) { | 265 if (error_code != base::PLATFORM_FILE_OK) { |
266 NotifyFailed(error_code); | 266 NotifyFailed(error_code); |
267 return; | 267 return; |
268 } | 268 } |
269 | 269 |
270 stream_.reset(new net::FileStream(file.ReleaseValue(), kFileFlags, NULL)); | 270 stream_.reset(new net::FileStream(file.ReleaseValue(), kFileFlags, NULL)); |
satorux1
2012/02/07 18:06:27
async.
| |
271 | 271 |
272 remaining_bytes_ = byte_range_.last_byte_position() - | 272 remaining_bytes_ = byte_range_.last_byte_position() - |
273 byte_range_.first_byte_position() + 1; | 273 byte_range_.first_byte_position() + 1; |
274 DCHECK_GE(remaining_bytes_, 0); | 274 DCHECK_GE(remaining_bytes_, 0); |
275 | 275 |
276 // TODO(adamk): Please remove this ScopedAllowIO once we support async seek on | 276 // TODO(adamk): Please remove this ScopedAllowIO once we support async seek on |
277 // FileStream. | 277 // FileStream. |
278 base::ThreadRestrictions::ScopedAllowIO allow_io; | 278 base::ThreadRestrictions::ScopedAllowIO allow_io; |
279 // Do the seek at the beginning of the request. | 279 // Do the seek at the beginning of the request. |
280 if (remaining_bytes_ > 0 && | 280 if (remaining_bytes_ > 0 && |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 } | 321 } |
322 | 322 |
323 return false; | 323 return false; |
324 } | 324 } |
325 | 325 |
326 void FileSystemURLRequestJob::NotifyFailed(int rv) { | 326 void FileSystemURLRequestJob::NotifyFailed(int rv) { |
327 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 327 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
328 } | 328 } |
329 | 329 |
330 } // namespace fileapi | 330 } // namespace fileapi |
OLD | NEW |