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

Side by Side Diff: net/url_request/url_request_file_job.cc

Issue 3983005: Revert 63600 - Thread IO safety: annotate file_util, and block IO thread from... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 2 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
« no previous file with comments | « net/socket/ssl_client_socket_nss.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 //
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/thread_restrictions.h"
27 #include "build/build_config.h" 26 #include "build/build_config.h"
28 #include "googleurl/src/gurl.h" 27 #include "googleurl/src/gurl.h"
29 #include "net/base/io_buffer.h" 28 #include "net/base/io_buffer.h"
30 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
31 #include "net/base/mime_util.h" 30 #include "net/base/mime_util.h"
32 #include "net/base/net_errors.h" 31 #include "net/base/net_errors.h"
33 #include "net/base/net_util.h" 32 #include "net/base/net_util.h"
34 #include "net/http/http_util.h" 33 #include "net/http/http_util.h"
35 #include "net/url_request/url_request.h" 34 #include "net/url_request/url_request.h"
36 #include "net/url_request/url_request_file_dir_job.h" 35 #include "net/url_request/url_request_file_dir_job.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 #if defined(OS_WIN) 121 #if defined(OS_WIN)
123 // Resolve UNC paths on a background thread. 122 // Resolve UNC paths on a background thread.
124 if (!file_path_.value().compare(0, 2, L"\\\\")) { 123 if (!file_path_.value().compare(0, 2, L"\\\\")) {
125 DCHECK(!async_resolver_); 124 DCHECK(!async_resolver_);
126 async_resolver_ = new AsyncResolver(this); 125 async_resolver_ = new AsyncResolver(this);
127 WorkerPool::PostTask(FROM_HERE, NewRunnableMethod( 126 WorkerPool::PostTask(FROM_HERE, NewRunnableMethod(
128 async_resolver_.get(), &AsyncResolver::Resolve, file_path_), true); 127 async_resolver_.get(), &AsyncResolver::Resolve, file_path_), true);
129 return; 128 return;
130 } 129 }
131 #endif 130 #endif
132
133 // URL requests should not block on the disk!
134 // http://code.google.com/p/chromium/issues/detail?id=59849
135 bool exists;
136 base::PlatformFileInfo file_info; 131 base::PlatformFileInfo file_info;
137 { 132 bool exists = file_util::GetFileInfo(file_path_, &file_info);
138 base::ThreadRestrictions::ScopedAllowIO allow_io;
139 exists = file_util::GetFileInfo(file_path_, &file_info);
140 }
141 133
142 // Continue asynchronously. 134 // Continue asynchronously.
143 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 135 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
144 this, &URLRequestFileJob::DidResolve, exists, file_info)); 136 this, &URLRequestFileJob::DidResolve, exists, file_info));
145 } 137 }
146 138
147 void URLRequestFileJob::Kill() { 139 void URLRequestFileJob::Kill() {
148 stream_.Close(); 140 stream_.Close();
149 141
150 #if defined(OS_WIN) 142 #if defined(OS_WIN)
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 if (!resolved) 323 if (!resolved)
332 return false; 324 return false;
333 325
334 *location = net::FilePathToFileURL(new_path); 326 *location = net::FilePathToFileURL(new_path);
335 *http_status_code = 301; 327 *http_status_code = 301;
336 return true; 328 return true;
337 #else 329 #else
338 return false; 330 return false;
339 #endif 331 #endif
340 } 332 }
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_nss.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698