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

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: Missed a merging of removed variable. Created 8 years, 1 month 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/profiles/storage_partition_descriptor.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 StoragePartitionDescriptor& partition_descriptor,
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_descriptor_(partition_descriptor),
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_descriptor_,
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 StoragePartitionDescriptor partition_descriptor_;
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(
112 const std::string& app_id, 113 const ProfileIOData* profile_io_data,
113 ChromeURLRequestContextGetter* app_context) 114 const StoragePartitionDescriptor& partition_descriptor,
114 : profile_io_data_(profile_io_data), 115 ChromeURLRequestContextGetter* app_context)
115 app_id_(app_id), 116 : profile_io_data_(profile_io_data),
116 app_context_getter_(app_context) {} 117 partition_descriptor_(partition_descriptor),
118 app_context_getter_(app_context) {}
117 119
118 virtual ChromeURLRequestContext* Create() OVERRIDE { 120 virtual ChromeURLRequestContext* Create() OVERRIDE {
119 // 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
120 // request context. We expect to have the same lifetime as 122 // request context. We expect to have the same lifetime as
121 // the associated |app_context_getter_| so we can just reuse 123 // the associated |app_context_getter_| so we can just reuse
122 // all its backing objects, including the 124 // all its backing objects, including the
123 // |protocol_handler_interceptor|. This is why the API 125 // |protocol_handler_interceptor|. This is why the API
124 // looks different from FactoryForIsolatedApp's. 126 // looks different from FactoryForIsolatedApp's.
125 return profile_io_data_->GetIsolatedMediaRequestContext( 127 return profile_io_data_->GetIsolatedMediaRequestContext(
126 app_context_getter_->GetIOContext(), app_id_); 128 app_context_getter_->GetIOContext(), partition_descriptor_);
127 } 129 }
128 130
129 private: 131 private:
130 const ProfileIOData* const profile_io_data_; 132 const ProfileIOData* const profile_io_data_;
131 const std::string app_id_; 133 const StoragePartitionDescriptor partition_descriptor_;
132 scoped_refptr<ChromeURLRequestContextGetter> app_context_getter_; 134 scoped_refptr<ChromeURLRequestContextGetter> app_context_getter_;
133 }; 135 };
134 136
135 // Factory that creates the ChromeURLRequestContext for media. 137 // Factory that creates the ChromeURLRequestContext for media.
136 class FactoryForMedia : public ChromeURLRequestContextFactory { 138 class FactoryForMedia : public ChromeURLRequestContextFactory {
137 public: 139 public:
138 explicit FactoryForMedia(const ProfileIOData* profile_io_data) 140 explicit FactoryForMedia(const ProfileIOData* profile_io_data)
139 : profile_io_data_(profile_io_data) { 141 : profile_io_data_(profile_io_data) {
140 } 142 }
141 143
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 return new ChromeURLRequestContextGetter( 220 return new ChromeURLRequestContextGetter(
219 profile, 221 profile,
220 new FactoryForExtensions(profile_io_data)); 222 new FactoryForExtensions(profile_io_data));
221 } 223 }
222 224
223 // static 225 // static
224 ChromeURLRequestContextGetter* 226 ChromeURLRequestContextGetter*
225 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( 227 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp(
226 Profile* profile, 228 Profile* profile,
227 const ProfileIOData* profile_io_data, 229 const ProfileIOData* profile_io_data,
228 const std::string& app_id, 230 const StoragePartitionDescriptor& partition_descriptor,
229 scoped_ptr<net::URLRequestJobFactory::Interceptor> 231 scoped_ptr<net::URLRequestJobFactory::Interceptor>
230 protocol_handler_interceptor) { 232 protocol_handler_interceptor) {
231 DCHECK(!profile->IsOffTheRecord()); 233 DCHECK(!profile->IsOffTheRecord());
232 ChromeURLRequestContextGetter* main_context = 234 ChromeURLRequestContextGetter* main_context =
233 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); 235 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext());
234 return new ChromeURLRequestContextGetter( 236 return new ChromeURLRequestContextGetter(
235 profile, 237 profile,
236 new FactoryForIsolatedApp(profile_io_data, app_id, main_context, 238 new FactoryForIsolatedApp(profile_io_data, partition_descriptor,
237 protocol_handler_interceptor.Pass())); 239 main_context, protocol_handler_interceptor.Pass()));
238 } 240 }
239 241
240 // static 242 // static
241 ChromeURLRequestContextGetter* 243 ChromeURLRequestContextGetter*
242 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( 244 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia(
243 Profile* profile, 245 Profile* profile,
244 ChromeURLRequestContextGetter* app_context, 246 ChromeURLRequestContextGetter* app_context,
245 const ProfileIOData* profile_io_data, 247 const ProfileIOData* profile_io_data,
246 const std::string& app_id) { 248 const StoragePartitionDescriptor& partition_descriptor) {
247 DCHECK(!profile->IsOffTheRecord()); 249 DCHECK(!profile->IsOffTheRecord());
248 return new ChromeURLRequestContextGetter( 250 return new ChromeURLRequestContextGetter(
249 profile, 251 profile,
250 new FactoryForIsolatedMedia(profile_io_data, app_id, app_context)); 252 new FactoryForIsolatedMedia(
253 profile_io_data, partition_descriptor, app_context));
251 } 254 }
252 255
253 // static 256 // static
254 ChromeURLRequestContextGetter* 257 ChromeURLRequestContextGetter*
255 ChromeURLRequestContextGetter::CreateOffTheRecord( 258 ChromeURLRequestContextGetter::CreateOffTheRecord(
256 Profile* profile, const ProfileIOData* profile_io_data) { 259 Profile* profile, const ProfileIOData* profile_io_data) {
257 DCHECK(profile->IsOffTheRecord()); 260 DCHECK(profile->IsOffTheRecord());
258 return new ChromeURLRequestContextGetter( 261 return new ChromeURLRequestContextGetter(
259 profile, new FactoryForMain(profile_io_data)); 262 profile, new FactoryForMain(profile_io_data));
260 } 263 }
261 264
262 // static 265 // static
263 ChromeURLRequestContextGetter* 266 ChromeURLRequestContextGetter*
264 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( 267 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(
265 Profile* profile, const ProfileIOData* profile_io_data) { 268 Profile* profile, const ProfileIOData* profile_io_data) {
266 DCHECK(profile->IsOffTheRecord()); 269 DCHECK(profile->IsOffTheRecord());
267 return new ChromeURLRequestContextGetter( 270 return new ChromeURLRequestContextGetter(
268 profile, new FactoryForExtensions(profile_io_data)); 271 profile, new FactoryForExtensions(profile_io_data));
269 } 272 }
270 273
271 // static 274 // static
272 ChromeURLRequestContextGetter* 275 ChromeURLRequestContextGetter*
273 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( 276 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp(
274 Profile* profile, 277 Profile* profile,
275 const ProfileIOData* profile_io_data, 278 const ProfileIOData* profile_io_data,
276 const std::string& app_id, 279 const StoragePartitionDescriptor& partition_descriptor,
277 scoped_ptr<net::URLRequestJobFactory::Interceptor> 280 scoped_ptr<net::URLRequestJobFactory::Interceptor>
278 protocol_handler_interceptor) { 281 protocol_handler_interceptor) {
279 DCHECK(profile->IsOffTheRecord()); 282 DCHECK(profile->IsOffTheRecord());
280 ChromeURLRequestContextGetter* main_context = 283 ChromeURLRequestContextGetter* main_context =
281 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); 284 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext());
282 return new ChromeURLRequestContextGetter( 285 return new ChromeURLRequestContextGetter(
283 profile, 286 profile,
284 new FactoryForIsolatedApp(profile_io_data, app_id, main_context, 287 new FactoryForIsolatedApp(profile_io_data, partition_descriptor,
285 protocol_handler_interceptor.Pass())); 288 main_context, protocol_handler_interceptor.Pass()));
286 } 289 }
287 290
288 void ChromeURLRequestContextGetter::CleanupOnUIThread() { 291 void ChromeURLRequestContextGetter::CleanupOnUIThread() {
289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
290 // Unregister for pref notifications. 293 // Unregister for pref notifications.
291 DCHECK(!registrar_.IsEmpty()) << "Called more than once!"; 294 DCHECK(!registrar_.IsEmpty()) << "Called more than once!";
292 registrar_.RemoveAll(); 295 registrar_.RemoveAll();
293 } 296 }
294 297
295 // content::NotificationObserver implementation. 298 // content::NotificationObserver implementation.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 set_accept_language( 399 set_accept_language(
397 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); 400 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language));
398 } 401 }
399 402
400 void ChromeURLRequestContext::OnDefaultCharsetChange( 403 void ChromeURLRequestContext::OnDefaultCharsetChange(
401 const std::string& default_charset) { 404 const std::string& default_charset) {
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
403 set_accept_charset( 406 set_accept_charset(
404 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); 407 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset));
405 } 408 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.h ('k') | chrome/browser/profiles/off_the_record_profile_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698