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

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

Issue 10700117: Replaced static URLRequestFileJob factory with non-static protocol handler for File jobs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits 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
« no previous file with comments | « net/url_request/file_protocol_handler.h ('k') | net/url_request/url_request_file_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/url_request/file_protocol_handler.h"
6
7 #include "base/logging.h"
8 #include "net/base/net_errors.h"
9 #include "net/base/net_util.h"
10 #include "net/url_request/url_request_error_job.h"
11 #include "net/url_request/url_request_file_dir_job.h"
12 #include "net/url_request/url_request_file_job.h"
13
14 namespace net {
15
16 FileProtocolHandler::FileProtocolHandler(
17 NetworkDelegate* network_delegate)
18 : network_delegate_(network_delegate) {
19 }
20
21 URLRequestJob* FileProtocolHandler::MaybeCreateJob(URLRequest* request) const {
22 FilePath file_path;
23 const bool is_file = FileURLToFilePath(request->url(), &file_path);
24
25 // Check file access permissions.
26 if (!network_delegate_ ||
27 !network_delegate_->CanAccessFile(*request, file_path)) {
28 return new URLRequestErrorJob(request, ERR_ACCESS_DENIED);
29 }
30
31 // We need to decide whether to create URLRequestFileJob for file access or
32 // URLRequestFileDirJob for directory access. To avoid accessing the
33 // filesystem, we only look at the path string here.
34 // The code in the URLRequestFileJob::Start() method discovers that a path,
35 // which doesn't end with a slash, should really be treated as a directory,
36 // and it then redirects to the URLRequestFileDirJob.
37 if (is_file &&
38 file_util::EndsWithSeparator(file_path) &&
39 file_path.IsAbsolute()) {
40 return new URLRequestFileDirJob(request, file_path);
41 }
42
43 // Use a regular file request job for all non-directories (including invalid
44 // file names).
45 return new URLRequestFileJob(request, file_path, network_delegate_);
46 }
47
48 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/file_protocol_handler.h ('k') | net/url_request/url_request_file_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698