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> |
| 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 { | 30 namespace { |
27 | 31 |
28 // Key names on ResourceContext. | 32 // Key names on ResourceContext. |
29 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; | 33 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; |
30 const char kStreamContextKeyName[] = "content_stream_context"; | 34 const char kStreamContextKeyName[] = "content_stream_context"; |
31 const char kURLDataManagerBackendKeyName[] = "url_data_manager_backend"; | 35 const char kURLDataManagerBackendKeyName[] = "url_data_manager_backend"; |
32 | 36 |
33 // Used by the default implementation of GetMediaDeviceIDSalt, below. | 37 std::string GetSalt(const std::string& salt) { |
34 std::string ReturnEmptySalt() { | 38 return salt; |
35 return std::string(); | |
36 } | 39 } |
37 | 40 |
38 } // namespace | 41 } // namespace |
39 | 42 |
40 | 43 ResourceContext::ResourceContext() |
41 ResourceContext::ResourceContext() { | 44 : media_device_id_salt_(CreateRandomMediaDeviceIDSalt()) { |
42 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); | 45 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); |
43 if (rdhi) { | 46 if (rdhi) { |
44 BrowserThread::PostTask( | 47 BrowserThread::PostTask( |
45 BrowserThread::IO, FROM_HERE, | 48 BrowserThread::IO, FROM_HERE, |
46 base::Bind(&ResourceDispatcherHostImpl::AddResourceContext, | 49 base::Bind(&ResourceDispatcherHostImpl::AddResourceContext, |
47 base::Unretained(rdhi), this)); | 50 base::Unretained(rdhi), this)); |
48 } | 51 } |
49 } | 52 } |
50 | 53 |
51 ResourceContext::~ResourceContext() { | 54 ResourceContext::~ResourceContext() { |
52 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); | 55 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); |
53 if (rdhi) { | 56 if (rdhi) { |
54 rdhi->CancelRequestsForContext(this); | 57 rdhi->CancelRequestsForContext(this); |
55 rdhi->RemoveResourceContext(this); | 58 rdhi->RemoveResourceContext(this); |
56 } | 59 } |
57 | 60 |
58 // In some tests this object is destructed on UI thread. | 61 // In some tests this object is destructed on UI thread. |
59 DetachUserDataThread(); | 62 DetachUserDataThread(); |
60 } | 63 } |
61 | 64 |
62 ResourceContext::SaltCallback ResourceContext::GetMediaDeviceIDSalt() { | 65 ResourceContext::SaltCallback ResourceContext::GetMediaDeviceIDSalt() { |
63 return base::Bind(&ReturnEmptySalt); | 66 return base::Bind(GetSalt, media_device_id_salt_); |
64 } | 67 } |
65 | 68 |
66 std::unique_ptr<net::ClientCertStore> ResourceContext::CreateClientCertStore() { | 69 std::unique_ptr<net::ClientCertStore> ResourceContext::CreateClientCertStore() { |
67 return std::unique_ptr<net::ClientCertStore>(); | 70 return std::unique_ptr<net::ClientCertStore>(); |
68 } | 71 } |
69 | 72 |
70 void ResourceContext::CreateKeygenHandler( | 73 void ResourceContext::CreateKeygenHandler( |
71 uint32_t key_size_in_bits, | 74 uint32_t key_size_in_bits, |
72 const std::string& challenge_string, | 75 const std::string& challenge_string, |
73 const GURL& url, | 76 const GURL& url, |
74 const base::Callback<void(std::unique_ptr<net::KeygenHandler>)>& callback) { | 77 const base::Callback<void(std::unique_ptr<net::KeygenHandler>)>& callback) { |
75 callback.Run(base::WrapUnique( | 78 callback.Run(base::WrapUnique( |
76 new net::KeygenHandler(key_size_in_bits, challenge_string, url))); | 79 new net::KeygenHandler(key_size_in_bits, challenge_string, url))); |
77 } | 80 } |
78 | 81 |
| 82 // static |
| 83 std::string ResourceContext::CreateRandomMediaDeviceIDSalt() { |
| 84 std::string salt; |
| 85 base::Base64Encode(base::RandBytesAsString(16), &salt); |
| 86 DCHECK(!salt.empty()); |
| 87 return salt; |
| 88 } |
| 89 |
79 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( | 90 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( |
80 const ResourceContext* resource_context) { | 91 const ResourceContext* resource_context) { |
81 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 92 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
82 return UserDataAdapter<ChromeBlobStorageContext>::Get( | 93 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
83 resource_context, kBlobStorageContextKeyName); | 94 resource_context, kBlobStorageContextKeyName); |
84 } | 95 } |
85 | 96 |
86 StreamContext* GetStreamContextForResourceContext( | 97 StreamContext* GetStreamContextForResourceContext( |
87 const ResourceContext* resource_context) { | 98 const ResourceContext* resource_context) { |
88 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 99 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
(...skipping 22 matching lines...) Expand all Loading... |
111 | 122 |
112 resource_context->SetUserData( | 123 resource_context->SetUserData( |
113 kStreamContextKeyName, | 124 kStreamContextKeyName, |
114 new UserDataAdapter<StreamContext>( | 125 new UserDataAdapter<StreamContext>( |
115 StreamContext::GetFor(browser_context))); | 126 StreamContext::GetFor(browser_context))); |
116 | 127 |
117 resource_context->DetachUserDataThread(); | 128 resource_context->DetachUserDataThread(); |
118 } | 129 } |
119 | 130 |
120 } // namespace content | 131 } // namespace content |
OLD | NEW |