| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // For loading files, we make use of overlapped i/o to ensure that reading from | 5 // For loading files, we make use of overlapped i/o to ensure that reading from |
| 6 // the filesystem (e.g., a network filesystem) does not block the calling | 6 // the filesystem (e.g., a network filesystem) does not block the calling |
| 7 // thread. An alternative approach would be to use a background thread or pool | 7 // thread. An alternative approach would be to use a background thread or pool |
| 8 // of threads, but it seems better to leverage the operating system's ability | 8 // of threads, but it seems better to leverage the operating system's ability |
| 9 // to do background file reads for us. | 9 // to do background file reads for us. |
| 10 // | 10 // |
| 11 // Since overlapped reads require a 'static' buffer for the duration of the | 11 // Since overlapped reads require a 'static' buffer for the duration of the |
| 12 // asynchronous read, the URLRequestFileJob keeps a buffer as a member var. In | 12 // asynchronous read, the URLRequestFileJob keeps a buffer as a member var. In |
| 13 // URLRequestFileJob::Read, data is simply copied from the object's buffer into | 13 // URLRequestFileJob::Read, data is simply copied from the object's buffer into |
| 14 // the given buffer. If there is no data to copy, the URLRequestFileJob | 14 // the given buffer. If there is no data to copy, the URLRequestFileJob |
| 15 // attempts to read more from the file to fill its buffer. If reading from the | 15 // attempts to read more from the file to fill its buffer. If reading from the |
| 16 // file does not complete synchronously, then the URLRequestFileJob waits for a | 16 // file does not complete synchronously, then the URLRequestFileJob waits for a |
| 17 // signal from the OS that the overlapped read has completed. It does so by | 17 // signal from the OS that the overlapped read has completed. It does so by |
| 18 // leveraging the MessageLoop::WatchObject API. | 18 // leveraging the MessageLoop::WatchObject API. |
| 19 | 19 |
| 20 #include "net/url_request/url_request_file_job.h" | 20 #include "net/url_request/url_request_file_job.h" |
| 21 | 21 |
| 22 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
| 23 #include "base/message_loop.h" | 23 #include "base/message_loop.h" |
| 24 #include "base/platform_file.h" | 24 #include "base/platform_file.h" |
| 25 #include "base/string_util.h" | 25 #include "base/string_util.h" |
| 26 #include "base/threading/worker_pool.h" |
| 26 #include "base/thread_restrictions.h" | 27 #include "base/thread_restrictions.h" |
| 27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 28 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| 29 #include "net/base/io_buffer.h" | 30 #include "net/base/io_buffer.h" |
| 30 #include "net/base/load_flags.h" | 31 #include "net/base/load_flags.h" |
| 31 #include "net/base/mime_util.h" | 32 #include "net/base/mime_util.h" |
| 32 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
| 33 #include "net/base/net_util.h" | 34 #include "net/base/net_util.h" |
| 34 #include "net/http/http_util.h" | 35 #include "net/http/http_util.h" |
| 35 #include "net/url_request/url_request.h" | 36 #include "net/url_request/url_request.h" |
| 36 #include "net/url_request/url_request_error_job.h" | 37 #include "net/url_request/url_request_error_job.h" |
| 37 #include "net/url_request/url_request_file_dir_job.h" | 38 #include "net/url_request/url_request_file_dir_job.h" |
| 38 | 39 |
| 39 #if defined(OS_WIN) | |
| 40 #include "base/worker_pool.h" | |
| 41 #endif | |
| 42 | |
| 43 namespace net { | 40 namespace net { |
| 44 | 41 |
| 45 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 46 class URLRequestFileJob::AsyncResolver | 43 class URLRequestFileJob::AsyncResolver |
| 47 : public base::RefCountedThreadSafe<URLRequestFileJob::AsyncResolver> { | 44 : public base::RefCountedThreadSafe<URLRequestFileJob::AsyncResolver> { |
| 48 public: | 45 public: |
| 49 explicit AsyncResolver(URLRequestFileJob* owner) | 46 explicit AsyncResolver(URLRequestFileJob* owner) |
| 50 : owner_(owner), owner_loop_(MessageLoop::current()) { | 47 : owner_(owner), owner_loop_(MessageLoop::current()) { |
| 51 } | 48 } |
| 52 | 49 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 DCHECK(!async_resolver_); | 126 DCHECK(!async_resolver_); |
| 130 #endif | 127 #endif |
| 131 } | 128 } |
| 132 | 129 |
| 133 void URLRequestFileJob::Start() { | 130 void URLRequestFileJob::Start() { |
| 134 #if defined(OS_WIN) | 131 #if defined(OS_WIN) |
| 135 // Resolve UNC paths on a background thread. | 132 // Resolve UNC paths on a background thread. |
| 136 if (!file_path_.value().compare(0, 2, L"\\\\")) { | 133 if (!file_path_.value().compare(0, 2, L"\\\\")) { |
| 137 DCHECK(!async_resolver_); | 134 DCHECK(!async_resolver_); |
| 138 async_resolver_ = new AsyncResolver(this); | 135 async_resolver_ = new AsyncResolver(this); |
| 139 WorkerPool::PostTask(FROM_HERE, NewRunnableMethod( | 136 base::WorkerPool::PostTask(FROM_HERE, NewRunnableMethod( |
| 140 async_resolver_.get(), &AsyncResolver::Resolve, file_path_), true); | 137 async_resolver_.get(), &AsyncResolver::Resolve, file_path_), true); |
| 141 return; | 138 return; |
| 142 } | 139 } |
| 143 #endif | 140 #endif |
| 144 | 141 |
| 145 // URL requests should not block on the disk! | 142 // URL requests should not block on the disk! |
| 146 // http://code.google.com/p/chromium/issues/detail?id=59849 | 143 // http://code.google.com/p/chromium/issues/detail?id=59849 |
| 147 bool exists; | 144 bool exists; |
| 148 base::PlatformFileInfo file_info; | 145 base::PlatformFileInfo file_info; |
| 149 { | 146 { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 if (white_listed_path == file_path.StripTrailingSeparators() || | 381 if (white_listed_path == file_path.StripTrailingSeparators() || |
| 385 white_listed_path.IsParent(file_path)) { | 382 white_listed_path.IsParent(file_path)) { |
| 386 return false; | 383 return false; |
| 387 } | 384 } |
| 388 } | 385 } |
| 389 return true; | 386 return true; |
| 390 } | 387 } |
| 391 #endif | 388 #endif |
| 392 | 389 |
| 393 } // namespace net | 390 } // namespace net |
| OLD | NEW |