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

Side by Side Diff: chrome/browser/profiles/off_the_record_profile_io_data.cc

Issue 6201005: Initial support for partitioning cookies for isolated apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor and address comments. Created 9 years, 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/profiles/off_the_record_profile_io_data.h" 5 #include "chrome/browser/profiles/off_the_record_profile_io_data.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/browser_thread.h" 11 #include "chrome/browser/browser_thread.h"
12 #include "chrome/browser/extensions/extension_io_event_router.h" 12 #include "chrome/browser/extensions/extension_io_event_router.h"
13 #include "chrome/browser/io_thread.h" 13 #include "chrome/browser/io_thread.h"
14 #include "chrome/browser/net/chrome_cookie_policy.h" 14 #include "chrome/browser/net/chrome_cookie_policy.h"
15 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h" 15 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h"
16 #include "chrome/browser/net/chrome_net_log.h" 16 #include "chrome/browser/net/chrome_net_log.h"
17 #include "chrome/browser/net/chrome_network_delegate.h" 17 #include "chrome/browser/net/chrome_network_delegate.h"
18 #include "chrome/browser/net/chrome_url_request_context.h" 18 #include "chrome/browser/net/chrome_url_request_context.h"
19 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
20 #include "net/ftp/ftp_network_layer.h" 21 #include "net/ftp/ftp_network_layer.h"
21 #include "net/http/http_cache.h" 22 #include "net/http/http_cache.h"
22 23
23 OffTheRecordProfileIOData::Handle::Handle(Profile* profile) 24 OffTheRecordProfileIOData::Handle::Handle(Profile* profile)
24 : io_data_(new OffTheRecordProfileIOData), 25 : io_data_(new OffTheRecordProfileIOData),
25 profile_(profile), 26 profile_(profile),
26 initialized_(false) { 27 initialized_(false) {
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
28 DCHECK(profile); 29 DCHECK(profile);
29 DCHECK(!io_data_->lazy_params_.get()); 30 DCHECK(!io_data_->lazy_params_.get());
30 LazyParams* lazy_params = new LazyParams; 31 LazyParams* lazy_params = new LazyParams;
31 lazy_params->io_thread = g_browser_process->io_thread(); 32 lazy_params->io_thread = g_browser_process->io_thread();
32 io_data_->lazy_params_.reset(lazy_params); 33 io_data_->lazy_params_.reset(lazy_params);
33 } 34 }
34 35
35 OffTheRecordProfileIOData::Handle::~Handle() { 36 OffTheRecordProfileIOData::Handle::~Handle() {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 if (main_request_context_getter_) 38 if (main_request_context_getter_)
38 main_request_context_getter_->CleanupOnUIThread(); 39 main_request_context_getter_->CleanupOnUIThread();
39 if (extensions_request_context_getter_) 40 if (extensions_request_context_getter_)
40 extensions_request_context_getter_->CleanupOnUIThread(); 41 extensions_request_context_getter_->CleanupOnUIThread();
42
43 // Clean up all isolated app request contexts.
44 for (ChromeURLRequestContextGetterMap::iterator iter =
45 app_request_context_getter_map_.begin();
46 iter != app_request_context_getter_map_.end();
47 ++iter) {
48 iter->second->CleanupOnUIThread();
49 }
50 }
51
52 void OffTheRecordProfileIOData::Handle::InitIsolatedApp(
53 const Extension* installed_app) {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
55
56 // This may be called multiple times before InitializeAppRequestContext.
57 // Only do the initialization once.
58 std::string id = installed_app->id();
59 if (io_data_->lazy_params_map_.find(id) != io_data_->lazy_params_map_.end())
60 return;
61
62 LazyParams* lazy_params = new LazyParams;
63 lazy_params->io_thread = g_browser_process->io_thread();
64
65 InitializeProfileParams(profile_, &lazy_params->profile_params);
66
67 // Keep track of this app's LazyParams until InitializeAppRequestContext.
68 io_data_->lazy_params_map_[id] = lazy_params;
41 } 69 }
42 70
43 scoped_refptr<ChromeURLRequestContextGetter> 71 scoped_refptr<ChromeURLRequestContextGetter>
44 OffTheRecordProfileIOData::Handle::GetMainRequestContextGetter() const { 72 OffTheRecordProfileIOData::Handle::GetMainRequestContextGetter() const {
45 // TODO(oshima): Re-enable when ChromeOS only accesses the profile on the UI 73 // TODO(oshima): Re-enable when ChromeOS only accesses the profile on the UI
46 // thread. 74 // thread.
47 #if !defined(OS_CHROMEOS) 75 #if !defined(OS_CHROMEOS)
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
49 #endif // defined(OS_CHROMEOS) 77 #endif // defined(OS_CHROMEOS)
50 LazyInitialize(); 78 LazyInitialize();
51 if (!main_request_context_getter_) { 79 if (!main_request_context_getter_) {
52 main_request_context_getter_ = 80 main_request_context_getter_ =
53 ChromeURLRequestContextGetter::CreateOffTheRecord(profile_, io_data_); 81 ChromeURLRequestContextGetter::CreateOffTheRecord(profile_, io_data_);
54 } 82 }
55 return main_request_context_getter_; 83 return main_request_context_getter_;
56 } 84 }
57 85
58 scoped_refptr<ChromeURLRequestContextGetter> 86 scoped_refptr<ChromeURLRequestContextGetter>
59 OffTheRecordProfileIOData::Handle::GetExtensionsRequestContextGetter() const { 87 OffTheRecordProfileIOData::Handle::GetExtensionsRequestContextGetter() const {
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
61 LazyInitialize(); 89 LazyInitialize();
62 if (!extensions_request_context_getter_) { 90 if (!extensions_request_context_getter_) {
63 extensions_request_context_getter_ = 91 extensions_request_context_getter_ =
64 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( 92 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(
65 profile_, io_data_); 93 profile_, io_data_);
66 } 94 }
67 return extensions_request_context_getter_; 95 return extensions_request_context_getter_;
68 } 96 }
69 97
98 scoped_refptr<ChromeURLRequestContextGetter>
99 OffTheRecordProfileIOData::Handle::GetIsolatedAppRequestContextGetter(
100 const Extension* installed_app) const {
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
102 CHECK(installed_app);
103 LazyInitialize();
104
105 // Keep a map of request contexts, one per requested app ID.
106 std::string id = installed_app->id();
107 ChromeURLRequestContextGetterMap::iterator iter =
108 app_request_context_getter_map_.find(id);
109 if (iter != app_request_context_getter_map_.end())
110 return iter->second;
111
112 ChromeURLRequestContextGetter* context =
113 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp(
114 profile_, io_data_, installed_app);
115 app_request_context_getter_map_[id] = context;
116
117 return context;
118 }
119
70 void OffTheRecordProfileIOData::Handle::LazyInitialize() const { 120 void OffTheRecordProfileIOData::Handle::LazyInitialize() const {
71 if (!initialized_) { 121 if (!initialized_) {
72 InitializeProfileParams(profile_, &io_data_->lazy_params_->profile_params); 122 InitializeProfileParams(profile_, &io_data_->lazy_params_->profile_params);
73 initialized_ = true; 123 initialized_ = true;
74 } 124 }
75 } 125 }
76 126
77 OffTheRecordProfileIOData::LazyParams::LazyParams() : io_thread(NULL) {} 127 OffTheRecordProfileIOData::LazyParams::LazyParams() : io_thread(NULL) {}
78 OffTheRecordProfileIOData::LazyParams::~LazyParams() {} 128 OffTheRecordProfileIOData::LazyParams::~LazyParams() {}
79 129
80 OffTheRecordProfileIOData::OffTheRecordProfileIOData() 130 OffTheRecordProfileIOData::OffTheRecordProfileIOData()
81 : ProfileIOData(true), 131 : ProfileIOData(true),
82 initialized_(false) {} 132 initialized_(false) {}
83 OffTheRecordProfileIOData::~OffTheRecordProfileIOData() {} 133 OffTheRecordProfileIOData::~OffTheRecordProfileIOData() {}
willchan no longer on Chromium 2011/03/01 23:39:24 Correct me if I'm wrong, but |lazy_params_map_| ma
Charlie Reis 2011/03/03 01:08:05 Good catch. Fixed in profile_impl_io_data.cc, sin
84 134
85 void OffTheRecordProfileIOData::LazyInitializeInternal() const { 135 void OffTheRecordProfileIOData::LazyInitializeInternal() const {
86 main_request_context_ = new RequestContext; 136 main_request_context_ = new RequestContext;
87 extensions_request_context_ = new RequestContext; 137 extensions_request_context_ = new RequestContext;
88 138
89 IOThread* const io_thread = lazy_params_->io_thread; 139 IOThread* const io_thread = lazy_params_->io_thread;
90 IOThread::Globals* const io_thread_globals = io_thread->globals(); 140 IOThread::Globals* const io_thread_globals = io_thread->globals();
91 const ProfileParams& profile_params = lazy_params_->profile_params; 141 const ProfileParams& profile_params = lazy_params_->profile_params;
92 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 142 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
93 143
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 main_request_context_->network_delegate(), 207 main_request_context_->network_delegate(),
158 main_request_context_->net_log(), 208 main_request_context_->net_log(),
159 main_backend); 209 main_backend);
160 210
161 main_http_factory_.reset(cache); 211 main_http_factory_.reset(cache);
162 main_request_context_->set_http_transaction_factory(cache); 212 main_request_context_->set_http_transaction_factory(cache);
163 main_request_context_->set_ftp_transaction_factory( 213 main_request_context_->set_ftp_transaction_factory(
164 new net::FtpNetworkLayer(main_request_context_->host_resolver())); 214 new net::FtpNetworkLayer(main_request_context_->host_resolver()));
165 } 215 }
166 216
217 scoped_refptr<ProfileIOData::RequestContext>
218 OffTheRecordProfileIOData::InitializeAppRequestContext(
219 const Extension *app) const {
220 scoped_refptr<ProfileIOData::RequestContext> context = new RequestContext;
221
222 // Get the app-specific LazyParams, which was created in InitIsolatedApp.
223 std::string id = app->id();
224 LazyParamsMap::iterator iter = lazy_params_map_.find(id);
225 DCHECK(iter != lazy_params_map_.end());
226 scoped_ptr<LazyParams> lazy_params(iter->second);
227
228 IOThread* const io_thread = lazy_params->io_thread;
229 IOThread::Globals* const io_thread_globals = io_thread->globals();
230 const ProfileParams& profile_params = lazy_params->profile_params;
231 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
232
233 ApplyProfileParamsToContext(profile_params, context);
willchan no longer on Chromium 2011/03/01 23:39:24 I'm concerned about all this code duplication here
Charlie Reis 2011/03/03 01:08:05 Yes, this is a better approach. I think I still n
234
235 scoped_refptr<ChromeCookiePolicy> cookie_policy =
236 new ChromeCookiePolicy(profile_params.host_content_settings_map);
237 context->set_chrome_cookie_policy(cookie_policy);
238
239 context->set_net_log(lazy_params->io_thread->net_log());
240
241 DCHECK(network_delegate_.get());
242 context->set_network_delegate(network_delegate_.get());
243
244 context->set_host_resolver(io_thread_globals->host_resolver.get());
245 context->set_cert_verifier(io_thread_globals->cert_verifier.get());
246 context->set_dnsrr_resolver(io_thread_globals->dnsrr_resolver.get());
247 context->set_http_auth_handler_factory(
248 io_thread_globals->http_auth_handler_factory.get());
249
250 DCHECK(dns_cert_checker_.get());
251 context->set_dns_cert_checker(dns_cert_checker_.get());
willchan no longer on Chromium 2011/03/01 23:39:24 In answer to your earlier question, this is OK to
Charlie Reis 2011/03/03 01:08:05 Thanks.
252
253 context->set_proxy_service(
willchan no longer on Chromium 2011/03/01 23:39:24 We should be sharing this guy.
Charlie Reis 2011/03/03 01:08:05 Fixed (via the new Copy method).
254 CreateProxyService(
255 io_thread->net_log(),
256 io_thread_globals->proxy_script_fetcher_context.get(),
257 lazy_params->profile_params.proxy_config_service.release(),
258 command_line));
259
260 context->set_cookie_store(
261 new net::CookieMonster(NULL, profile_params.cookie_monster_delegate));
262
263 net::HttpCache::BackendFactory* app_backend =
264 net::HttpCache::DefaultBackend::InMemory(0);
265 net::HttpNetworkSession* main_network_session = main_http_factory_->GetSession ();
266 net::HttpCache* app_cache =
267 new net::HttpCache(main_network_session, app_backend);
268
269 context->set_http_transaction_factory(app_cache);
270 context->set_ftp_transaction_factory(
271 new net::FtpNetworkLayer(context->host_resolver()));
272
273 lazy_params_map_.erase(iter);
274 return context;
275 }
276
167 scoped_refptr<ChromeURLRequestContext> 277 scoped_refptr<ChromeURLRequestContext>
168 OffTheRecordProfileIOData::AcquireMainRequestContext() const { 278 OffTheRecordProfileIOData::AcquireMainRequestContext() const {
169 DCHECK(main_request_context_); 279 DCHECK(main_request_context_);
170 scoped_refptr<ChromeURLRequestContext> context = main_request_context_; 280 scoped_refptr<ChromeURLRequestContext> context = main_request_context_;
171 main_request_context_->set_profile_io_data(this); 281 main_request_context_->set_profile_io_data(this);
172 main_request_context_ = NULL; 282 main_request_context_ = NULL;
173 return context; 283 return context;
174 } 284 }
175 285
176 scoped_refptr<ChromeURLRequestContext> 286 scoped_refptr<ChromeURLRequestContext>
177 OffTheRecordProfileIOData::AcquireMediaRequestContext() const { 287 OffTheRecordProfileIOData::AcquireMediaRequestContext() const {
178 NOTREACHED(); 288 NOTREACHED();
179 return NULL; 289 return NULL;
180 } 290 }
181 291
182 scoped_refptr<ChromeURLRequestContext> 292 scoped_refptr<ChromeURLRequestContext>
183 OffTheRecordProfileIOData::AcquireExtensionsRequestContext() const { 293 OffTheRecordProfileIOData::AcquireExtensionsRequestContext() const {
184 DCHECK(extensions_request_context_); 294 DCHECK(extensions_request_context_);
185 scoped_refptr<ChromeURLRequestContext> context = extensions_request_context_; 295 scoped_refptr<ChromeURLRequestContext> context = extensions_request_context_;
186 extensions_request_context_->set_profile_io_data(this); 296 extensions_request_context_->set_profile_io_data(this);
187 extensions_request_context_ = NULL; 297 extensions_request_context_ = NULL;
188 return context; 298 return context;
189 } 299 }
300
301 scoped_refptr<ChromeURLRequestContext>
302 OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext(
303 const Extension* installed_app) const {
304 // We create per-app contexts on demand, unlike the others above.
305 scoped_refptr<RequestContext> app_request_context =
306 InitializeAppRequestContext(installed_app);
307 DCHECK(app_request_context);
308 app_request_context->set_profile_io_data(this);
309 return app_request_context;
310 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698