OLD | NEW |
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 #include "webkit/fileapi/file_system_url_request_job_factory.h" | 5 #include "webkit/fileapi/file_system_url_request_job_factory.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
12 #include "webkit/fileapi/file_system_url_request_job.h" | 12 #include "webkit/fileapi/file_system_url_request_job.h" |
13 #include "webkit/fileapi/file_system_dir_url_request_job.h" | 13 #include "webkit/fileapi/file_system_dir_url_request_job.h" |
14 | 14 |
15 namespace fileapi { | 15 namespace fileapi { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class FileSystemProtocolHandler | 19 class FileSystemProtocolHandler |
20 : public net::URLRequestJobFactory::ProtocolHandler { | 20 : public net::URLRequestJobFactory::ProtocolHandler { |
21 public: | 21 public: |
22 explicit FileSystemProtocolHandler( | 22 explicit FileSystemProtocolHandler(FileSystemContext* context); |
23 FileSystemContext* context, | |
24 base::MessageLoopProxy* loop_proxy); | |
25 virtual ~FileSystemProtocolHandler(); | 23 virtual ~FileSystemProtocolHandler(); |
26 | 24 |
27 virtual net::URLRequestJob* MaybeCreateJob( | 25 virtual net::URLRequestJob* MaybeCreateJob( |
28 net::URLRequest* request) const OVERRIDE; | 26 net::URLRequest* request) const OVERRIDE; |
29 | 27 |
30 private: | 28 private: |
31 // No scoped_refptr because |file_system_context_| is owned by the | 29 // No scoped_refptr because |file_system_context_| is owned by the |
32 // ProfileIOData, which also owns this ProtocolHandler. | 30 // ProfileIOData, which also owns this ProtocolHandler. |
33 FileSystemContext* const file_system_context_; | 31 FileSystemContext* const file_system_context_; |
34 const scoped_refptr<base::MessageLoopProxy> file_loop_proxy_; | |
35 | 32 |
36 DISALLOW_COPY_AND_ASSIGN(FileSystemProtocolHandler); | 33 DISALLOW_COPY_AND_ASSIGN(FileSystemProtocolHandler); |
37 }; | 34 }; |
38 | 35 |
39 FileSystemProtocolHandler::FileSystemProtocolHandler( | 36 FileSystemProtocolHandler::FileSystemProtocolHandler( |
40 FileSystemContext* context, | 37 FileSystemContext* context) |
41 base::MessageLoopProxy* file_loop_proxy) | 38 : file_system_context_(context) { |
42 : file_system_context_(context), | |
43 file_loop_proxy_(file_loop_proxy) { | |
44 DCHECK(file_system_context_); | 39 DCHECK(file_system_context_); |
45 DCHECK(file_loop_proxy_); | |
46 } | 40 } |
47 | 41 |
48 FileSystemProtocolHandler::~FileSystemProtocolHandler() {} | 42 FileSystemProtocolHandler::~FileSystemProtocolHandler() {} |
49 | 43 |
50 net::URLRequestJob* FileSystemProtocolHandler::MaybeCreateJob( | 44 net::URLRequestJob* FileSystemProtocolHandler::MaybeCreateJob( |
51 net::URLRequest* request) const { | 45 net::URLRequest* request) const { |
52 const std::string path = request->url().path(); | 46 const std::string path = request->url().path(); |
53 | 47 |
54 // If the path ends with a /, we know it's a directory. If the path refers | 48 // If the path ends with a /, we know it's a directory. If the path refers |
55 // to a directory and gets dispatched to FileSystemURLRequestJob, that class | 49 // to a directory and gets dispatched to FileSystemURLRequestJob, that class |
56 // redirects back here, by adding a / to the URL. | 50 // redirects back here, by adding a / to the URL. |
57 if (!path.empty() && path[path.size() - 1] == '/') { | 51 if (!path.empty() && path[path.size() - 1] == '/') { |
58 return new FileSystemDirURLRequestJob( | 52 return new FileSystemDirURLRequestJob(request, file_system_context_); |
59 request, file_system_context_, file_loop_proxy_); | |
60 } | 53 } |
61 return new FileSystemURLRequestJob( | 54 return new FileSystemURLRequestJob(request, file_system_context_); |
62 request, file_system_context_, file_loop_proxy_); | |
63 } | 55 } |
64 | 56 |
65 } // anonymous namespace | 57 } // anonymous namespace |
66 | 58 |
67 net::URLRequestJobFactory::ProtocolHandler* | 59 net::URLRequestJobFactory::ProtocolHandler* |
68 CreateFileSystemProtocolHandler(FileSystemContext* context, | 60 CreateFileSystemProtocolHandler(FileSystemContext* context) { |
69 base::MessageLoopProxy* loop_proxy) { | |
70 DCHECK(context); | 61 DCHECK(context); |
71 DCHECK(loop_proxy); | 62 return new FileSystemProtocolHandler(context); |
72 return new FileSystemProtocolHandler(context, loop_proxy); | |
73 } | 63 } |
74 | 64 |
75 } // namespace fileapi | 65 } // namespace fileapi |
OLD | NEW |