| 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 | 19 |
| 22 using base::UserDataAdapter; | 20 using base::UserDataAdapter; |
| 23 | 21 |
| 24 namespace content { | 22 namespace content { |
| 25 | 23 |
| 26 // Key names on ResourceContext. | 24 // Key names on ResourceContext. |
| 27 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; | 25 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; |
| 28 const char kStreamContextKeyName[] = "content_stream_context"; | 26 const char kStreamContextKeyName[] = "content_stream_context"; |
| 29 const char kURLDataManagerBackendKeyName[] = "url_data_manager_backend"; | 27 const char kURLDataManagerBackendKeyName[] = "url_data_manager_backend"; |
| 30 | 28 |
| 31 ResourceContext::ResourceContext() | 29 ResourceContext::ResourceContext() {} |
| 32 : media_device_id_salt_(CreateRandomMediaDeviceIDSalt()) { | |
| 33 } | |
| 34 | 30 |
| 35 ResourceContext::~ResourceContext() { | 31 ResourceContext::~ResourceContext() { |
| 36 if (ResourceDispatcherHostImpl::Get()) | 32 if (ResourceDispatcherHostImpl::Get()) |
| 37 ResourceDispatcherHostImpl::Get()->CancelRequestsForContext(this); | 33 ResourceDispatcherHostImpl::Get()->CancelRequestsForContext(this); |
| 38 } | 34 } |
| 39 | 35 |
| 40 std::string ResourceContext::GetMediaDeviceIDSalt() { | |
| 41 return media_device_id_salt_; | |
| 42 } | |
| 43 | |
| 44 // static | |
| 45 std::string ResourceContext::CreateRandomMediaDeviceIDSalt() { | |
| 46 std::string salt; | |
| 47 base::Base64Encode(base::RandBytesAsString(16), &salt); | |
| 48 DCHECK(!salt.empty()); | |
| 49 return salt; | |
| 50 } | |
| 51 | |
| 52 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( | 36 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( |
| 53 const ResourceContext* resource_context) { | 37 const ResourceContext* resource_context) { |
| 54 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 38 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 55 return UserDataAdapter<ChromeBlobStorageContext>::Get( | 39 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
| 56 resource_context, kBlobStorageContextKeyName); | 40 resource_context, kBlobStorageContextKeyName); |
| 57 } | 41 } |
| 58 | 42 |
| 59 StreamContext* GetStreamContextForResourceContext( | 43 StreamContext* GetStreamContextForResourceContext( |
| 60 const ResourceContext* resource_context) { | 44 const ResourceContext* resource_context) { |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 45 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 84 | 68 |
| 85 resource_context->SetUserData( | 69 resource_context->SetUserData( |
| 86 kStreamContextKeyName, | 70 kStreamContextKeyName, |
| 87 new UserDataAdapter<StreamContext>( | 71 new UserDataAdapter<StreamContext>( |
| 88 StreamContext::GetFor(browser_context))); | 72 StreamContext::GetFor(browser_context))); |
| 89 | 73 |
| 90 resource_context->DetachFromSequence(); | 74 resource_context->DetachFromSequence(); |
| 91 } | 75 } |
| 92 | 76 |
| 93 } // namespace content | 77 } // namespace content |
| OLD | NEW |