OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/net/chrome_url_request_context_getter.h" | 5 #include "chrome/browser/net/chrome_url_request_context_getter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/profiler/scoped_tracker.h" | |
12 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/io_thread.h" | 12 #include "chrome/browser/io_thread.h" |
14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile_io_data.h" | 14 #include "chrome/browser/profiles/profile_io_data.h" |
16 #include "chrome/browser/profiles/storage_partition_descriptor.h" | 15 #include "chrome/browser/profiles/storage_partition_descriptor.h" |
17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
18 #include "net/cookies/cookie_store.h" | 17 #include "net/cookies/cookie_store.h" |
19 | 18 |
20 using content::BrowserThread; | 19 using content::BrowserThread; |
21 | 20 |
(...skipping 21 matching lines...) Expand all Loading... |
43 FactoryForMain( | 42 FactoryForMain( |
44 const ProfileIOData* profile_io_data, | 43 const ProfileIOData* profile_io_data, |
45 content::ProtocolHandlerMap* protocol_handlers, | 44 content::ProtocolHandlerMap* protocol_handlers, |
46 content::URLRequestInterceptorScopedVector request_interceptors) | 45 content::URLRequestInterceptorScopedVector request_interceptors) |
47 : profile_io_data_(profile_io_data), | 46 : profile_io_data_(profile_io_data), |
48 request_interceptors_(request_interceptors.Pass()) { | 47 request_interceptors_(request_interceptors.Pass()) { |
49 std::swap(protocol_handlers_, *protocol_handlers); | 48 std::swap(protocol_handlers_, *protocol_handlers); |
50 } | 49 } |
51 | 50 |
52 net::URLRequestContext* Create() override { | 51 net::URLRequestContext* Create() override { |
53 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436671 is fixed. | |
54 tracked_objects::ScopedTracker tracking_profile( | |
55 FROM_HERE_WITH_EXPLICIT_FUNCTION("436671 FactoryForMain::Create")); | |
56 | |
57 profile_io_data_->Init(&protocol_handlers_, request_interceptors_.Pass()); | 52 profile_io_data_->Init(&protocol_handlers_, request_interceptors_.Pass()); |
58 return profile_io_data_->GetMainRequestContext(); | 53 return profile_io_data_->GetMainRequestContext(); |
59 } | 54 } |
60 | 55 |
61 private: | 56 private: |
62 const ProfileIOData* const profile_io_data_; | 57 const ProfileIOData* const profile_io_data_; |
63 content::ProtocolHandlerMap protocol_handlers_; | 58 content::ProtocolHandlerMap protocol_handlers_; |
64 content::URLRequestInterceptorScopedVector request_interceptors_; | 59 content::URLRequestInterceptorScopedVector request_interceptors_; |
65 }; | 60 }; |
66 | 61 |
67 // Factory that creates the URLRequestContext for extensions. | 62 // Factory that creates the URLRequestContext for extensions. |
68 class FactoryForExtensions : public ChromeURLRequestContextFactory { | 63 class FactoryForExtensions : public ChromeURLRequestContextFactory { |
69 public: | 64 public: |
70 explicit FactoryForExtensions(const ProfileIOData* profile_io_data) | 65 explicit FactoryForExtensions(const ProfileIOData* profile_io_data) |
71 : profile_io_data_(profile_io_data) {} | 66 : profile_io_data_(profile_io_data) {} |
72 | 67 |
73 net::URLRequestContext* Create() override { | 68 net::URLRequestContext* Create() override { |
74 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436671 is fixed. | |
75 tracked_objects::ScopedTracker tracking_profile( | |
76 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
77 "436671 FactoryForExtensions::Create")); | |
78 | |
79 return profile_io_data_->GetExtensionsRequestContext(); | 69 return profile_io_data_->GetExtensionsRequestContext(); |
80 } | 70 } |
81 | 71 |
82 private: | 72 private: |
83 const ProfileIOData* const profile_io_data_; | 73 const ProfileIOData* const profile_io_data_; |
84 }; | 74 }; |
85 | 75 |
86 // Factory that creates the URLRequestContext for a given isolated app. | 76 // Factory that creates the URLRequestContext for a given isolated app. |
87 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { | 77 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { |
88 public: | 78 public: |
89 FactoryForIsolatedApp( | 79 FactoryForIsolatedApp( |
90 const ProfileIOData* profile_io_data, | 80 const ProfileIOData* profile_io_data, |
91 const StoragePartitionDescriptor& partition_descriptor, | 81 const StoragePartitionDescriptor& partition_descriptor, |
92 ChromeURLRequestContextGetter* main_context, | 82 ChromeURLRequestContextGetter* main_context, |
93 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 83 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
94 protocol_handler_interceptor, | 84 protocol_handler_interceptor, |
95 content::ProtocolHandlerMap* protocol_handlers, | 85 content::ProtocolHandlerMap* protocol_handlers, |
96 content::URLRequestInterceptorScopedVector request_interceptors) | 86 content::URLRequestInterceptorScopedVector request_interceptors) |
97 : profile_io_data_(profile_io_data), | 87 : profile_io_data_(profile_io_data), |
98 partition_descriptor_(partition_descriptor), | 88 partition_descriptor_(partition_descriptor), |
99 main_request_context_getter_(main_context), | 89 main_request_context_getter_(main_context), |
100 protocol_handler_interceptor_(protocol_handler_interceptor.Pass()), | 90 protocol_handler_interceptor_(protocol_handler_interceptor.Pass()), |
101 request_interceptors_(request_interceptors.Pass()) { | 91 request_interceptors_(request_interceptors.Pass()) { |
102 std::swap(protocol_handlers_, *protocol_handlers); | 92 std::swap(protocol_handlers_, *protocol_handlers); |
103 } | 93 } |
104 | 94 |
105 net::URLRequestContext* Create() override { | 95 net::URLRequestContext* Create() override { |
106 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436671 is fixed. | |
107 tracked_objects::ScopedTracker tracking_profile( | |
108 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
109 "436671 FactoryForIsolatedApp::Create")); | |
110 | |
111 // We will copy most of the state from the main request context. | 96 // We will copy most of the state from the main request context. |
112 // | 97 // |
113 // Note that this factory is one-shot. After Create() is called once, the | 98 // Note that this factory is one-shot. After Create() is called once, the |
114 // factory is actually destroyed. Thus it is safe to destructively pass | 99 // factory is actually destroyed. Thus it is safe to destructively pass |
115 // state onwards. | 100 // state onwards. |
116 return profile_io_data_->GetIsolatedAppRequestContext( | 101 return profile_io_data_->GetIsolatedAppRequestContext( |
117 main_request_context_getter_->GetURLRequestContext(), | 102 main_request_context_getter_->GetURLRequestContext(), |
118 partition_descriptor_, | 103 partition_descriptor_, |
119 protocol_handler_interceptor_.Pass(), | 104 protocol_handler_interceptor_.Pass(), |
120 &protocol_handlers_, | 105 &protocol_handlers_, |
(...skipping 17 matching lines...) Expand all Loading... |
138 public: | 123 public: |
139 FactoryForIsolatedMedia( | 124 FactoryForIsolatedMedia( |
140 const ProfileIOData* profile_io_data, | 125 const ProfileIOData* profile_io_data, |
141 const StoragePartitionDescriptor& partition_descriptor, | 126 const StoragePartitionDescriptor& partition_descriptor, |
142 ChromeURLRequestContextGetter* app_context) | 127 ChromeURLRequestContextGetter* app_context) |
143 : profile_io_data_(profile_io_data), | 128 : profile_io_data_(profile_io_data), |
144 partition_descriptor_(partition_descriptor), | 129 partition_descriptor_(partition_descriptor), |
145 app_context_getter_(app_context) {} | 130 app_context_getter_(app_context) {} |
146 | 131 |
147 net::URLRequestContext* Create() override { | 132 net::URLRequestContext* Create() override { |
148 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436671 is fixed. | |
149 tracked_objects::ScopedTracker tracking_profile( | |
150 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
151 "436671 FactoryForIsolatedMedia::Create")); | |
152 | |
153 // We will copy most of the state from the corresopnding app's | 133 // We will copy most of the state from the corresopnding app's |
154 // request context. We expect to have the same lifetime as | 134 // request context. We expect to have the same lifetime as |
155 // the associated |app_context_getter_| so we can just reuse | 135 // the associated |app_context_getter_| so we can just reuse |
156 // all its backing objects, including the | 136 // all its backing objects, including the |
157 // |protocol_handler_interceptor|. This is why the API | 137 // |protocol_handler_interceptor|. This is why the API |
158 // looks different from FactoryForIsolatedApp's. | 138 // looks different from FactoryForIsolatedApp's. |
159 return profile_io_data_->GetIsolatedMediaRequestContext( | 139 return profile_io_data_->GetIsolatedMediaRequestContext( |
160 app_context_getter_->GetURLRequestContext(), partition_descriptor_); | 140 app_context_getter_->GetURLRequestContext(), partition_descriptor_); |
161 } | 141 } |
162 | 142 |
163 private: | 143 private: |
164 const ProfileIOData* const profile_io_data_; | 144 const ProfileIOData* const profile_io_data_; |
165 const StoragePartitionDescriptor partition_descriptor_; | 145 const StoragePartitionDescriptor partition_descriptor_; |
166 scoped_refptr<ChromeURLRequestContextGetter> app_context_getter_; | 146 scoped_refptr<ChromeURLRequestContextGetter> app_context_getter_; |
167 }; | 147 }; |
168 | 148 |
169 // Factory that creates the URLRequestContext for media. | 149 // Factory that creates the URLRequestContext for media. |
170 class FactoryForMedia : public ChromeURLRequestContextFactory { | 150 class FactoryForMedia : public ChromeURLRequestContextFactory { |
171 public: | 151 public: |
172 explicit FactoryForMedia(const ProfileIOData* profile_io_data) | 152 explicit FactoryForMedia(const ProfileIOData* profile_io_data) |
173 : profile_io_data_(profile_io_data) { | 153 : profile_io_data_(profile_io_data) { |
174 } | 154 } |
175 | 155 |
176 net::URLRequestContext* Create() override { | 156 net::URLRequestContext* Create() override { |
177 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436671 is fixed. | |
178 tracked_objects::ScopedTracker tracking_profile( | |
179 FROM_HERE_WITH_EXPLICIT_FUNCTION("436671 FactoryForMedia::Create")); | |
180 | |
181 return profile_io_data_->GetMediaRequestContext(); | 157 return profile_io_data_->GetMediaRequestContext(); |
182 } | 158 } |
183 | 159 |
184 private: | 160 private: |
185 const ProfileIOData* const profile_io_data_; | 161 const ProfileIOData* const profile_io_data_; |
186 }; | 162 }; |
187 | 163 |
188 } // namespace | 164 } // namespace |
189 | 165 |
190 // ---------------------------------------------------------------------------- | 166 // ---------------------------------------------------------------------------- |
191 // ChromeURLRequestContextGetter | 167 // ChromeURLRequestContextGetter |
192 // ---------------------------------------------------------------------------- | 168 // ---------------------------------------------------------------------------- |
193 | 169 |
194 ChromeURLRequestContextGetter::ChromeURLRequestContextGetter( | 170 ChromeURLRequestContextGetter::ChromeURLRequestContextGetter( |
195 ChromeURLRequestContextFactory* factory) | 171 ChromeURLRequestContextFactory* factory) |
196 : factory_(factory), | 172 : factory_(factory), |
197 url_request_context_(NULL) { | 173 url_request_context_(NULL) { |
198 DCHECK(factory); | 174 DCHECK(factory); |
199 } | 175 } |
200 | 176 |
201 ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() {} | 177 ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() {} |
202 | 178 |
203 // Lazily create a URLRequestContext using our factory. | 179 // Lazily create a URLRequestContext using our factory. |
204 net::URLRequestContext* | 180 net::URLRequestContext* |
205 ChromeURLRequestContextGetter::GetURLRequestContext() { | 181 ChromeURLRequestContextGetter::GetURLRequestContext() { |
206 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436671 is fixed. | |
207 tracked_objects::ScopedTracker tracking_profile( | |
208 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
209 "436671 ChromeURLRequestContextGetter::GetURLRequestContext")); | |
210 | |
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
212 | 183 |
213 if (factory_.get()) { | 184 if (factory_.get()) { |
214 DCHECK(!url_request_context_); | 185 DCHECK(!url_request_context_); |
215 url_request_context_ = factory_->Create(); | 186 url_request_context_ = factory_->Create(); |
216 factory_.reset(); | 187 factory_.reset(); |
217 } | 188 } |
218 | 189 |
219 // Context reference is valid, unless we're trying to use the | 190 // Context reference is valid, unless we're trying to use the |
220 // URLRequestContextGetter after the Profile has already been deleted. | 191 // URLRequestContextGetter after the Profile has already been deleted. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 ChromeURLRequestContextGetter* | 256 ChromeURLRequestContextGetter* |
286 ChromeURLRequestContextGetter::CreateForIsolatedMedia( | 257 ChromeURLRequestContextGetter::CreateForIsolatedMedia( |
287 Profile* profile, | 258 Profile* profile, |
288 ChromeURLRequestContextGetter* app_context, | 259 ChromeURLRequestContextGetter* app_context, |
289 const ProfileIOData* profile_io_data, | 260 const ProfileIOData* profile_io_data, |
290 const StoragePartitionDescriptor& partition_descriptor) { | 261 const StoragePartitionDescriptor& partition_descriptor) { |
291 return new ChromeURLRequestContextGetter( | 262 return new ChromeURLRequestContextGetter( |
292 new FactoryForIsolatedMedia( | 263 new FactoryForIsolatedMedia( |
293 profile_io_data, partition_descriptor, app_context)); | 264 profile_io_data, partition_descriptor, app_context)); |
294 } | 265 } |
OLD | NEW |