summaryrefslogtreecommitdiffstats
path: root/storage/browser/blob/blob_url_request_job_factory.h
blob: 326da9b6f186fe9b3fba7b50a56e32168cbacdc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_FACTORY_H_
#define STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_FACTORY_H_

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job_factory.h"
#include "storage/browser/storage_browser_export.h"

namespace base {
class SingleThreadTaskRunner;
}  // namespace base

namespace storage {
class FileSystemContext;
}  // namespace storage

namespace net {
class URLRequestContext;
}  // namespace net

namespace storage {

class BlobDataHandle;
class BlobStorageContext;

class STORAGE_EXPORT BlobProtocolHandler
    : public net::URLRequestJobFactory::ProtocolHandler {
 public:
  // A helper to manufacture an URLRequest to retrieve the given blob.
  static scoped_ptr<net::URLRequest> CreateBlobRequest(
      scoped_ptr<BlobDataHandle> blob_data_handle,
      const net::URLRequestContext* request_context,
      net::URLRequest::Delegate* request_delegate);

  // This class ignores the request's URL and uses the value given
  // to SetRequestedBlobDataHandle instead.
  static void SetRequestedBlobDataHandle(
      net::URLRequest* request,
      scoped_ptr<BlobDataHandle> blob_data_handle);

  // This gets the handle on the request if it exists.
  static BlobDataHandle* GetRequestBlobDataHandle(net::URLRequest* request);

  BlobProtocolHandler(
      BlobStorageContext* context,
      storage::FileSystemContext* file_system_context,
      const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner);
  ~BlobProtocolHandler() override;

  net::URLRequestJob* MaybeCreateJob(
      net::URLRequest* request,
      net::NetworkDelegate* network_delegate) const override;

 private:
  BlobDataHandle* LookupBlobHandle(net::URLRequest* request) const;

  base::WeakPtr<BlobStorageContext> context_;
  const scoped_refptr<storage::FileSystemContext> file_system_context_;
  const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;

  DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler);
};

}  // namespace storage

#endif  // STORAGE_BROWSER_BLOB_BLOB_URL_REQUEST_JOB_FACTORY_H_