summaryrefslogtreecommitdiffstats
path: root/content/browser/resource_context.h
blob: 90c01e7a9e32d7de582f4166c93daaf052c91257 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// 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 CONTENT_BROWSER_RESOURCE_CONTEXT_H_
#define CONTENT_BROWSER_RESOURCE_CONTEXT_H_

#include <map>

#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "content/browser/download/download_manager.h"

class ChromeAppCacheService;
class ChromeBlobStorageContext;
class ExtensionInfoMap;
class HostZoomMap;
class MediaObserver;
namespace fileapi {
class FileSystemContext;
}  // namespace fileapi
namespace media_stream {
class MediaStreamManager;
}  // namespace media_stream
namespace net {
class HostResolver;
class URLRequestContext;
}  // namespace net
namespace prerender {
class PrerenderManager;
}  // namespace prerender
namespace quota {
class QuotaManager;
};  // namespace quota
namespace webkit_database {
class DatabaseTracker;
}  // namespace webkit_database

namespace content {

// ResourceContext contains the relevant context information required for
// resource loading. It lives on the IO thread, although it is constructed on
// the UI thread. ResourceContext doesn't own anything it points to, it just
// holds pointers to relevant objects to resource loading.
class CONTENT_EXPORT ResourceContext {
 public:
  virtual ~ResourceContext();

  // The user data allows the clients to associate data with this request.
  // Multiple user data values can be stored under different keys.
  void* GetUserData(const void* key) const;
  void SetUserData(const void* key, void* data);

  net::HostResolver* host_resolver() const;
  void set_host_resolver(net::HostResolver* host_resolver);

  net::URLRequestContext* request_context() const;
  void set_request_context(net::URLRequestContext* request_context);

  ChromeAppCacheService* appcache_service() const;
  void set_appcache_service(ChromeAppCacheService* service);

  webkit_database::DatabaseTracker* database_tracker() const;
  void set_database_tracker(webkit_database::DatabaseTracker* tracker);

  fileapi::FileSystemContext* file_system_context() const;
  void set_file_system_context(fileapi::FileSystemContext* context);

  ChromeBlobStorageContext* blob_storage_context() const;
  void set_blob_storage_context(ChromeBlobStorageContext* context);

  quota::QuotaManager* quota_manager() const;
  void set_quota_manager(quota::QuotaManager* quota_manager);

  HostZoomMap* host_zoom_map() const;
  void set_host_zoom_map(HostZoomMap* host_zoom_map);

  MediaObserver* media_observer() const;
  void set_media_observer(MediaObserver* media_observer);

  // TODO(benjhayden): Promote GetNextIdThunkType to a separate object.
  const DownloadManager::GetNextIdThunkType& next_download_id_thunk() const;
  void set_next_download_id_thunk(
      const DownloadManager::GetNextIdThunkType& thunk);

  media_stream::MediaStreamManager* media_stream_manager() const;
  void set_media_stream_manager(
      media_stream::MediaStreamManager* media_stream_manager);

  // =======================================================================
  // TODO(willchan): These don't belong in content/. Remove them eventually.

  // TODO(cbentzel): Kill this one.
  const base::Callback<prerender::PrerenderManager*(void)>&
      prerender_manager_getter() const;
  void set_prerender_manager_getter(
      const base::Callback<prerender::PrerenderManager*(void)>&
          prerender_manager_getter);

 protected:
  ResourceContext();

 private:
  virtual void EnsureInitialized() const = 0;

  net::HostResolver* host_resolver_;
  net::URLRequestContext* request_context_;
  ChromeAppCacheService* appcache_service_;
  webkit_database::DatabaseTracker* database_tracker_;
  fileapi::FileSystemContext* file_system_context_;
  ChromeBlobStorageContext* blob_storage_context_;
  quota::QuotaManager* quota_manager_;
  HostZoomMap* host_zoom_map_;
  MediaObserver* media_observer_;
  DownloadManager::GetNextIdThunkType next_download_id_thunk_;
  media_stream::MediaStreamManager* media_stream_manager_;

  // Externally-defined data accessible by key.
  typedef std::map<const void*, void*> UserDataMap;
  UserDataMap user_data_;


  // =======================================================================
  // TODO(willchan): These don't belong in content/. Remove them eventually.

  base::Callback<prerender::PrerenderManager*(void)> prerender_manager_getter_;

  DISALLOW_COPY_AND_ASSIGN(ResourceContext);
};

}  // namespace content

#endif  // CONTENT_BROWSER_RESOURCE_CONTEXT_H_