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 <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
11 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
12 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/io_thread.h" | 15 #include "chrome/browser/io_thread.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile_io_data.h" | 17 #include "chrome/browser/profiles/profile_io_data.h" |
16 #include "chrome/browser/profiles/storage_partition_descriptor.h" | 18 #include "chrome/browser/profiles/storage_partition_descriptor.h" |
(...skipping 21 matching lines...) Expand all Loading... |
38 // ---------------------------------------------------------------------------- | 40 // ---------------------------------------------------------------------------- |
39 | 41 |
40 // Factory that creates the main URLRequestContext. | 42 // Factory that creates the main URLRequestContext. |
41 class FactoryForMain : public ChromeURLRequestContextFactory { | 43 class FactoryForMain : public ChromeURLRequestContextFactory { |
42 public: | 44 public: |
43 FactoryForMain( | 45 FactoryForMain( |
44 const ProfileIOData* profile_io_data, | 46 const ProfileIOData* profile_io_data, |
45 content::ProtocolHandlerMap* protocol_handlers, | 47 content::ProtocolHandlerMap* protocol_handlers, |
46 content::URLRequestInterceptorScopedVector request_interceptors) | 48 content::URLRequestInterceptorScopedVector request_interceptors) |
47 : profile_io_data_(profile_io_data), | 49 : profile_io_data_(profile_io_data), |
48 request_interceptors_(request_interceptors.Pass()) { | 50 request_interceptors_(std::move(request_interceptors)) { |
49 std::swap(protocol_handlers_, *protocol_handlers); | 51 std::swap(protocol_handlers_, *protocol_handlers); |
50 } | 52 } |
51 | 53 |
52 net::URLRequestContext* Create() override { | 54 net::URLRequestContext* Create() override { |
53 profile_io_data_->Init(&protocol_handlers_, request_interceptors_.Pass()); | 55 profile_io_data_->Init(&protocol_handlers_, |
| 56 std::move(request_interceptors_)); |
54 return profile_io_data_->GetMainRequestContext(); | 57 return profile_io_data_->GetMainRequestContext(); |
55 } | 58 } |
56 | 59 |
57 private: | 60 private: |
58 const ProfileIOData* const profile_io_data_; | 61 const ProfileIOData* const profile_io_data_; |
59 content::ProtocolHandlerMap protocol_handlers_; | 62 content::ProtocolHandlerMap protocol_handlers_; |
60 content::URLRequestInterceptorScopedVector request_interceptors_; | 63 content::URLRequestInterceptorScopedVector request_interceptors_; |
61 }; | 64 }; |
62 | 65 |
63 // Factory that creates the URLRequestContext for extensions. | 66 // Factory that creates the URLRequestContext for extensions. |
(...skipping 17 matching lines...) Expand all Loading... |
81 const ProfileIOData* profile_io_data, | 84 const ProfileIOData* profile_io_data, |
82 const StoragePartitionDescriptor& partition_descriptor, | 85 const StoragePartitionDescriptor& partition_descriptor, |
83 ChromeURLRequestContextGetter* main_context, | 86 ChromeURLRequestContextGetter* main_context, |
84 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 87 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
85 protocol_handler_interceptor, | 88 protocol_handler_interceptor, |
86 content::ProtocolHandlerMap* protocol_handlers, | 89 content::ProtocolHandlerMap* protocol_handlers, |
87 content::URLRequestInterceptorScopedVector request_interceptors) | 90 content::URLRequestInterceptorScopedVector request_interceptors) |
88 : profile_io_data_(profile_io_data), | 91 : profile_io_data_(profile_io_data), |
89 partition_descriptor_(partition_descriptor), | 92 partition_descriptor_(partition_descriptor), |
90 main_request_context_getter_(main_context), | 93 main_request_context_getter_(main_context), |
91 protocol_handler_interceptor_(protocol_handler_interceptor.Pass()), | 94 protocol_handler_interceptor_(std::move(protocol_handler_interceptor)), |
92 request_interceptors_(request_interceptors.Pass()) { | 95 request_interceptors_(std::move(request_interceptors)) { |
93 std::swap(protocol_handlers_, *protocol_handlers); | 96 std::swap(protocol_handlers_, *protocol_handlers); |
94 } | 97 } |
95 | 98 |
96 net::URLRequestContext* Create() override { | 99 net::URLRequestContext* Create() override { |
97 // We will copy most of the state from the main request context. | 100 // We will copy most of the state from the main request context. |
98 // | 101 // |
99 // Note that this factory is one-shot. After Create() is called once, the | 102 // Note that this factory is one-shot. After Create() is called once, the |
100 // factory is actually destroyed. Thus it is safe to destructively pass | 103 // factory is actually destroyed. Thus it is safe to destructively pass |
101 // state onwards. | 104 // state onwards. |
102 return profile_io_data_->GetIsolatedAppRequestContext( | 105 return profile_io_data_->GetIsolatedAppRequestContext( |
103 main_request_context_getter_->GetURLRequestContext(), | 106 main_request_context_getter_->GetURLRequestContext(), |
104 partition_descriptor_, | 107 partition_descriptor_, std::move(protocol_handler_interceptor_), |
105 protocol_handler_interceptor_.Pass(), | 108 &protocol_handlers_, std::move(request_interceptors_)); |
106 &protocol_handlers_, | |
107 request_interceptors_.Pass()); | |
108 } | 109 } |
109 | 110 |
110 private: | 111 private: |
111 const ProfileIOData* const profile_io_data_; | 112 const ProfileIOData* const profile_io_data_; |
112 const StoragePartitionDescriptor partition_descriptor_; | 113 const StoragePartitionDescriptor partition_descriptor_; |
113 scoped_refptr<ChromeURLRequestContextGetter> | 114 scoped_refptr<ChromeURLRequestContextGetter> |
114 main_request_context_getter_; | 115 main_request_context_getter_; |
115 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 116 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
116 protocol_handler_interceptor_; | 117 protocol_handler_interceptor_; |
117 content::ProtocolHandlerMap protocol_handlers_; | 118 content::ProtocolHandlerMap protocol_handlers_; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 209 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
209 } | 210 } |
210 | 211 |
211 // static | 212 // static |
212 ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::Create( | 213 ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::Create( |
213 Profile* profile, | 214 Profile* profile, |
214 const ProfileIOData* profile_io_data, | 215 const ProfileIOData* profile_io_data, |
215 content::ProtocolHandlerMap* protocol_handlers, | 216 content::ProtocolHandlerMap* protocol_handlers, |
216 content::URLRequestInterceptorScopedVector request_interceptors) { | 217 content::URLRequestInterceptorScopedVector request_interceptors) { |
217 return new ChromeURLRequestContextGetter(new FactoryForMain( | 218 return new ChromeURLRequestContextGetter(new FactoryForMain( |
218 profile_io_data, protocol_handlers, request_interceptors.Pass())); | 219 profile_io_data, protocol_handlers, std::move(request_interceptors))); |
219 } | 220 } |
220 | 221 |
221 // static | 222 // static |
222 ChromeURLRequestContextGetter* | 223 ChromeURLRequestContextGetter* |
223 ChromeURLRequestContextGetter::CreateForMedia( | 224 ChromeURLRequestContextGetter::CreateForMedia( |
224 Profile* profile, const ProfileIOData* profile_io_data) { | 225 Profile* profile, const ProfileIOData* profile_io_data) { |
225 return new ChromeURLRequestContextGetter( | 226 return new ChromeURLRequestContextGetter( |
226 new FactoryForMedia(profile_io_data)); | 227 new FactoryForMedia(profile_io_data)); |
227 } | 228 } |
228 | 229 |
(...skipping 10 matching lines...) Expand all Loading... |
239 ChromeURLRequestContextGetter::CreateForIsolatedApp( | 240 ChromeURLRequestContextGetter::CreateForIsolatedApp( |
240 Profile* profile, | 241 Profile* profile, |
241 const ProfileIOData* profile_io_data, | 242 const ProfileIOData* profile_io_data, |
242 const StoragePartitionDescriptor& partition_descriptor, | 243 const StoragePartitionDescriptor& partition_descriptor, |
243 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 244 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
244 protocol_handler_interceptor, | 245 protocol_handler_interceptor, |
245 content::ProtocolHandlerMap* protocol_handlers, | 246 content::ProtocolHandlerMap* protocol_handlers, |
246 content::URLRequestInterceptorScopedVector request_interceptors) { | 247 content::URLRequestInterceptorScopedVector request_interceptors) { |
247 ChromeURLRequestContextGetter* main_context = | 248 ChromeURLRequestContextGetter* main_context = |
248 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); | 249 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); |
249 return new ChromeURLRequestContextGetter( | 250 return new ChromeURLRequestContextGetter(new FactoryForIsolatedApp( |
250 new FactoryForIsolatedApp(profile_io_data, | 251 profile_io_data, partition_descriptor, main_context, |
251 partition_descriptor, | 252 std::move(protocol_handler_interceptor), protocol_handlers, |
252 main_context, | 253 std::move(request_interceptors))); |
253 protocol_handler_interceptor.Pass(), | |
254 protocol_handlers, | |
255 request_interceptors.Pass())); | |
256 } | 254 } |
257 | 255 |
258 // static | 256 // static |
259 ChromeURLRequestContextGetter* | 257 ChromeURLRequestContextGetter* |
260 ChromeURLRequestContextGetter::CreateForIsolatedMedia( | 258 ChromeURLRequestContextGetter::CreateForIsolatedMedia( |
261 Profile* profile, | 259 Profile* profile, |
262 ChromeURLRequestContextGetter* app_context, | 260 ChromeURLRequestContextGetter* app_context, |
263 const ProfileIOData* profile_io_data, | 261 const ProfileIOData* profile_io_data, |
264 const StoragePartitionDescriptor& partition_descriptor) { | 262 const StoragePartitionDescriptor& partition_descriptor) { |
265 return new ChromeURLRequestContextGetter( | 263 return new ChromeURLRequestContextGetter( |
266 new FactoryForIsolatedMedia( | 264 new FactoryForIsolatedMedia( |
267 profile_io_data, partition_descriptor, app_context)); | 265 profile_io_data, partition_descriptor, app_context)); |
268 } | 266 } |
OLD | NEW |