Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/browser/net/chrome_url_request_context.cc

Issue 10969017: Create a new URLRequestJobFactory for isolated request contexts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment fixes. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 109 // Takes the |main_context| for the profile so that it can find or create the
Charlie Reis 2012/09/20 22:57:46 Update this comment.
awong 2012/09/20 23:16:46 Done.
100 // isolated app's context if necessary. 110 // isolated app's context if necessary.
101 class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory { 111 class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory {
102 public: 112 public:
103 FactoryForIsolatedMedia(const ProfileIOData* profile_io_data, 113 FactoryForIsolatedMedia(const ProfileIOData* profile_io_data,
104 const std::string& app_id, 114 const std::string& app_id,
105 ChromeURLRequestContextGetter* main_context) 115 ChromeURLRequestContextGetter* app_context)
106 : profile_io_data_(profile_io_data), 116 : profile_io_data_(profile_io_data),
107 app_id_(app_id), 117 app_id_(app_id),
108 main_request_context_getter_(main_context) {} 118 app_context_getter_(app_context) {}
109 119
110 virtual ChromeURLRequestContext* Create() OVERRIDE { 120 virtual ChromeURLRequestContext* Create() OVERRIDE {
111 // We will copy most of the state from the corresopnding app's 121 // We will copy most of the state from the corresopnding app's
112 // request context, which we obtain using the main context. 122 // request context. We expect to have the same lifetime as
123 // the associated |app_context_getter_| so we can just reuse
124 // all its backing objects, including the
125 // |protocol_handler_interceptor|. This is why the API
126 // looks different from FactoryForIsolatedApp's.
113 return profile_io_data_->GetIsolatedMediaRequestContext( 127 return profile_io_data_->GetIsolatedMediaRequestContext(
114 main_request_context_getter_->GetIOContext(), app_id_); 128 app_context_getter_->GetIOContext(), app_id_);
115 } 129 }
116 130
117 private: 131 private:
118 const ProfileIOData* const profile_io_data_; 132 const ProfileIOData* const profile_io_data_;
119 const std::string app_id_; 133 const std::string app_id_;
120 scoped_refptr<ChromeURLRequestContextGetter> 134 scoped_refptr<ChromeURLRequestContextGetter> app_context_getter_;
121 main_request_context_getter_;
122 }; 135 };
123 136
124 // Factory that creates the ChromeURLRequestContext for media. 137 // Factory that creates the ChromeURLRequestContext for media.
125 class FactoryForMedia : public ChromeURLRequestContextFactory { 138 class FactoryForMedia : public ChromeURLRequestContextFactory {
126 public: 139 public:
127 explicit FactoryForMedia(const ProfileIOData* profile_io_data) 140 explicit FactoryForMedia(const ProfileIOData* profile_io_data)
128 : profile_io_data_(profile_io_data) { 141 : profile_io_data_(profile_io_data) {
129 } 142 }
130 143
131 virtual ChromeURLRequestContext* Create() OVERRIDE { 144 virtual ChromeURLRequestContext* Create() OVERRIDE {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 return new ChromeURLRequestContextGetter( 220 return new ChromeURLRequestContextGetter(
208 profile, 221 profile,
209 new FactoryForExtensions(profile_io_data)); 222 new FactoryForExtensions(profile_io_data));
210 } 223 }
211 224
212 // static 225 // static
213 ChromeURLRequestContextGetter* 226 ChromeURLRequestContextGetter*
214 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( 227 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp(
215 Profile* profile, 228 Profile* profile,
216 const ProfileIOData* profile_io_data, 229 const ProfileIOData* profile_io_data,
217 const std::string& app_id) { 230 const std::string& app_id,
231 scoped_ptr<net::URLRequestJobFactory::Interceptor>
232 protocol_handler_interceptor) {
218 DCHECK(!profile->IsOffTheRecord()); 233 DCHECK(!profile->IsOffTheRecord());
219 ChromeURLRequestContextGetter* main_context = 234 ChromeURLRequestContextGetter* main_context =
220 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); 235 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext());
221 return new ChromeURLRequestContextGetter( 236 return new ChromeURLRequestContextGetter(
222 profile, 237 profile,
223 new FactoryForIsolatedApp(profile_io_data, app_id, main_context)); 238 new FactoryForIsolatedApp(profile_io_data, app_id, main_context,
239 protocol_handler_interceptor.Pass()));
224 } 240 }
225 241
226 // static 242 // static
227 ChromeURLRequestContextGetter* 243 ChromeURLRequestContextGetter*
228 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( 244 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia(
229 Profile* profile, 245 Profile* profile,
246 ChromeURLRequestContextGetter* app_context,
230 const ProfileIOData* profile_io_data, 247 const ProfileIOData* profile_io_data,
231 const std::string& app_id) { 248 const std::string& app_id) {
232 DCHECK(!profile->IsOffTheRecord()); 249 DCHECK(!profile->IsOffTheRecord());
233 ChromeURLRequestContextGetter* main_context =
234 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext());
235 return new ChromeURLRequestContextGetter( 250 return new ChromeURLRequestContextGetter(
236 profile, 251 profile,
237 new FactoryForIsolatedMedia(profile_io_data, app_id, main_context)); 252 new FactoryForIsolatedMedia(profile_io_data, app_id, app_context));
238 } 253 }
239 254
240 // static 255 // static
241 ChromeURLRequestContextGetter* 256 ChromeURLRequestContextGetter*
242 ChromeURLRequestContextGetter::CreateOffTheRecord( 257 ChromeURLRequestContextGetter::CreateOffTheRecord(
243 Profile* profile, const ProfileIOData* profile_io_data) { 258 Profile* profile, const ProfileIOData* profile_io_data) {
244 DCHECK(profile->IsOffTheRecord()); 259 DCHECK(profile->IsOffTheRecord());
245 return new ChromeURLRequestContextGetter( 260 return new ChromeURLRequestContextGetter(
246 profile, new FactoryForMain(profile_io_data)); 261 profile, new FactoryForMain(profile_io_data));
247 } 262 }
248 263
249 // static 264 // static
250 ChromeURLRequestContextGetter* 265 ChromeURLRequestContextGetter*
251 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( 266 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(
252 Profile* profile, const ProfileIOData* profile_io_data) { 267 Profile* profile, const ProfileIOData* profile_io_data) {
253 DCHECK(profile->IsOffTheRecord()); 268 DCHECK(profile->IsOffTheRecord());
254 return new ChromeURLRequestContextGetter( 269 return new ChromeURLRequestContextGetter(
255 profile, new FactoryForExtensions(profile_io_data)); 270 profile, new FactoryForExtensions(profile_io_data));
256 } 271 }
257 272
258 // static 273 // static
259 ChromeURLRequestContextGetter* 274 ChromeURLRequestContextGetter*
260 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( 275 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp(
261 Profile* profile, 276 Profile* profile,
262 const ProfileIOData* profile_io_data, 277 const ProfileIOData* profile_io_data,
263 const std::string& app_id) { 278 const std::string& app_id,
279 scoped_ptr<net::URLRequestJobFactory::Interceptor>
280 protocol_handler_interceptor) {
264 DCHECK(profile->IsOffTheRecord()); 281 DCHECK(profile->IsOffTheRecord());
265 ChromeURLRequestContextGetter* main_context = 282 ChromeURLRequestContextGetter* main_context =
266 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); 283 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext());
267 return new ChromeURLRequestContextGetter( 284 return new ChromeURLRequestContextGetter(
268 profile, 285 profile,
269 new FactoryForIsolatedApp(profile_io_data, app_id, main_context)); 286 new FactoryForIsolatedApp(profile_io_data, app_id, main_context,
287 protocol_handler_interceptor.Pass()));
270 } 288 }
271 289
272 void ChromeURLRequestContextGetter::CleanupOnUIThread() { 290 void ChromeURLRequestContextGetter::CleanupOnUIThread() {
273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
274 // Unregister for pref notifications. 292 // Unregister for pref notifications.
275 DCHECK(!registrar_.IsEmpty()) << "Called more than once!"; 293 DCHECK(!registrar_.IsEmpty()) << "Called more than once!";
276 registrar_.RemoveAll(); 294 registrar_.RemoveAll();
277 } 295 }
278 296
279 // content::NotificationObserver implementation. 297 // content::NotificationObserver implementation.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); 398 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language));
381 } 399 }
382 400
383 void ChromeURLRequestContext::OnDefaultCharsetChange( 401 void ChromeURLRequestContext::OnDefaultCharsetChange(
384 const std::string& default_charset) { 402 const std::string& default_charset) {
385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
386 set_referrer_charset(default_charset); 404 set_referrer_charset(default_charset);
387 set_accept_charset( 405 set_accept_charset(
388 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); 406 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset));
389 } 407 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698