| 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 "chrome/browser/net/chrome_url_request_context.h" | 5 #include "chrome/browser/net/chrome_url_request_context.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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 const ProfileIOData* const profile_io_data_; | 71 const ProfileIOData* const profile_io_data_; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // Factory that creates the ChromeURLRequestContext for a given isolated app. | 74 // Factory that creates the ChromeURLRequestContext for a given isolated app. |
| 75 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { | 75 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { |
| 76 public: | 76 public: |
| 77 FactoryForIsolatedApp(const ProfileIOData* profile_io_data, | 77 FactoryForIsolatedApp(const ProfileIOData* profile_io_data, |
| 78 const std::string& app_id, | 78 const std::string& app_id, |
| 79 ChromeURLRequestContextGetter* main_context) | 79 ChromeURLRequestContextGetter* main_context, |
| 80 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 81 protocol_handler_interceptor) |
| 80 : profile_io_data_(profile_io_data), | 82 : profile_io_data_(profile_io_data), |
| 81 app_id_(app_id), | 83 app_id_(app_id), |
| 82 main_request_context_getter_(main_context) {} | 84 main_request_context_getter_(main_context), |
| 85 protocol_handler_interceptor_(protocol_handler_interceptor.Pass()) {} |
| 83 | 86 |
| 84 virtual ChromeURLRequestContext* Create() OVERRIDE { | 87 virtual ChromeURLRequestContext* Create() OVERRIDE { |
| 85 // We will copy most of the state from the main request context. | 88 // We will copy most of the state from the main request context. |
| 89 // |
| 90 // Note that this factory is one-shot. After Create() is called once, the |
| 91 // factory is actually destroyed. Thus it is safe to destructively pass |
| 92 // state onwards. |
| 86 return profile_io_data_->GetIsolatedAppRequestContext( | 93 return profile_io_data_->GetIsolatedAppRequestContext( |
| 87 main_request_context_getter_->GetIOContext(), app_id_); | 94 main_request_context_getter_->GetIOContext(), app_id_, |
| 95 protocol_handler_interceptor_.Pass()); |
| 88 } | 96 } |
| 89 | 97 |
| 90 private: | 98 private: |
| 91 const ProfileIOData* const profile_io_data_; | 99 const ProfileIOData* const profile_io_data_; |
| 92 const std::string app_id_; | 100 const std::string app_id_; |
| 93 scoped_refptr<ChromeURLRequestContextGetter> | 101 scoped_refptr<ChromeURLRequestContextGetter> |
| 94 main_request_context_getter_; | 102 main_request_context_getter_; |
| 103 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 104 protocol_handler_interceptor_; |
| 95 }; | 105 }; |
| 96 | 106 |
| 97 // Factory that creates the media ChromeURLRequestContext for a given isolated | 107 // Factory that creates the media ChromeURLRequestContext for a given isolated |
| 98 // app. The media context is based on the corresponding isolated app's context. | 108 // app. The media context is based on the corresponding isolated app's context. |
| 99 // Takes the |main_context| for the profile so that it can find or create the | |
| 100 // isolated app's context if necessary. | |
| 101 class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory { | 109 class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory { |
| 102 public: | 110 public: |
| 103 FactoryForIsolatedMedia(const ProfileIOData* profile_io_data, | 111 FactoryForIsolatedMedia(const ProfileIOData* profile_io_data, |
| 104 const std::string& app_id, | 112 const std::string& app_id, |
| 105 ChromeURLRequestContextGetter* main_context) | 113 ChromeURLRequestContextGetter* app_context) |
| 106 : profile_io_data_(profile_io_data), | 114 : profile_io_data_(profile_io_data), |
| 107 app_id_(app_id), | 115 app_id_(app_id), |
| 108 main_request_context_getter_(main_context) {} | 116 app_context_getter_(app_context) {} |
| 109 | 117 |
| 110 virtual ChromeURLRequestContext* Create() OVERRIDE { | 118 virtual ChromeURLRequestContext* Create() OVERRIDE { |
| 111 // We will copy most of the state from the corresopnding app's | 119 // We will copy most of the state from the corresopnding app's |
| 112 // request context, which we obtain using the main context. | 120 // request context. We expect to have the same lifetime as |
| 121 // the associated |app_context_getter_| so we can just reuse |
| 122 // all its backing objects, including the |
| 123 // |protocol_handler_interceptor|. This is why the API |
| 124 // looks different from FactoryForIsolatedApp's. |
| 113 return profile_io_data_->GetIsolatedMediaRequestContext( | 125 return profile_io_data_->GetIsolatedMediaRequestContext( |
| 114 main_request_context_getter_->GetIOContext(), app_id_); | 126 app_context_getter_->GetIOContext(), app_id_); |
| 115 } | 127 } |
| 116 | 128 |
| 117 private: | 129 private: |
| 118 const ProfileIOData* const profile_io_data_; | 130 const ProfileIOData* const profile_io_data_; |
| 119 const std::string app_id_; | 131 const std::string app_id_; |
| 120 scoped_refptr<ChromeURLRequestContextGetter> | 132 scoped_refptr<ChromeURLRequestContextGetter> app_context_getter_; |
| 121 main_request_context_getter_; | |
| 122 }; | 133 }; |
| 123 | 134 |
| 124 // Factory that creates the ChromeURLRequestContext for media. | 135 // Factory that creates the ChromeURLRequestContext for media. |
| 125 class FactoryForMedia : public ChromeURLRequestContextFactory { | 136 class FactoryForMedia : public ChromeURLRequestContextFactory { |
| 126 public: | 137 public: |
| 127 explicit FactoryForMedia(const ProfileIOData* profile_io_data) | 138 explicit FactoryForMedia(const ProfileIOData* profile_io_data) |
| 128 : profile_io_data_(profile_io_data) { | 139 : profile_io_data_(profile_io_data) { |
| 129 } | 140 } |
| 130 | 141 |
| 131 virtual ChromeURLRequestContext* Create() OVERRIDE { | 142 virtual ChromeURLRequestContext* Create() OVERRIDE { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 return new ChromeURLRequestContextGetter( | 218 return new ChromeURLRequestContextGetter( |
| 208 profile, | 219 profile, |
| 209 new FactoryForExtensions(profile_io_data)); | 220 new FactoryForExtensions(profile_io_data)); |
| 210 } | 221 } |
| 211 | 222 |
| 212 // static | 223 // static |
| 213 ChromeURLRequestContextGetter* | 224 ChromeURLRequestContextGetter* |
| 214 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( | 225 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( |
| 215 Profile* profile, | 226 Profile* profile, |
| 216 const ProfileIOData* profile_io_data, | 227 const ProfileIOData* profile_io_data, |
| 217 const std::string& app_id) { | 228 const std::string& app_id, |
| 229 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 230 protocol_handler_interceptor) { |
| 218 DCHECK(!profile->IsOffTheRecord()); | 231 DCHECK(!profile->IsOffTheRecord()); |
| 219 ChromeURLRequestContextGetter* main_context = | 232 ChromeURLRequestContextGetter* main_context = |
| 220 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); | 233 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); |
| 221 return new ChromeURLRequestContextGetter( | 234 return new ChromeURLRequestContextGetter( |
| 222 profile, | 235 profile, |
| 223 new FactoryForIsolatedApp(profile_io_data, app_id, main_context)); | 236 new FactoryForIsolatedApp(profile_io_data, app_id, main_context, |
| 237 protocol_handler_interceptor.Pass())); |
| 224 } | 238 } |
| 225 | 239 |
| 226 // static | 240 // static |
| 227 ChromeURLRequestContextGetter* | 241 ChromeURLRequestContextGetter* |
| 228 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( | 242 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( |
| 229 Profile* profile, | 243 Profile* profile, |
| 244 ChromeURLRequestContextGetter* app_context, |
| 230 const ProfileIOData* profile_io_data, | 245 const ProfileIOData* profile_io_data, |
| 231 const std::string& app_id) { | 246 const std::string& app_id) { |
| 232 DCHECK(!profile->IsOffTheRecord()); | 247 DCHECK(!profile->IsOffTheRecord()); |
| 233 ChromeURLRequestContextGetter* main_context = | |
| 234 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); | |
| 235 return new ChromeURLRequestContextGetter( | 248 return new ChromeURLRequestContextGetter( |
| 236 profile, | 249 profile, |
| 237 new FactoryForIsolatedMedia(profile_io_data, app_id, main_context)); | 250 new FactoryForIsolatedMedia(profile_io_data, app_id, app_context)); |
| 238 } | 251 } |
| 239 | 252 |
| 240 // static | 253 // static |
| 241 ChromeURLRequestContextGetter* | 254 ChromeURLRequestContextGetter* |
| 242 ChromeURLRequestContextGetter::CreateOffTheRecord( | 255 ChromeURLRequestContextGetter::CreateOffTheRecord( |
| 243 Profile* profile, const ProfileIOData* profile_io_data) { | 256 Profile* profile, const ProfileIOData* profile_io_data) { |
| 244 DCHECK(profile->IsOffTheRecord()); | 257 DCHECK(profile->IsOffTheRecord()); |
| 245 return new ChromeURLRequestContextGetter( | 258 return new ChromeURLRequestContextGetter( |
| 246 profile, new FactoryForMain(profile_io_data)); | 259 profile, new FactoryForMain(profile_io_data)); |
| 247 } | 260 } |
| 248 | 261 |
| 249 // static | 262 // static |
| 250 ChromeURLRequestContextGetter* | 263 ChromeURLRequestContextGetter* |
| 251 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( | 264 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( |
| 252 Profile* profile, const ProfileIOData* profile_io_data) { | 265 Profile* profile, const ProfileIOData* profile_io_data) { |
| 253 DCHECK(profile->IsOffTheRecord()); | 266 DCHECK(profile->IsOffTheRecord()); |
| 254 return new ChromeURLRequestContextGetter( | 267 return new ChromeURLRequestContextGetter( |
| 255 profile, new FactoryForExtensions(profile_io_data)); | 268 profile, new FactoryForExtensions(profile_io_data)); |
| 256 } | 269 } |
| 257 | 270 |
| 258 // static | 271 // static |
| 259 ChromeURLRequestContextGetter* | 272 ChromeURLRequestContextGetter* |
| 260 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( | 273 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( |
| 261 Profile* profile, | 274 Profile* profile, |
| 262 const ProfileIOData* profile_io_data, | 275 const ProfileIOData* profile_io_data, |
| 263 const std::string& app_id) { | 276 const std::string& app_id, |
| 277 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 278 protocol_handler_interceptor) { |
| 264 DCHECK(profile->IsOffTheRecord()); | 279 DCHECK(profile->IsOffTheRecord()); |
| 265 ChromeURLRequestContextGetter* main_context = | 280 ChromeURLRequestContextGetter* main_context = |
| 266 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); | 281 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); |
| 267 return new ChromeURLRequestContextGetter( | 282 return new ChromeURLRequestContextGetter( |
| 268 profile, | 283 profile, |
| 269 new FactoryForIsolatedApp(profile_io_data, app_id, main_context)); | 284 new FactoryForIsolatedApp(profile_io_data, app_id, main_context, |
| 285 protocol_handler_interceptor.Pass())); |
| 270 } | 286 } |
| 271 | 287 |
| 272 void ChromeURLRequestContextGetter::CleanupOnUIThread() { | 288 void ChromeURLRequestContextGetter::CleanupOnUIThread() { |
| 273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 274 // Unregister for pref notifications. | 290 // Unregister for pref notifications. |
| 275 DCHECK(!registrar_.IsEmpty()) << "Called more than once!"; | 291 DCHECK(!registrar_.IsEmpty()) << "Called more than once!"; |
| 276 registrar_.RemoveAll(); | 292 registrar_.RemoveAll(); |
| 277 } | 293 } |
| 278 | 294 |
| 279 // content::NotificationObserver implementation. | 295 // content::NotificationObserver implementation. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); | 396 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); |
| 381 } | 397 } |
| 382 | 398 |
| 383 void ChromeURLRequestContext::OnDefaultCharsetChange( | 399 void ChromeURLRequestContext::OnDefaultCharsetChange( |
| 384 const std::string& default_charset) { | 400 const std::string& default_charset) { |
| 385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 386 set_referrer_charset(default_charset); | 402 set_referrer_charset(default_charset); |
| 387 set_accept_charset( | 403 set_accept_charset( |
| 388 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); | 404 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); |
| 389 } | 405 } |
| OLD | NEW |