IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / resource_context_impl.cc
blob9561c8d8ebf8ac32dda2ed3544d066d56cbdc09e
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 "content/browser/resource_context_impl.h"
7 #include "base/logging.h"
8 #include "content/browser/fileapi/chrome_blob_storage_context.h"
9 #include "content/browser/host_zoom_map_impl.h"
10 #include "content/browser/loader/resource_dispatcher_host_impl.h"
11 #include "content/browser/loader/resource_request_info_impl.h"
12 #include "content/browser/streams/stream_context.h"
13 #include "content/browser/webui/url_data_manager_backend.h"
14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "net/base/keygen_handler.h"
17 #include "net/ssl/client_cert_store.h"
19 using base::UserDataAdapter;
21 namespace content {
23 namespace {
25 // Key names on ResourceContext.
26 const char kBlobStorageContextKeyName[] = "content_blob_storage_context";
27 const char kHostZoomMapKeyName[] = "content_host_zoom_map";
28 const char kStreamContextKeyName[] = "content_stream_context";
29 const char kURLDataManagerBackendKeyName[] = "url_data_manager_backend";
31 class NonOwningZoomData : public base::SupportsUserData::Data {
32 public:
33 explicit NonOwningZoomData(HostZoomMap* hzm) : host_zoom_map_(hzm) {}
34 HostZoomMap* host_zoom_map() { return host_zoom_map_; }
36 private:
37 HostZoomMap* host_zoom_map_;
40 } // namespace
43 ResourceContext::ResourceContext() {
44 if (ResourceDispatcherHostImpl::Get())
45 ResourceDispatcherHostImpl::Get()->AddResourceContext(this);
48 ResourceContext::~ResourceContext() {
49 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get();
50 if (rdhi) {
51 rdhi->CancelRequestsForContext(this);
52 rdhi->RemoveResourceContext(this);
55 // In some tests this object is destructed on UI thread.
56 DetachUserDataThread();
59 std::string ResourceContext::GetMediaDeviceIDSalt() {
60 return std::string();
63 scoped_ptr<net::ClientCertStore> ResourceContext::CreateClientCertStore() {
64 return scoped_ptr<net::ClientCertStore>();
67 void ResourceContext::CreateKeygenHandler(
68 uint32 key_size_in_bits,
69 const std::string& challenge_string,
70 const GURL& url,
71 const base::Callback<void(scoped_ptr<net::KeygenHandler>)>& callback) {
72 callback.Run(make_scoped_ptr(
73 new net::KeygenHandler(key_size_in_bits, challenge_string, url)));
76 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext(
77 ResourceContext* resource_context) {
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
79 return UserDataAdapter<ChromeBlobStorageContext>::Get(
80 resource_context, kBlobStorageContextKeyName);
83 StreamContext* GetStreamContextForResourceContext(
84 ResourceContext* resource_context) {
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
86 return UserDataAdapter<StreamContext>::Get(
87 resource_context, kStreamContextKeyName);
90 HostZoomMap* GetHostZoomMapForResourceContext(ResourceContext* context) {
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
92 return static_cast<NonOwningZoomData*>(
93 context->GetUserData(kHostZoomMapKeyName))->host_zoom_map();
96 URLDataManagerBackend* GetURLDataManagerForResourceContext(
97 ResourceContext* context) {
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
99 if (!context->GetUserData(kURLDataManagerBackendKeyName)) {
100 context->SetUserData(kURLDataManagerBackendKeyName,
101 new URLDataManagerBackend());
103 return static_cast<URLDataManagerBackend*>(
104 context->GetUserData(kURLDataManagerBackendKeyName));
107 void InitializeResourceContext(BrowserContext* browser_context) {
108 ResourceContext* resource_context = browser_context->GetResourceContext();
109 DCHECK(!resource_context->GetUserData(kHostZoomMapKeyName));
111 resource_context->SetUserData(
112 kBlobStorageContextKeyName,
113 new UserDataAdapter<ChromeBlobStorageContext>(
114 ChromeBlobStorageContext::GetFor(browser_context)));
116 resource_context->SetUserData(
117 kStreamContextKeyName,
118 new UserDataAdapter<StreamContext>(
119 StreamContext::GetFor(browser_context)));
121 // This object is owned by the BrowserContext and not ResourceContext, so
122 // store a non-owning pointer here.
123 resource_context->SetUserData(
124 kHostZoomMapKeyName,
125 new NonOwningZoomData(
126 HostZoomMap::GetForBrowserContext(browser_context)));
128 resource_context->DetachUserDataThread();
131 } // namespace content