| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/net/file_system_url_request_job_factory.h" | |
| 6 | |
| 7 #include "base/basictypes.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" | |
| 13 #include "webkit/fileapi/file_system_url_request_job.h" | |
| 14 #include "webkit/fileapi/file_system_dir_url_request_job.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 class FileSystemProtocolHandler | |
| 19 : public net::URLRequestJobFactory::ProtocolHandler { | |
| 20 public: | |
| 21 explicit FileSystemProtocolHandler(fileapi::FileSystemContext* context); | |
| 22 virtual ~FileSystemProtocolHandler(); | |
| 23 | |
| 24 virtual net::URLRequestJob* MaybeCreateJob( | |
| 25 net::URLRequest* request) const OVERRIDE; | |
| 26 | |
| 27 private: | |
| 28 // No scoped_refptr because |file_system_context_| is owned by the | |
| 29 // ProfileIOData, which also owns this ProtocolHandler. | |
| 30 fileapi::FileSystemContext* const file_system_context_; | |
| 31 | |
| 32 DISALLOW_COPY_AND_ASSIGN(FileSystemProtocolHandler); | |
| 33 }; | |
| 34 | |
| 35 FileSystemProtocolHandler::FileSystemProtocolHandler( | |
| 36 fileapi::FileSystemContext* context) | |
| 37 : file_system_context_(context) { | |
| 38 DCHECK(file_system_context_); | |
| 39 } | |
| 40 | |
| 41 FileSystemProtocolHandler::~FileSystemProtocolHandler() {} | |
| 42 | |
| 43 net::URLRequestJob* FileSystemProtocolHandler::MaybeCreateJob( | |
| 44 net::URLRequest* request) const { | |
| 45 const std::string path = request->url().path(); | |
| 46 | |
| 47 // 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 | |
| 49 // redirects back here, by adding a / to the URL. | |
| 50 if (!path.empty() && path[path.size() - 1] == '/') { | |
| 51 return new fileapi::FileSystemDirURLRequestJob( | |
| 52 request, file_system_context_, | |
| 53 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | |
| 54 } | |
| 55 return new fileapi::FileSystemURLRequestJob( | |
| 56 request, file_system_context_, | |
| 57 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | |
| 58 } | |
| 59 | |
| 60 } // anonymous namespace | |
| 61 | |
| 62 net::URLRequestJobFactory::ProtocolHandler* | |
| 63 CreateFileSystemProtocolHandler(fileapi::FileSystemContext* context) { | |
| 64 DCHECK(context); | |
| 65 return new FileSystemProtocolHandler(context); | |
| 66 } | |
| OLD | NEW |