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

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

Issue 10855209: Refactoring: ProtocolHandler::MaybeCreateJob takes NetworkDelegate as argument (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 owner_->DidResolve(exists, file_info); 77 owner_->DidResolve(exists, file_info);
78 } 78 }
79 79
80 URLRequestFileJob* owner_; 80 URLRequestFileJob* owner_;
81 81
82 base::Lock lock_; 82 base::Lock lock_;
83 MessageLoop* owner_loop_; 83 MessageLoop* owner_loop_;
84 }; 84 };
85 85
86 URLRequestFileJob::URLRequestFileJob(URLRequest* request, 86 URLRequestFileJob::URLRequestFileJob(URLRequest* request,
87 NetworkDelegate* network_delegate,
87 const FilePath& file_path) 88 const FilePath& file_path)
88 : URLRequestJob(request, request->context()->network_delegate()), 89 : URLRequestJob(request, network_delegate),
89 file_path_(file_path), 90 file_path_(file_path),
90 stream_(NULL), 91 stream_(NULL),
91 is_directory_(false), 92 is_directory_(false),
92 remaining_bytes_(0) { 93 remaining_bytes_(0) {
93 } 94 }
94 95
95 // static 96 // static
96 URLRequestJob* URLRequestFileJob::Factory(URLRequest* request, 97 URLRequestJob* URLRequestFileJob::Factory(URLRequest* request,
97 const std::string& scheme) { 98 const std::string& scheme) {
98 FilePath file_path; 99 FilePath file_path;
99 const bool is_file = FileURLToFilePath(request->url(), &file_path); 100 const bool is_file = FileURLToFilePath(request->url(), &file_path);
100 101
101 // Check file access permissions. 102 // Check file access permissions.
102 if (!IsFileAccessAllowed(*request, file_path)) 103 if (!IsFileAccessAllowed(*request, file_path))
103 return new URLRequestErrorJob(request, ERR_ACCESS_DENIED); 104 return new URLRequestErrorJob(request,
105 request->context()->network_delegate(),
106 ERR_ACCESS_DENIED);
104 107
105 // We need to decide whether to create URLRequestFileJob for file access or 108 // We need to decide whether to create URLRequestFileJob for file access or
106 // URLRequestFileDirJob for directory access. To avoid accessing the 109 // URLRequestFileDirJob for directory access. To avoid accessing the
107 // filesystem, we only look at the path string here. 110 // filesystem, we only look at the path string here.
108 // The code in the URLRequestFileJob::Start() method discovers that a path, 111 // The code in the URLRequestFileJob::Start() method discovers that a path,
109 // which doesn't end with a slash, should really be treated as a directory, 112 // which doesn't end with a slash, should really be treated as a directory,
110 // and it then redirects to the URLRequestFileDirJob. 113 // and it then redirects to the URLRequestFileDirJob.
111 if (is_file && 114 if (is_file &&
112 file_util::EndsWithSeparator(file_path) && 115 file_util::EndsWithSeparator(file_path) &&
113 file_path.IsAbsolute()) 116 file_path.IsAbsolute())
114 return new URLRequestFileDirJob(request, file_path); 117 return new URLRequestFileDirJob(request, file_path);
115 118
116 // Use a regular file request job for all non-directories (including invalid 119 // Use a regular file request job for all non-directories (including invalid
117 // file names). 120 // file names).
118 return new URLRequestFileJob(request, file_path); 121 return new URLRequestFileJob(
122 request, request->context()->network_delegate(), file_path);
119 } 123 }
120 124
121 void URLRequestFileJob::Start() { 125 void URLRequestFileJob::Start() {
122 DCHECK(!async_resolver_); 126 DCHECK(!async_resolver_);
123 async_resolver_ = new AsyncResolver(this); 127 async_resolver_ = new AsyncResolver(this);
124 base::WorkerPool::PostTask( 128 base::WorkerPool::PostTask(
125 FROM_HERE, 129 FROM_HERE,
126 base::Bind(&AsyncResolver::Resolve, async_resolver_.get(), file_path_), 130 base::Bind(&AsyncResolver::Resolve, async_resolver_.get(), file_path_),
127 true); 131 true);
128 } 132 }
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); 342 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result));
339 } 343 }
340 344
341 remaining_bytes_ -= result; 345 remaining_bytes_ -= result;
342 DCHECK_GE(remaining_bytes_, 0); 346 DCHECK_GE(remaining_bytes_, 0);
343 347
344 NotifyReadComplete(result); 348 NotifyReadComplete(result);
345 } 349 }
346 350
347 } // namespace net 351 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698