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

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

Issue 11147026: Initial refactor to get profiles to propagate storage partition details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changing bool param to pass by reference. Created 8 years, 2 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"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/io_thread.h" 12 #include "chrome/browser/io_thread.h"
13 #include "chrome/browser/net/load_time_stats.h" 13 #include "chrome/browser/net/load_time_stats.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_io_data.h" 16 #include "chrome/browser/profiles/profile_io_data.h"
17 #include "chrome/browser/storage_partition_details.h"
17 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/notification_details.h" 21 #include "content/public/browser/notification_details.h"
21 #include "content/public/browser/notification_source.h" 22 #include "content/public/browser/notification_source.h"
22 #include "content/public/common/content_client.h" 23 #include "content/public/common/content_client.h"
23 #include "net/cookies/cookie_store.h" 24 #include "net/cookies/cookie_store.h"
24 #include "net/http/http_util.h" 25 #include "net/http/http_util.h"
25 26
26 using content::BrowserThread; 27 using content::BrowserThread;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 69 }
69 70
70 private: 71 private:
71 const ProfileIOData* const profile_io_data_; 72 const ProfileIOData* const profile_io_data_;
72 }; 73 };
73 74
74 // Factory that creates the ChromeURLRequestContext for a given isolated app. 75 // Factory that creates the ChromeURLRequestContext for a given isolated app.
75 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { 76 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory {
76 public: 77 public:
77 FactoryForIsolatedApp(const ProfileIOData* profile_io_data, 78 FactoryForIsolatedApp(const ProfileIOData* profile_io_data,
78 const std::string& app_id, 79 const StoragePartitionDetails& partition_details,
79 ChromeURLRequestContextGetter* main_context, 80 ChromeURLRequestContextGetter* main_context,
80 scoped_ptr<net::URLRequestJobFactory::Interceptor> 81 scoped_ptr<net::URLRequestJobFactory::Interceptor>
81 protocol_handler_interceptor) 82 protocol_handler_interceptor)
82 : profile_io_data_(profile_io_data), 83 : profile_io_data_(profile_io_data),
83 app_id_(app_id), 84 partition_details_(partition_details),
84 main_request_context_getter_(main_context), 85 main_request_context_getter_(main_context),
85 protocol_handler_interceptor_(protocol_handler_interceptor.Pass()) {} 86 protocol_handler_interceptor_(protocol_handler_interceptor.Pass()) {}
86 87
87 virtual ChromeURLRequestContext* Create() OVERRIDE { 88 virtual ChromeURLRequestContext* Create() OVERRIDE {
88 // We will copy most of the state from the main request context. 89 // We will copy most of the state from the main request context.
89 // 90 //
90 // Note that this factory is one-shot. After Create() is called once, the 91 // 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 // factory is actually destroyed. Thus it is safe to destructively pass
92 // state onwards. 93 // state onwards.
93 return profile_io_data_->GetIsolatedAppRequestContext( 94 return profile_io_data_->GetIsolatedAppRequestContext(
94 main_request_context_getter_->GetIOContext(), app_id_, 95 main_request_context_getter_->GetIOContext(), partition_details_,
95 protocol_handler_interceptor_.Pass()); 96 protocol_handler_interceptor_.Pass());
96 } 97 }
97 98
98 private: 99 private:
99 const ProfileIOData* const profile_io_data_; 100 const ProfileIOData* const profile_io_data_;
100 const std::string app_id_; 101 const StoragePartitionDetails partition_details_;
101 scoped_refptr<ChromeURLRequestContextGetter> 102 scoped_refptr<ChromeURLRequestContextGetter>
102 main_request_context_getter_; 103 main_request_context_getter_;
103 scoped_ptr<net::URLRequestJobFactory::Interceptor> 104 scoped_ptr<net::URLRequestJobFactory::Interceptor>
104 protocol_handler_interceptor_; 105 protocol_handler_interceptor_;
105 }; 106 };
106 107
107 // Factory that creates the media ChromeURLRequestContext for a given isolated 108 // Factory that creates the media ChromeURLRequestContext for a given isolated
108 // app. The media context is based on the corresponding isolated app's context. 109 // app. The media context is based on the corresponding isolated app's context.
109 class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory { 110 class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory {
110 public: 111 public:
111 FactoryForIsolatedMedia(const ProfileIOData* profile_io_data, 112 FactoryForIsolatedMedia(const ProfileIOData* profile_io_data,
112 const std::string& app_id, 113 const StoragePartitionDetails& partition_details,
113 ChromeURLRequestContextGetter* app_context) 114 ChromeURLRequestContextGetter* app_context)
114 : profile_io_data_(profile_io_data), 115 : profile_io_data_(profile_io_data),
115 app_id_(app_id), 116 partition_details_(partition_details),
116 app_context_getter_(app_context) {} 117 app_context_getter_(app_context) {}
117 118
118 virtual ChromeURLRequestContext* Create() OVERRIDE { 119 virtual ChromeURLRequestContext* Create() OVERRIDE {
119 // We will copy most of the state from the corresopnding app's 120 // We will copy most of the state from the corresopnding app's
120 // request context. We expect to have the same lifetime as 121 // request context. We expect to have the same lifetime as
121 // the associated |app_context_getter_| so we can just reuse 122 // the associated |app_context_getter_| so we can just reuse
122 // all its backing objects, including the 123 // all its backing objects, including the
123 // |protocol_handler_interceptor|. This is why the API 124 // |protocol_handler_interceptor|. This is why the API
124 // looks different from FactoryForIsolatedApp's. 125 // looks different from FactoryForIsolatedApp's.
125 return profile_io_data_->GetIsolatedMediaRequestContext( 126 return profile_io_data_->GetIsolatedMediaRequestContext(
126 app_context_getter_->GetIOContext(), app_id_); 127 app_context_getter_->GetIOContext(), partition_details_);
127 } 128 }
128 129
129 private: 130 private:
130 const ProfileIOData* const profile_io_data_; 131 const ProfileIOData* const profile_io_data_;
131 const std::string app_id_; 132 const StoragePartitionDetails partition_details_;
132 scoped_refptr<ChromeURLRequestContextGetter> app_context_getter_; 133 scoped_refptr<ChromeURLRequestContextGetter> app_context_getter_;
133 }; 134 };
134 135
135 // Factory that creates the ChromeURLRequestContext for media. 136 // Factory that creates the ChromeURLRequestContext for media.
136 class FactoryForMedia : public ChromeURLRequestContextFactory { 137 class FactoryForMedia : public ChromeURLRequestContextFactory {
137 public: 138 public:
138 explicit FactoryForMedia(const ProfileIOData* profile_io_data) 139 explicit FactoryForMedia(const ProfileIOData* profile_io_data)
139 : profile_io_data_(profile_io_data) { 140 : profile_io_data_(profile_io_data) {
140 } 141 }
141 142
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 return new ChromeURLRequestContextGetter( 219 return new ChromeURLRequestContextGetter(
219 profile, 220 profile,
220 new FactoryForExtensions(profile_io_data)); 221 new FactoryForExtensions(profile_io_data));
221 } 222 }
222 223
223 // static 224 // static
224 ChromeURLRequestContextGetter* 225 ChromeURLRequestContextGetter*
225 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( 226 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp(
226 Profile* profile, 227 Profile* profile,
227 const ProfileIOData* profile_io_data, 228 const ProfileIOData* profile_io_data,
228 const std::string& app_id, 229 const StoragePartitionDetails& partition_details,
229 scoped_ptr<net::URLRequestJobFactory::Interceptor> 230 scoped_ptr<net::URLRequestJobFactory::Interceptor>
230 protocol_handler_interceptor) { 231 protocol_handler_interceptor) {
231 DCHECK(!profile->IsOffTheRecord()); 232 DCHECK(!profile->IsOffTheRecord());
232 ChromeURLRequestContextGetter* main_context = 233 ChromeURLRequestContextGetter* main_context =
233 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); 234 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext());
234 return new ChromeURLRequestContextGetter( 235 return new ChromeURLRequestContextGetter(
235 profile, 236 profile,
236 new FactoryForIsolatedApp(profile_io_data, app_id, main_context, 237 new FactoryForIsolatedApp(profile_io_data, partition_details,
237 protocol_handler_interceptor.Pass())); 238 main_context, protocol_handler_interceptor.Pass()));
238 } 239 }
239 240
240 // static 241 // static
241 ChromeURLRequestContextGetter* 242 ChromeURLRequestContextGetter*
242 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( 243 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia(
243 Profile* profile, 244 Profile* profile,
244 ChromeURLRequestContextGetter* app_context, 245 ChromeURLRequestContextGetter* app_context,
245 const ProfileIOData* profile_io_data, 246 const ProfileIOData* profile_io_data,
246 const std::string& app_id) { 247 const StoragePartitionDetails& partition_details) {
247 DCHECK(!profile->IsOffTheRecord()); 248 DCHECK(!profile->IsOffTheRecord());
248 return new ChromeURLRequestContextGetter( 249 return new ChromeURLRequestContextGetter(
249 profile, 250 profile,
250 new FactoryForIsolatedMedia(profile_io_data, app_id, app_context)); 251 new FactoryForIsolatedMedia(
252 profile_io_data, partition_details, app_context));
251 } 253 }
252 254
253 // static 255 // static
254 ChromeURLRequestContextGetter* 256 ChromeURLRequestContextGetter*
255 ChromeURLRequestContextGetter::CreateOffTheRecord( 257 ChromeURLRequestContextGetter::CreateOffTheRecord(
256 Profile* profile, const ProfileIOData* profile_io_data) { 258 Profile* profile, const ProfileIOData* profile_io_data) {
257 DCHECK(profile->IsOffTheRecord()); 259 DCHECK(profile->IsOffTheRecord());
258 return new ChromeURLRequestContextGetter( 260 return new ChromeURLRequestContextGetter(
259 profile, new FactoryForMain(profile_io_data)); 261 profile, new FactoryForMain(profile_io_data));
260 } 262 }
261 263
262 // static 264 // static
263 ChromeURLRequestContextGetter* 265 ChromeURLRequestContextGetter*
264 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( 266 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(
265 Profile* profile, const ProfileIOData* profile_io_data) { 267 Profile* profile, const ProfileIOData* profile_io_data) {
266 DCHECK(profile->IsOffTheRecord()); 268 DCHECK(profile->IsOffTheRecord());
267 return new ChromeURLRequestContextGetter( 269 return new ChromeURLRequestContextGetter(
268 profile, new FactoryForExtensions(profile_io_data)); 270 profile, new FactoryForExtensions(profile_io_data));
269 } 271 }
270 272
271 // static 273 // static
272 ChromeURLRequestContextGetter* 274 ChromeURLRequestContextGetter*
273 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( 275 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp(
274 Profile* profile, 276 Profile* profile,
275 const ProfileIOData* profile_io_data, 277 const ProfileIOData* profile_io_data,
276 const std::string& app_id, 278 const StoragePartitionDetails& partition_details,
277 scoped_ptr<net::URLRequestJobFactory::Interceptor> 279 scoped_ptr<net::URLRequestJobFactory::Interceptor>
278 protocol_handler_interceptor) { 280 protocol_handler_interceptor) {
279 DCHECK(profile->IsOffTheRecord()); 281 DCHECK(profile->IsOffTheRecord());
280 ChromeURLRequestContextGetter* main_context = 282 ChromeURLRequestContextGetter* main_context =
281 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); 283 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext());
282 return new ChromeURLRequestContextGetter( 284 return new ChromeURLRequestContextGetter(
283 profile, 285 profile,
284 new FactoryForIsolatedApp(profile_io_data, app_id, main_context, 286 new FactoryForIsolatedApp(profile_io_data, partition_details,
285 protocol_handler_interceptor.Pass())); 287 main_context, protocol_handler_interceptor.Pass()));
286 } 288 }
287 289
288 void ChromeURLRequestContextGetter::CleanupOnUIThread() { 290 void ChromeURLRequestContextGetter::CleanupOnUIThread() {
289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
290 // Unregister for pref notifications. 292 // Unregister for pref notifications.
291 DCHECK(!registrar_.IsEmpty()) << "Called more than once!"; 293 DCHECK(!registrar_.IsEmpty()) << "Called more than once!";
292 registrar_.RemoveAll(); 294 registrar_.RemoveAll();
293 } 295 }
294 296
295 // content::NotificationObserver implementation. 297 // content::NotificationObserver implementation.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); 399 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language));
398 } 400 }
399 401
400 void ChromeURLRequestContext::OnDefaultCharsetChange( 402 void ChromeURLRequestContext::OnDefaultCharsetChange(
401 const std::string& default_charset) { 403 const std::string& default_charset) {
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
403 set_referrer_charset(default_charset); 405 set_referrer_charset(default_charset);
404 set_accept_charset( 406 set_accept_charset(
405 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); 407 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset));
406 } 408 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698