OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 // |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
42 class URLRequestFileJob::AsyncResolver : | 42 class URLRequestFileJob::AsyncResolver : |
43 public base::RefCountedThreadSafe<URLRequestFileJob::AsyncResolver> { | 43 public base::RefCountedThreadSafe<URLRequestFileJob::AsyncResolver> { |
44 public: | 44 public: |
45 explicit AsyncResolver(URLRequestFileJob* owner) | 45 explicit AsyncResolver(URLRequestFileJob* owner) |
46 : owner_(owner), owner_loop_(MessageLoop::current()) { | 46 : owner_(owner), owner_loop_(MessageLoop::current()) { |
47 } | 47 } |
48 | 48 |
49 void Resolve(const FilePath& file_path) { | 49 void Resolve(const FilePath& file_path) { |
50 file_util::FileInfo file_info; | 50 base::PlatformFileInfo file_info; |
51 bool exists = file_util::GetFileInfo(file_path, &file_info); | 51 bool exists = file_util::GetFileInfo(file_path, &file_info); |
52 AutoLock locked(lock_); | 52 AutoLock locked(lock_); |
53 if (owner_loop_) { | 53 if (owner_loop_) { |
54 owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 54 owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
55 this, &AsyncResolver::ReturnResults, exists, file_info)); | 55 this, &AsyncResolver::ReturnResults, exists, file_info)); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 void Cancel() { | 59 void Cancel() { |
60 owner_ = NULL; | 60 owner_ = NULL; |
61 | 61 |
62 AutoLock locked(lock_); | 62 AutoLock locked(lock_); |
63 owner_loop_ = NULL; | 63 owner_loop_ = NULL; |
64 } | 64 } |
65 | 65 |
66 private: | 66 private: |
67 friend class base::RefCountedThreadSafe<URLRequestFileJob::AsyncResolver>; | 67 friend class base::RefCountedThreadSafe<URLRequestFileJob::AsyncResolver>; |
68 | 68 |
69 ~AsyncResolver() {} | 69 ~AsyncResolver() {} |
70 | 70 |
71 void ReturnResults(bool exists, const file_util::FileInfo& file_info) { | 71 void ReturnResults(bool exists, const base::PlatformFileInfo& file_info) { |
72 if (owner_) | 72 if (owner_) |
73 owner_->DidResolve(exists, file_info); | 73 owner_->DidResolve(exists, file_info); |
74 } | 74 } |
75 | 75 |
76 URLRequestFileJob* owner_; | 76 URLRequestFileJob* owner_; |
77 | 77 |
78 Lock lock_; | 78 Lock lock_; |
79 MessageLoop* owner_loop_; | 79 MessageLoop* owner_loop_; |
80 }; | 80 }; |
81 #endif | 81 #endif |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 #if defined(OS_WIN) | 121 #if defined(OS_WIN) |
122 // Resolve UNC paths on a background thread. | 122 // Resolve UNC paths on a background thread. |
123 if (!file_path_.value().compare(0, 2, L"\\\\")) { | 123 if (!file_path_.value().compare(0, 2, L"\\\\")) { |
124 DCHECK(!async_resolver_); | 124 DCHECK(!async_resolver_); |
125 async_resolver_ = new AsyncResolver(this); | 125 async_resolver_ = new AsyncResolver(this); |
126 WorkerPool::PostTask(FROM_HERE, NewRunnableMethod( | 126 WorkerPool::PostTask(FROM_HERE, NewRunnableMethod( |
127 async_resolver_.get(), &AsyncResolver::Resolve, file_path_), true); | 127 async_resolver_.get(), &AsyncResolver::Resolve, file_path_), true); |
128 return; | 128 return; |
129 } | 129 } |
130 #endif | 130 #endif |
131 file_util::FileInfo file_info; | 131 base::PlatformFileInfo file_info; |
132 bool exists = file_util::GetFileInfo(file_path_, &file_info); | 132 bool exists = file_util::GetFileInfo(file_path_, &file_info); |
133 | 133 |
134 // Continue asynchronously. | 134 // Continue asynchronously. |
135 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 135 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
136 this, &URLRequestFileJob::DidResolve, exists, file_info)); | 136 this, &URLRequestFileJob::DidResolve, exists, file_info)); |
137 } | 137 } |
138 | 138 |
139 void URLRequestFileJob::Kill() { | 139 void URLRequestFileJob::Kill() { |
140 stream_.Close(); | 140 stream_.Close(); |
141 | 141 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // TODO(hclam): decide whether we want to support multiple range | 214 // TODO(hclam): decide whether we want to support multiple range |
215 // requests. | 215 // requests. |
216 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 216 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
217 net::ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 217 net::ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
218 } | 218 } |
219 } | 219 } |
220 } | 220 } |
221 } | 221 } |
222 | 222 |
223 void URLRequestFileJob::DidResolve( | 223 void URLRequestFileJob::DidResolve( |
224 bool exists, const file_util::FileInfo& file_info) { | 224 bool exists, const base::PlatformFileInfo& file_info) { |
225 #if defined(OS_WIN) | 225 #if defined(OS_WIN) |
226 async_resolver_ = NULL; | 226 async_resolver_ = NULL; |
227 #endif | 227 #endif |
228 | 228 |
229 // We may have been orphaned... | 229 // We may have been orphaned... |
230 if (!request_) | 230 if (!request_) |
231 return; | 231 return; |
232 | 232 |
233 is_directory_ = file_info.is_directory; | 233 is_directory_ = file_info.is_directory; |
234 | 234 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 if (!resolved) | 323 if (!resolved) |
324 return false; | 324 return false; |
325 | 325 |
326 *location = net::FilePathToFileURL(new_path); | 326 *location = net::FilePathToFileURL(new_path); |
327 *http_status_code = 301; | 327 *http_status_code = 301; |
328 return true; | 328 return true; |
329 #else | 329 #else |
330 return false; | 330 return false; |
331 #endif | 331 #endif |
332 } | 332 } |
OLD | NEW |