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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 8 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
9 #include "content/browser/host_zoom_map_impl.h" | |
10 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 9 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
11 #include "content/browser/loader/resource_request_info_impl.h" | 10 #include "content/browser/loader/resource_request_info_impl.h" |
12 #include "content/browser/streams/stream_context.h" | 11 #include "content/browser/streams/stream_context.h" |
13 #include "content/browser/webui/url_data_manager_backend.h" | 12 #include "content/browser/webui/url_data_manager_backend.h" |
14 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
15 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
16 #include "net/base/keygen_handler.h" | 15 #include "net/base/keygen_handler.h" |
17 #include "net/ssl/client_cert_store.h" | 16 #include "net/ssl/client_cert_store.h" |
18 | 17 |
19 using base::UserDataAdapter; | 18 using base::UserDataAdapter; |
20 | 19 |
21 namespace content { | 20 namespace content { |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 // Key names on ResourceContext. | 24 // Key names on ResourceContext. |
26 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; | 25 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; |
27 const char kHostZoomMapKeyName[] = "content_host_zoom_map"; | |
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 class NonOwningZoomData : public base::SupportsUserData::Data { | |
32 public: | |
33 explicit NonOwningZoomData(HostZoomMap* hzm) : host_zoom_map_(hzm) {} | |
34 HostZoomMap* host_zoom_map() { return host_zoom_map_; } | |
35 | |
36 private: | |
37 HostZoomMap* host_zoom_map_; | |
38 }; | |
39 | |
40 // Used by the default implementation of GetMediaDeviceIDSalt, below. | 29 // Used by the default implementation of GetMediaDeviceIDSalt, below. |
41 std::string ReturnEmptySalt() { | 30 std::string ReturnEmptySalt() { |
42 return std::string(); | 31 return std::string(); |
43 } | 32 } |
44 | 33 |
45 } // namespace | 34 } // namespace |
46 | 35 |
47 | 36 |
48 ResourceContext::ResourceContext() { | 37 ResourceContext::ResourceContext() { |
49 if (ResourceDispatcherHostImpl::Get()) | 38 if (ResourceDispatcherHostImpl::Get()) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 resource_context, kBlobStorageContextKeyName); | 74 resource_context, kBlobStorageContextKeyName); |
86 } | 75 } |
87 | 76 |
88 StreamContext* GetStreamContextForResourceContext( | 77 StreamContext* GetStreamContextForResourceContext( |
89 ResourceContext* resource_context) { | 78 ResourceContext* resource_context) { |
90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
91 return UserDataAdapter<StreamContext>::Get( | 80 return UserDataAdapter<StreamContext>::Get( |
92 resource_context, kStreamContextKeyName); | 81 resource_context, kStreamContextKeyName); |
93 } | 82 } |
94 | 83 |
95 HostZoomMap* GetHostZoomMapForResourceContext(ResourceContext* context) { | |
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
97 NonOwningZoomData* result = static_cast<NonOwningZoomData*>( | |
98 context->GetUserData(kHostZoomMapKeyName)); | |
99 if (!result) | |
100 return NULL; | |
101 return result->host_zoom_map(); | |
102 } | |
103 | |
104 URLDataManagerBackend* GetURLDataManagerForResourceContext( | 84 URLDataManagerBackend* GetURLDataManagerForResourceContext( |
105 ResourceContext* context) { | 85 ResourceContext* context) { |
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
107 if (!context->GetUserData(kURLDataManagerBackendKeyName)) { | 87 if (!context->GetUserData(kURLDataManagerBackendKeyName)) { |
108 context->SetUserData(kURLDataManagerBackendKeyName, | 88 context->SetUserData(kURLDataManagerBackendKeyName, |
109 new URLDataManagerBackend()); | 89 new URLDataManagerBackend()); |
110 } | 90 } |
111 return static_cast<URLDataManagerBackend*>( | 91 return static_cast<URLDataManagerBackend*>( |
112 context->GetUserData(kURLDataManagerBackendKeyName)); | 92 context->GetUserData(kURLDataManagerBackendKeyName)); |
113 } | 93 } |
114 | 94 |
115 void InitializeResourceContext(BrowserContext* browser_context) { | 95 void InitializeResourceContext(BrowserContext* browser_context) { |
116 ResourceContext* resource_context = browser_context->GetResourceContext(); | 96 ResourceContext* resource_context = browser_context->GetResourceContext(); |
117 DCHECK(!resource_context->GetUserData(kHostZoomMapKeyName)); | |
118 | 97 |
119 resource_context->SetUserData( | 98 resource_context->SetUserData( |
120 kBlobStorageContextKeyName, | 99 kBlobStorageContextKeyName, |
121 new UserDataAdapter<ChromeBlobStorageContext>( | 100 new UserDataAdapter<ChromeBlobStorageContext>( |
122 ChromeBlobStorageContext::GetFor(browser_context))); | 101 ChromeBlobStorageContext::GetFor(browser_context))); |
123 | 102 |
124 resource_context->SetUserData( | 103 resource_context->SetUserData( |
125 kStreamContextKeyName, | 104 kStreamContextKeyName, |
126 new UserDataAdapter<StreamContext>( | 105 new UserDataAdapter<StreamContext>( |
127 StreamContext::GetFor(browser_context))); | 106 StreamContext::GetFor(browser_context))); |
128 | 107 |
129 // This object is owned by the BrowserContext and not ResourceContext, so | |
130 // store a non-owning pointer here. | |
131 resource_context->SetUserData( | |
132 kHostZoomMapKeyName, | |
133 new NonOwningZoomData( | |
134 HostZoomMap::GetDefaultForBrowserContext(browser_context))); | |
135 | |
136 resource_context->DetachUserDataThread(); | 108 resource_context->DetachUserDataThread(); |
137 } | 109 } |
138 | 110 |
139 } // namespace content | 111 } // namespace content |
OLD | NEW |