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

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: Removed context from file_dir_job, merged with error_job cl Created 8 years, 5 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
(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(
29 request, network_delegate_, ERR_ACCESS_DENIED);
30 }
31
32 // We need to decide whether to create URLRequestFileJob for file access or
33 // URLRequestFileDirJob for directory access. To avoid accessing the
34 // filesystem, we only look at the path string here.
35 // The code in the URLRequestFileJob::Start() method discovers that a path,
36 // which doesn't end with a slash, should really be treated as a directory,
37 // and it then redirects to the URLRequestFileDirJob.
38 if (is_file &&
39 file_util::EndsWithSeparator(file_path) &&
40 file_path.IsAbsolute()) {
41 return new URLRequestFileDirJob(request, network_delegate_, file_path);
42 }
43
44 // Use a regular file request job for all non-directories (including invalid
45 // file names).
46 return new URLRequestFileJob(request, file_path, network_delegate_);
47 }
48
49 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698