[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "content/browser/resource_context_impl.h" |
| 6 | |
[email protected] | ff1e64e | 2012-03-23 15:21:51 | [diff] [blame] | 7 | #include "base/logging.h" |
[email protected] | 16dd6e2 | 2012-03-01 19:08:20 | [diff] [blame] | 8 | #include "content/browser/fileapi/chrome_blob_storage_context.h" |
[email protected] | 678c036 | 2012-12-05 08:02:44 | [diff] [blame] | 9 | #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 10 | #include "content/browser/loader/resource_request_info_impl.h" |
[email protected] | bb85a8c4 | 2013-03-13 04:34:19 | [diff] [blame] | 11 | #include "content/browser/streams/stream_context.h" |
[email protected] | 33c1c26a | 2013-01-24 21:56:26 | [diff] [blame] | 12 | #include "content/browser/webui/url_data_manager_backend.h" |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 13 | #include "content/public/browser/browser_context.h" |
| 14 | #include "content/public/browser/browser_thread.h" |
[email protected] | 99e5e952 | 2013-12-16 13:05:27 | [diff] [blame] | 15 | #include "net/base/keygen_handler.h" |
[email protected] | 1ccb699 | 2013-10-30 04:46:20 | [diff] [blame] | 16 | #include "net/ssl/client_cert_store.h" |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 17 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 18 | using base::UserDataAdapter; |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 19 | |
| 20 | namespace content { |
| 21 | |
[email protected] | ff1e64e | 2012-03-23 15:21:51 | [diff] [blame] | 22 | namespace { |
| 23 | |
[email protected] | 33c1c26a | 2013-01-24 21:56:26 | [diff] [blame] | 24 | // Key names on ResourceContext. |
| 25 | const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; |
[email protected] | bb85a8c4 | 2013-03-13 04:34:19 | [diff] [blame] | 26 | const char kStreamContextKeyName[] = "content_stream_context"; |
[email protected] | 33c1c26a | 2013-01-24 21:56:26 | [diff] [blame] | 27 | const char kURLDataManagerBackendKeyName[] = "url_data_manager_backend"; |
| 28 | |
[email protected] | f9583f8 | 2014-02-13 15:34:21 | [diff] [blame] | 29 | // Used by the default implementation of GetMediaDeviceIDSalt, below. |
| 30 | std::string ReturnEmptySalt() { |
| 31 | return std::string(); |
| 32 | } |
| 33 | |
[email protected] | ff1e64e | 2012-03-23 15:21:51 | [diff] [blame] | 34 | } // namespace |
| 35 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 36 | |
[email protected] | 10848bb | 2012-05-15 17:40:52 | [diff] [blame] | 37 | ResourceContext::ResourceContext() { |
[email protected] | 9a3b349b6 | 2012-03-26 14:38:15 | [diff] [blame] | 38 | if (ResourceDispatcherHostImpl::Get()) |
[email protected] | 10848bb | 2012-05-15 17:40:52 | [diff] [blame] | 39 | ResourceDispatcherHostImpl::Get()->AddResourceContext(this); |
| 40 | } |
| 41 | |
| 42 | ResourceContext::~ResourceContext() { |
| 43 | ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); |
| 44 | if (rdhi) { |
| 45 | rdhi->CancelRequestsForContext(this); |
| 46 | rdhi->RemoveResourceContext(this); |
| 47 | } |
[email protected] | 33c1c26a | 2013-01-24 21:56:26 | [diff] [blame] | 48 | |
| 49 | // In some tests this object is destructed on UI thread. |
| 50 | DetachUserDataThread(); |
[email protected] | 9a3b349b6 | 2012-03-26 14:38:15 | [diff] [blame] | 51 | } |
| 52 | |
[email protected] | f9583f8 | 2014-02-13 15:34:21 | [diff] [blame] | 53 | ResourceContext::SaltCallback ResourceContext::GetMediaDeviceIDSalt() { |
| 54 | return base::Bind(&ReturnEmptySalt); |
[email protected] | cd80cce | 2013-12-02 15:19:19 | [diff] [blame] | 55 | } |
| 56 | |
[email protected] | 1ccb699 | 2013-10-30 04:46:20 | [diff] [blame] | 57 | scoped_ptr<net::ClientCertStore> ResourceContext::CreateClientCertStore() { |
| 58 | return scoped_ptr<net::ClientCertStore>(); |
| 59 | } |
| 60 | |
[email protected] | 99e5e952 | 2013-12-16 13:05:27 | [diff] [blame] | 61 | void ResourceContext::CreateKeygenHandler( |
| 62 | uint32 key_size_in_bits, |
| 63 | const std::string& challenge_string, |
| 64 | const GURL& url, |
| 65 | const base::Callback<void(scoped_ptr<net::KeygenHandler>)>& callback) { |
| 66 | callback.Run(make_scoped_ptr( |
| 67 | new net::KeygenHandler(key_size_in_bits, challenge_string, url))); |
| 68 | } |
| 69 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 70 | ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( |
horo | d556043 | 2014-12-12 06:20:13 | [diff] [blame] | 71 | const ResourceContext* resource_context) { |
mostynb | 042582e | 2015-03-16 22:13:40 | [diff] [blame] | 72 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 73 | return UserDataAdapter<ChromeBlobStorageContext>::Get( |
| 74 | resource_context, kBlobStorageContextKeyName); |
| 75 | } |
| 76 | |
[email protected] | bb85a8c4 | 2013-03-13 04:34:19 | [diff] [blame] | 77 | StreamContext* GetStreamContextForResourceContext( |
horo | d556043 | 2014-12-12 06:20:13 | [diff] [blame] | 78 | const ResourceContext* resource_context) { |
mostynb | 042582e | 2015-03-16 22:13:40 | [diff] [blame] | 79 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | bb85a8c4 | 2013-03-13 04:34:19 | [diff] [blame] | 80 | return UserDataAdapter<StreamContext>::Get( |
| 81 | resource_context, kStreamContextKeyName); |
| 82 | } |
| 83 | |
[email protected] | 5bf1646f5 | 2013-01-28 03:57:02 | [diff] [blame] | 84 | URLDataManagerBackend* GetURLDataManagerForResourceContext( |
[email protected] | 33c1c26a | 2013-01-24 21:56:26 | [diff] [blame] | 85 | ResourceContext* context) { |
mostynb | 042582e | 2015-03-16 22:13:40 | [diff] [blame] | 86 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 33c1c26a | 2013-01-24 21:56:26 | [diff] [blame] | 87 | if (!context->GetUserData(kURLDataManagerBackendKeyName)) { |
| 88 | context->SetUserData(kURLDataManagerBackendKeyName, |
[email protected] | 5bf1646f5 | 2013-01-28 03:57:02 | [diff] [blame] | 89 | new URLDataManagerBackend()); |
[email protected] | 33c1c26a | 2013-01-24 21:56:26 | [diff] [blame] | 90 | } |
[email protected] | 5bf1646f5 | 2013-01-28 03:57:02 | [diff] [blame] | 91 | return static_cast<URLDataManagerBackend*>( |
[email protected] | 33c1c26a | 2013-01-24 21:56:26 | [diff] [blame] | 92 | context->GetUserData(kURLDataManagerBackendKeyName)); |
| 93 | } |
| 94 | |
[email protected] | 7e26ac9 | 2012-02-27 20:15:05 | [diff] [blame] | 95 | void InitializeResourceContext(BrowserContext* browser_context) { |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 96 | ResourceContext* resource_context = browser_context->GetResourceContext(); |
[email protected] | 38ed59b | 2012-02-24 17:08:24 | [diff] [blame] | 97 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 98 | resource_context->SetUserData( |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 99 | kBlobStorageContextKeyName, |
| 100 | new UserDataAdapter<ChromeBlobStorageContext>( |
| 101 | ChromeBlobStorageContext::GetFor(browser_context))); |
[email protected] | 5fe3713a | 2012-02-22 08:31:56 | [diff] [blame] | 102 | |
[email protected] | bb85a8c4 | 2013-03-13 04:34:19 | [diff] [blame] | 103 | resource_context->SetUserData( |
| 104 | kStreamContextKeyName, |
| 105 | new UserDataAdapter<StreamContext>( |
| 106 | StreamContext::GetFor(browser_context))); |
| 107 | |
[email protected] | 7d2e5f762 | 2012-09-10 19:18:53 | [diff] [blame] | 108 | resource_context->DetachUserDataThread(); |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | } // namespace content |