| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util_proxy.h" | 12 #include "base/file_util_proxy.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
| 15 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
| 16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 20 #include "net/base/file_stream.h" | 20 #include "net/base/file_stream.h" |
| 21 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
| 22 #include "net/base/mime_util.h" | 22 #include "net/base/mime_util.h" |
| 23 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
| 25 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
| 26 #include "net/http/http_response_info.h" | 26 #include "net/http/http_response_info.h" |
| 27 #include "net/http/http_util.h" | 27 #include "net/http/http_util.h" |
| 28 #include "net/url_request/url_request.h" | 28 #include "net/url_request/url_request.h" |
| 29 #include "net/url_request/url_request_context.h" |
| 29 #include "webkit/blob/file_stream_reader.h" | 30 #include "webkit/blob/file_stream_reader.h" |
| 30 #include "webkit/fileapi/file_system_context.h" | 31 #include "webkit/fileapi/file_system_context.h" |
| 31 #include "webkit/fileapi/file_system_operation.h" | 32 #include "webkit/fileapi/file_system_operation.h" |
| 32 #include "webkit/fileapi/file_system_util.h" | 33 #include "webkit/fileapi/file_system_util.h" |
| 33 | 34 |
| 34 using net::URLRequest; | 35 using net::URLRequest; |
| 35 using net::URLRequestJob; | 36 using net::URLRequestJob; |
| 36 using net::URLRequestStatus; | 37 using net::URLRequestStatus; |
| 37 | 38 |
| 38 namespace fileapi { | 39 namespace fileapi { |
| 39 | 40 |
| 40 static net::HttpResponseHeaders* CreateHttpResponseHeaders() { | 41 static net::HttpResponseHeaders* CreateHttpResponseHeaders() { |
| 41 // HttpResponseHeaders expects its input string to be terminated by two NULs. | 42 // HttpResponseHeaders expects its input string to be terminated by two NULs. |
| 42 static const char kStatus[] = "HTTP/1.1 200 OK\0"; | 43 static const char kStatus[] = "HTTP/1.1 200 OK\0"; |
| 43 static const size_t kStatusLen = arraysize(kStatus); | 44 static const size_t kStatusLen = arraysize(kStatus); |
| 44 | 45 |
| 45 net::HttpResponseHeaders* headers = | 46 net::HttpResponseHeaders* headers = |
| 46 new net::HttpResponseHeaders(std::string(kStatus, kStatusLen)); | 47 new net::HttpResponseHeaders(std::string(kStatus, kStatusLen)); |
| 47 | 48 |
| 48 // Tell WebKit never to cache this content. | 49 // Tell WebKit never to cache this content. |
| 49 std::string cache_control(net::HttpRequestHeaders::kCacheControl); | 50 std::string cache_control(net::HttpRequestHeaders::kCacheControl); |
| 50 cache_control.append(": no-cache"); | 51 cache_control.append(": no-cache"); |
| 51 headers->AddHeader(cache_control); | 52 headers->AddHeader(cache_control); |
| 52 | 53 |
| 53 return headers; | 54 return headers; |
| 54 } | 55 } |
| 55 | 56 |
| 56 FileSystemURLRequestJob::FileSystemURLRequestJob( | 57 FileSystemURLRequestJob::FileSystemURLRequestJob( |
| 57 URLRequest* request, FileSystemContext* file_system_context) | 58 URLRequest* request, FileSystemContext* file_system_context) |
| 58 : URLRequestJob(request), | 59 : URLRequestJob(request, request->context()->network_delegate()), |
| 59 file_system_context_(file_system_context), | 60 file_system_context_(file_system_context), |
| 60 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 61 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 61 is_directory_(false), | 62 is_directory_(false), |
| 62 remaining_bytes_(0) { | 63 remaining_bytes_(0) { |
| 63 } | 64 } |
| 64 | 65 |
| 65 FileSystemURLRequestJob::~FileSystemURLRequestJob() {} | 66 FileSystemURLRequestJob::~FileSystemURLRequestJob() {} |
| 66 | 67 |
| 67 void FileSystemURLRequestJob::Start() { | 68 void FileSystemURLRequestJob::Start() { |
| 68 MessageLoop::current()->PostTask( | 69 MessageLoop::current()->PostTask( |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 241 } |
| 241 | 242 |
| 242 return false; | 243 return false; |
| 243 } | 244 } |
| 244 | 245 |
| 245 void FileSystemURLRequestJob::NotifyFailed(int rv) { | 246 void FileSystemURLRequestJob::NotifyFailed(int rv) { |
| 246 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 247 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 247 } | 248 } |
| 248 | 249 |
| 249 } // namespace fileapi | 250 } // namespace fileapi |
| OLD | NEW |