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