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

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

Issue 10836206: Removed static factories for data, ftp, file, and about jobs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: small fix Created 8 years, 3 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/url_request/url_request_file_job.h ('k') | net/url_request/url_request_ftp_job.h » ('j') | 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) 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 // 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 URLRequestFileJob::URLRequestFileJob(URLRequest* request, 84 URLRequestFileJob::URLRequestFileJob(URLRequest* request,
85 NetworkDelegate* network_delegate, 85 NetworkDelegate* network_delegate,
86 const FilePath& file_path) 86 const FilePath& file_path)
87 : URLRequestJob(request, network_delegate), 87 : URLRequestJob(request, network_delegate),
88 file_path_(file_path), 88 file_path_(file_path),
89 stream_(NULL), 89 stream_(NULL),
90 is_directory_(false), 90 is_directory_(false),
91 remaining_bytes_(0) { 91 remaining_bytes_(0) {
92 } 92 }
93 93
94 // static
95 URLRequestJob* URLRequestFileJob::Factory(URLRequest* request,
96 NetworkDelegate* network_delegate,
97 const std::string& scheme) {
98 FilePath file_path;
99 const bool is_file = FileURLToFilePath(request->url(), &file_path);
100
101 // Check file access permissions.
102 if (!network_delegate ||
103 !network_delegate->CanAccessFile(*request, file_path)) {
104 return new URLRequestErrorJob(request, network_delegate, ERR_ACCESS_DENIED);
105 }
106 // We need to decide whether to create URLRequestFileJob for file access or
107 // URLRequestFileDirJob for directory access. To avoid accessing the
108 // filesystem, we only look at the path string here.
109 // The code in the URLRequestFileJob::Start() method discovers that a path,
110 // which doesn't end with a slash, should really be treated as a directory,
111 // and it then redirects to the URLRequestFileDirJob.
112 if (is_file &&
113 file_util::EndsWithSeparator(file_path) &&
114 file_path.IsAbsolute())
115 return new URLRequestFileDirJob(request, network_delegate, file_path);
116
117 // Use a regular file request job for all non-directories (including invalid
118 // file names).
119 return new URLRequestFileJob(request, network_delegate, file_path);
120 }
121
122 void URLRequestFileJob::Start() { 94 void URLRequestFileJob::Start() {
123 DCHECK(!async_resolver_); 95 DCHECK(!async_resolver_);
124 async_resolver_ = new AsyncResolver(this); 96 async_resolver_ = new AsyncResolver(this);
125 base::WorkerPool::PostTask( 97 base::WorkerPool::PostTask(
126 FROM_HERE, 98 FROM_HERE,
127 base::Bind(&AsyncResolver::Resolve, async_resolver_.get(), file_path_), 99 base::Bind(&AsyncResolver::Resolve, async_resolver_.get(), file_path_),
128 true); 100 true);
129 } 101 }
130 102
131 void URLRequestFileJob::Kill() { 103 void URLRequestFileJob::Kill() {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); 302 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result));
331 } 303 }
332 304
333 remaining_bytes_ -= result; 305 remaining_bytes_ -= result;
334 DCHECK_GE(remaining_bytes_, 0); 306 DCHECK_GE(remaining_bytes_, 0);
335 307
336 NotifyReadComplete(result); 308 NotifyReadComplete(result);
337 } 309 }
338 310
339 } // namespace net 311 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_file_job.h ('k') | net/url_request/url_request_ftp_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698