1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/profiles/profile_io_data.h"
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/chrome_url_request_context.h"
ProfileIOData::Handle::Handle() : io_data_(new ProfileIOData) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
ProfileIOData::Handle::~Handle() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (main_request_context_getter_)
main_request_context_getter_->CleanupOnUIThread();
if (media_request_context_getter_)
media_request_context_getter_->CleanupOnUIThread();
if (extensions_request_context_getter_)
extensions_request_context_getter_->CleanupOnUIThread();
}
void ProfileIOData::Handle::Init(const FilePath& cookie_path,
const FilePath& cache_path,
int cache_max_size,
const FilePath& media_cache_path,
int media_cache_max_size,
const FilePath& extensions_cookie_path,
Profile* profile) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!io_data_->lazy_params_.get());
LazyParams* lazy_params = new LazyParams;
lazy_params->cookie_path = cookie_path;
lazy_params->cache_path = cache_path;
lazy_params->cache_max_size = cache_max_size;
lazy_params->media_cache_path = media_cache_path;
lazy_params->media_cache_max_size = media_cache_max_size;
lazy_params->extensions_cookie_path = extensions_cookie_path;
lazy_params->profile = profile;
lazy_params->io_thread = g_browser_process->io_thread();
io_data_->lazy_params_.reset(lazy_params);
}
scoped_refptr<ChromeURLRequestContextGetter>
ProfileIOData::Handle::GetMainRequestContextGetter() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!main_request_context_getter_) {
main_request_context_getter_ =
ChromeURLRequestContextGetter::CreateOriginal(
io_data_->lazy_params_->profile, io_data_);
}
return main_request_context_getter_;
}
scoped_refptr<ChromeURLRequestContextGetter>
ProfileIOData::Handle::GetMediaRequestContextGetter() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!media_request_context_getter_) {
media_request_context_getter_ =
ChromeURLRequestContextGetter::CreateOriginalForMedia(
io_data_->lazy_params_->profile, io_data_);
}
return media_request_context_getter_;
}
scoped_refptr<ChromeURLRequestContextGetter>
ProfileIOData::Handle::GetExtensionsRequestContextGetter() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!extensions_request_context_getter_) {
extensions_request_context_getter_ =
ChromeURLRequestContextGetter::CreateOriginalForExtensions(
io_data_->lazy_params_->profile, io_data_);
}
return extensions_request_context_getter_;
}
ProfileIOData::LazyParams::LazyParams()
: cache_max_size(0),
media_cache_max_size(0),
io_thread(NULL),
profile(NULL) {
}
ProfileIOData::LazyParams::~LazyParams() {}
class ProfileIOData::RequestContext : public ChromeURLRequestContext {
public:
RequestContext();
~RequestContext();
void set_profile_io_data(const ProfileIOData* profile_io_data) {
profile_io_data_ = profile_io_data;
}
private:
scoped_refptr<const ProfileIOData> profile_io_data_;
};
ProfileIOData::RequestContext::RequestContext() {}
ProfileIOData::RequestContext::~RequestContext() {}
ProfileIOData::ProfileIOData() : initialized_(false) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
ProfileIOData::~ProfileIOData() {
// If we have never initialized ProfileIOData, then Handle may hold the only
// reference to it. The important thing is to make sure it hasn't been
// initialized yet, because the lazily initialized variables are supposed to
// live on the IO thread.
if (BrowserThread::CurrentlyOn(BrowserThread::UI))
DCHECK(!initialized_);
else
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
}
scoped_refptr<ChromeURLRequestContext>
ProfileIOData::GetMainRequestContext() const {
LazyInitialize();
DCHECK(main_request_context_);
scoped_refptr<ChromeURLRequestContext> context = main_request_context_;
main_request_context_->set_profile_io_data(this);
main_request_context_ = NULL;
return context;
}
scoped_refptr<ChromeURLRequestContext>
ProfileIOData::GetMediaRequestContext() const {
LazyInitialize();
DCHECK(media_request_context_);
scoped_refptr<ChromeURLRequestContext> context = media_request_context_;
media_request_context_->set_profile_io_data(this);
media_request_context_ = NULL;
return context;
}
scoped_refptr<ChromeURLRequestContext>
ProfileIOData::GetExtensionsRequestContext() const {
LazyInitialize();
DCHECK(extensions_request_context_);
scoped_refptr<ChromeURLRequestContext> context = extensions_request_context_;
extensions_request_context_->set_profile_io_data(this);
extensions_request_context_ = NULL;
return context;
}
const ProfileIOData::LazyParams& ProfileIOData::lazy_params() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(lazy_params_.get());
return *lazy_params_;
}
void ProfileIOData::LazyInitialize() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (initialized_)
return;
main_request_context_ = new RequestContext;
media_request_context_ = new RequestContext;
extensions_request_context_ = new RequestContext;
// Initialize context members.
IOThread::Globals* io_thread_globals = lazy_params_->io_thread->globals();
main_request_context_->set_net_log(lazy_params_->io_thread->net_log());
media_request_context_->set_net_log(lazy_params_->io_thread->net_log());
main_request_context_->set_host_resolver(
io_thread_globals->host_resolver.get());
main_request_context_->set_cert_verifier(
io_thread_globals->cert_verifier.get());
main_request_context_->set_dnsrr_resolver(
io_thread_globals->dnsrr_resolver.get());
main_request_context_->set_network_delegate(
&io_thread_globals->network_delegate);
main_request_context_->set_http_auth_handler_factory(
io_thread_globals->http_auth_handler_factory.get());
media_request_context_->set_http_auth_handler_factory(
io_thread_globals->http_auth_handler_factory.get());
// TODO(cbentzel): How should extensions handle HTTP Authentication?
extensions_request_context_->set_http_auth_handler_factory(
io_thread_globals->http_auth_handler_factory.get());
// TODO(willchan): Initialize more of the contexts!
// TODO(willchan): Enable this when LazyInitialize() is able to fully
// initialize all the ChromeURLRequestContexts.
#if 0
params_.reset();
#endif
initialized_ = true;
}
|