| 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" | |
| 10 #include "base/bind.h" | 9 #include "base/bind.h" |
| 11 #include "base/logging.h" | 10 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 13 #include "base/rand_util.h" | |
| 14 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 12 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 15 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 13 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 16 #include "content/browser/loader/resource_request_info_impl.h" | 14 #include "content/browser/loader/resource_request_info_impl.h" |
| 17 #include "content/browser/streams/stream_context.h" | 15 #include "content/browser/streams/stream_context.h" |
| 18 #include "content/browser/webui/url_data_manager_backend.h" | 16 #include "content/browser/webui/url_data_manager_backend.h" |
| 19 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 21 #include "net/base/keygen_handler.h" | 19 #include "net/base/keygen_handler.h" |
| 22 #include "net/ssl/client_cert_store.h" | 20 #include "net/ssl/client_cert_store.h" |
| 23 | 21 |
| 24 using base::UserDataAdapter; | 22 using base::UserDataAdapter; |
| 25 | 23 |
| 26 namespace content { | 24 namespace content { |
| 27 | 25 |
| 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 ResourceContext::ResourceContext() | 33 // Used by the default implementation of GetMediaDeviceIDSalt, below. |
| 34 : media_device_id_salt_(CreateRandomMediaDeviceIDSalt()) { | 34 std::string ReturnEmptySalt() { |
| 35 return std::string(); |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
| 40 |
| 41 ResourceContext::ResourceContext() { |
| 35 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); | 42 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); |
| 36 if (rdhi) { | 43 if (rdhi) { |
| 37 BrowserThread::PostTask( | 44 BrowserThread::PostTask( |
| 38 BrowserThread::IO, FROM_HERE, | 45 BrowserThread::IO, FROM_HERE, |
| 39 base::Bind(&ResourceDispatcherHostImpl::AddResourceContext, | 46 base::Bind(&ResourceDispatcherHostImpl::AddResourceContext, |
| 40 base::Unretained(rdhi), this)); | 47 base::Unretained(rdhi), this)); |
| 41 } | 48 } |
| 42 } | 49 } |
| 43 | 50 |
| 44 ResourceContext::~ResourceContext() { | 51 ResourceContext::~ResourceContext() { |
| 45 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); | 52 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); |
| 46 if (rdhi) { | 53 if (rdhi) { |
| 47 rdhi->CancelRequestsForContext(this); | 54 rdhi->CancelRequestsForContext(this); |
| 48 rdhi->RemoveResourceContext(this); | 55 rdhi->RemoveResourceContext(this); |
| 49 } | 56 } |
| 50 | 57 |
| 51 // In some tests this object is destructed on UI thread. | 58 // In some tests this object is destructed on UI thread. |
| 52 DetachUserDataThread(); | 59 DetachUserDataThread(); |
| 53 } | 60 } |
| 54 | 61 |
| 55 std::string ResourceContext::GetMediaDeviceIDSalt() { | 62 ResourceContext::SaltCallback ResourceContext::GetMediaDeviceIDSalt() { |
| 56 return media_device_id_salt_; | 63 return base::Bind(&ReturnEmptySalt); |
| 57 } | 64 } |
| 58 | 65 |
| 59 std::unique_ptr<net::ClientCertStore> ResourceContext::CreateClientCertStore() { | 66 std::unique_ptr<net::ClientCertStore> ResourceContext::CreateClientCertStore() { |
| 60 return std::unique_ptr<net::ClientCertStore>(); | 67 return std::unique_ptr<net::ClientCertStore>(); |
| 61 } | 68 } |
| 62 | 69 |
| 63 void ResourceContext::CreateKeygenHandler( | 70 void ResourceContext::CreateKeygenHandler( |
| 64 uint32_t key_size_in_bits, | 71 uint32_t key_size_in_bits, |
| 65 const std::string& challenge_string, | 72 const std::string& challenge_string, |
| 66 const GURL& url, | 73 const GURL& url, |
| 67 const base::Callback<void(std::unique_ptr<net::KeygenHandler>)>& callback) { | 74 const base::Callback<void(std::unique_ptr<net::KeygenHandler>)>& callback) { |
| 68 callback.Run(base::WrapUnique( | 75 callback.Run(base::WrapUnique( |
| 69 new net::KeygenHandler(key_size_in_bits, challenge_string, url))); | 76 new net::KeygenHandler(key_size_in_bits, challenge_string, url))); |
| 70 } | 77 } |
| 71 | 78 |
| 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 | |
| 80 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( | 79 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( |
| 81 const ResourceContext* resource_context) { | 80 const ResourceContext* resource_context) { |
| 82 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 81 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 83 return UserDataAdapter<ChromeBlobStorageContext>::Get( | 82 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
| 84 resource_context, kBlobStorageContextKeyName); | 83 resource_context, kBlobStorageContextKeyName); |
| 85 } | 84 } |
| 86 | 85 |
| 87 StreamContext* GetStreamContextForResourceContext( | 86 StreamContext* GetStreamContextForResourceContext( |
| 88 const ResourceContext* resource_context) { | 87 const ResourceContext* resource_context) { |
| 89 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 88 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 112 | 111 |
| 113 resource_context->SetUserData( | 112 resource_context->SetUserData( |
| 114 kStreamContextKeyName, | 113 kStreamContextKeyName, |
| 115 new UserDataAdapter<StreamContext>( | 114 new UserDataAdapter<StreamContext>( |
| 116 StreamContext::GetFor(browser_context))); | 115 StreamContext::GetFor(browser_context))); |
| 117 | 116 |
| 118 resource_context->DetachUserDataThread(); | 117 resource_context->DetachUserDataThread(); |
| 119 } | 118 } |
| 120 | 119 |
| 121 } // namespace content | 120 } // namespace content |
| OLD | NEW |