Include all dupe types (event when value is zero) in scan stats.
[chromium-blink-merge.git] / storage / browser / fileapi / file_system_url_request_job_factory.cc
blobc61c8c0a78bad2f8a2b054b8afa59b8ef2f23c50
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.
5 #include "storage/browser/fileapi/file_system_url_request_job_factory.h"
7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h"
9 #include "net/url_request/url_request.h"
10 #include "storage/browser/fileapi/file_system_dir_url_request_job.h"
11 #include "storage/browser/fileapi/file_system_url_request_job.h"
13 namespace storage {
15 namespace {
17 class FileSystemProtocolHandler
18 : public net::URLRequestJobFactory::ProtocolHandler {
19 public:
20 FileSystemProtocolHandler(const std::string& storage_domain,
21 FileSystemContext* context);
22 ~FileSystemProtocolHandler() override;
24 net::URLRequestJob* MaybeCreateJob(
25 net::URLRequest* request,
26 net::NetworkDelegate* network_delegate) const override;
28 private:
29 const std::string storage_domain_;
31 // No scoped_refptr because |file_system_context_| is owned by the
32 // ProfileIOData, which also owns this ProtocolHandler.
33 FileSystemContext* const file_system_context_;
35 DISALLOW_COPY_AND_ASSIGN(FileSystemProtocolHandler);
38 FileSystemProtocolHandler::FileSystemProtocolHandler(
39 const std::string& storage_domain,
40 FileSystemContext* context)
41 : storage_domain_(storage_domain),
42 file_system_context_(context) {
43 DCHECK(file_system_context_);
46 FileSystemProtocolHandler::~FileSystemProtocolHandler() {}
48 net::URLRequestJob* FileSystemProtocolHandler::MaybeCreateJob(
49 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
50 const std::string path = request->url().path();
52 // If the path ends with a /, we know it's a directory. If the path refers
53 // to a directory and gets dispatched to FileSystemURLRequestJob, that class
54 // redirects back here, by adding a / to the URL.
55 if (!path.empty() && path[path.size() - 1] == '/') {
56 return new FileSystemDirURLRequestJob(
57 request, network_delegate, storage_domain_, file_system_context_);
59 return new FileSystemURLRequestJob(
60 request, network_delegate, storage_domain_, file_system_context_);
63 } // anonymous namespace
65 net::URLRequestJobFactory::ProtocolHandler* CreateFileSystemProtocolHandler(
66 const std::string& storage_domain, FileSystemContext* context) {
67 DCHECK(context);
68 return new FileSystemProtocolHandler(storage_domain, context);
71 } // namespace storage