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