| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/resource_context_impl.h" | 5 #include "content/browser/resource_context_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/base64.h" |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/rand_util.h" |
| 12 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 14 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 13 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 15 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 14 #include "content/browser/loader/resource_request_info_impl.h" | 16 #include "content/browser/loader/resource_request_info_impl.h" |
| 15 #include "content/browser/streams/stream_context.h" | 17 #include "content/browser/streams/stream_context.h" |
| 16 #include "content/browser/webui/url_data_manager_backend.h" | 18 #include "content/browser/webui/url_data_manager_backend.h" |
| 17 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 19 #include "net/base/keygen_handler.h" | 21 #include "net/base/keygen_handler.h" |
| 20 #include "net/ssl/client_cert_store.h" | 22 #include "net/ssl/client_cert_store.h" |
| 21 | 23 |
| 22 using base::UserDataAdapter; | 24 using base::UserDataAdapter; |
| 23 | 25 |
| 24 namespace content { | 26 namespace content { |
| 25 | 27 |
| 26 namespace { | |
| 27 | |
| 28 // Key names on ResourceContext. | 28 // Key names on ResourceContext. |
| 29 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; | 29 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; |
| 30 const char kStreamContextKeyName[] = "content_stream_context"; | 30 const char kStreamContextKeyName[] = "content_stream_context"; |
| 31 const char kURLDataManagerBackendKeyName[] = "url_data_manager_backend"; | 31 const char kURLDataManagerBackendKeyName[] = "url_data_manager_backend"; |
| 32 | 32 |
| 33 // Used by the default implementation of GetMediaDeviceIDSalt, below. | 33 ResourceContext::ResourceContext() |
| 34 std::string ReturnEmptySalt() { | 34 : media_device_id_salt_(CreateRandomMediaDeviceIDSalt()) { |
| 35 return std::string(); | |
| 36 } | |
| 37 | |
| 38 } // namespace | |
| 39 | |
| 40 | |
| 41 ResourceContext::ResourceContext() { | |
| 42 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); | 35 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); |
| 43 if (rdhi) { | 36 if (rdhi) { |
| 44 BrowserThread::PostTask( | 37 BrowserThread::PostTask( |
| 45 BrowserThread::IO, FROM_HERE, | 38 BrowserThread::IO, FROM_HERE, |
| 46 base::Bind(&ResourceDispatcherHostImpl::AddResourceContext, | 39 base::Bind(&ResourceDispatcherHostImpl::AddResourceContext, |
| 47 base::Unretained(rdhi), this)); | 40 base::Unretained(rdhi), this)); |
| 48 } | 41 } |
| 49 } | 42 } |
| 50 | 43 |
| 51 ResourceContext::~ResourceContext() { | 44 ResourceContext::~ResourceContext() { |
| 52 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); | 45 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); |
| 53 if (rdhi) { | 46 if (rdhi) { |
| 54 rdhi->CancelRequestsForContext(this); | 47 rdhi->CancelRequestsForContext(this); |
| 55 rdhi->RemoveResourceContext(this); | 48 rdhi->RemoveResourceContext(this); |
| 56 } | 49 } |
| 57 | 50 |
| 58 // In some tests this object is destructed on UI thread. | 51 // In some tests this object is destructed on UI thread. |
| 59 DetachUserDataThread(); | 52 DetachUserDataThread(); |
| 60 } | 53 } |
| 61 | 54 |
| 62 ResourceContext::SaltCallback ResourceContext::GetMediaDeviceIDSalt() { | 55 std::string ResourceContext::GetMediaDeviceIDSalt() { |
| 63 return base::Bind(&ReturnEmptySalt); | 56 return media_device_id_salt_; |
| 64 } | 57 } |
| 65 | 58 |
| 66 std::unique_ptr<net::ClientCertStore> ResourceContext::CreateClientCertStore() { | 59 std::unique_ptr<net::ClientCertStore> ResourceContext::CreateClientCertStore() { |
| 67 return std::unique_ptr<net::ClientCertStore>(); | 60 return std::unique_ptr<net::ClientCertStore>(); |
| 68 } | 61 } |
| 69 | 62 |
| 70 void ResourceContext::CreateKeygenHandler( | 63 void ResourceContext::CreateKeygenHandler( |
| 71 uint32_t key_size_in_bits, | 64 uint32_t key_size_in_bits, |
| 72 const std::string& challenge_string, | 65 const std::string& challenge_string, |
| 73 const GURL& url, | 66 const GURL& url, |
| 74 const base::Callback<void(std::unique_ptr<net::KeygenHandler>)>& callback) { | 67 const base::Callback<void(std::unique_ptr<net::KeygenHandler>)>& callback) { |
| 75 callback.Run(base::WrapUnique( | 68 callback.Run(base::WrapUnique( |
| 76 new net::KeygenHandler(key_size_in_bits, challenge_string, url))); | 69 new net::KeygenHandler(key_size_in_bits, challenge_string, url))); |
| 77 } | 70 } |
| 78 | 71 |
| 72 // static |
| 73 std::string ResourceContext::CreateRandomMediaDeviceIDSalt() { |
| 74 std::string salt; |
| 75 base::Base64Encode(base::RandBytesAsString(16), &salt); |
| 76 DCHECK(!salt.empty()); |
| 77 return salt; |
| 78 } |
| 79 |
| 79 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( | 80 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( |
| 80 const ResourceContext* resource_context) { | 81 const ResourceContext* resource_context) { |
| 81 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 82 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 82 return UserDataAdapter<ChromeBlobStorageContext>::Get( | 83 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
| 83 resource_context, kBlobStorageContextKeyName); | 84 resource_context, kBlobStorageContextKeyName); |
| 84 } | 85 } |
| 85 | 86 |
| 86 StreamContext* GetStreamContextForResourceContext( | 87 StreamContext* GetStreamContextForResourceContext( |
| 87 const ResourceContext* resource_context) { | 88 const ResourceContext* resource_context) { |
| 88 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 89 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 111 | 112 |
| 112 resource_context->SetUserData( | 113 resource_context->SetUserData( |
| 113 kStreamContextKeyName, | 114 kStreamContextKeyName, |
| 114 new UserDataAdapter<StreamContext>( | 115 new UserDataAdapter<StreamContext>( |
| 115 StreamContext::GetFor(browser_context))); | 116 StreamContext::GetFor(browser_context))); |
| 116 | 117 |
| 117 resource_context->DetachUserDataThread(); | 118 resource_context->DetachUserDataThread(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 } // namespace content | 121 } // namespace content |
| OLD | NEW |