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

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

Issue 12605011: Revert 188912 "Removed static factories for data, ftp, file, and..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 9 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
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 URLRequestFileJob::URLRequestFileJob(URLRequest* request, 55 URLRequestFileJob::URLRequestFileJob(URLRequest* request,
56 NetworkDelegate* network_delegate, 56 NetworkDelegate* network_delegate,
57 const base::FilePath& file_path) 57 const base::FilePath& file_path)
58 : URLRequestJob(request, network_delegate), 58 : URLRequestJob(request, network_delegate),
59 file_path_(file_path), 59 file_path_(file_path),
60 stream_(new FileStream(NULL)), 60 stream_(new FileStream(NULL)),
61 remaining_bytes_(0), 61 remaining_bytes_(0),
62 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 62 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
63 } 63 }
64 64
65 // static
66 URLRequestJob* URLRequestFileJob::Factory(URLRequest* request,
67 NetworkDelegate* network_delegate,
68 const std::string& scheme) {
69 base::FilePath file_path;
70 const bool is_file = FileURLToFilePath(request->url(), &file_path);
71
72 // Check file access permissions.
73 if (!network_delegate ||
74 !network_delegate->CanAccessFile(*request, file_path)) {
75 return new URLRequestErrorJob(request, network_delegate, ERR_ACCESS_DENIED);
76 }
77 // We need to decide whether to create URLRequestFileJob for file access or
78 // URLRequestFileDirJob for directory access. To avoid accessing the
79 // filesystem, we only look at the path string here.
80 // The code in the URLRequestFileJob::Start() method discovers that a path,
81 // which doesn't end with a slash, should really be treated as a directory,
82 // and it then redirects to the URLRequestFileDirJob.
83 if (is_file &&
84 file_util::EndsWithSeparator(file_path) &&
85 file_path.IsAbsolute())
86 return new URLRequestFileDirJob(request, network_delegate, file_path);
87
88 // Use a regular file request job for all non-directories (including invalid
89 // file names).
90 return new URLRequestFileJob(request, network_delegate, file_path);
91 }
92
65 void URLRequestFileJob::Start() { 93 void URLRequestFileJob::Start() {
66 FileMetaInfo* meta_info = new FileMetaInfo(); 94 FileMetaInfo* meta_info = new FileMetaInfo();
67 base::WorkerPool::PostTaskAndReply( 95 base::WorkerPool::PostTaskAndReply(
68 FROM_HERE, 96 FROM_HERE,
69 base::Bind(&URLRequestFileJob::FetchMetaInfo, file_path_, 97 base::Bind(&URLRequestFileJob::FetchMetaInfo, file_path_,
70 base::Unretained(meta_info)), 98 base::Unretained(meta_info)),
71 base::Bind(&URLRequestFileJob::DidFetchMetaInfo, 99 base::Bind(&URLRequestFileJob::DidFetchMetaInfo,
72 weak_ptr_factory_.GetWeakPtr(), 100 weak_ptr_factory_.GetWeakPtr(),
73 base::Owned(meta_info)), 101 base::Owned(meta_info)),
74 true); 102 true);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); 318 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result));
291 } 319 }
292 320
293 remaining_bytes_ -= result; 321 remaining_bytes_ -= result;
294 DCHECK_GE(remaining_bytes_, 0); 322 DCHECK_GE(remaining_bytes_, 0);
295 323
296 NotifyReadComplete(result); 324 NotifyReadComplete(result);
297 } 325 }
298 326
299 } // namespace net 327 } // namespace net
OLDNEW
« no previous file with comments | « trunk/src/net/url_request/url_request_file_job.h ('k') | trunk/src/net/url_request/url_request_ftp_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698