OLD | NEW |
---|---|
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/profile_io_data.h" | 5 #include "chrome/browser/profiles/profile_io_data.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/browser_thread.h" | 12 #include "chrome/browser/browser_thread.h" |
13 #include "chrome/browser/io_thread.h" | 13 #include "chrome/browser/io_thread.h" |
14 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 14 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
15 #include "chrome/browser/net/pref_proxy_config_service.h" | 15 #include "chrome/browser/net/pref_proxy_config_service.h" |
16 #include "chrome/browser/net/proxy_service_factory.h" | |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/browser/extensions/user_script_master.h" | 19 #include "chrome/browser/extensions/user_script_master.h" |
19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
22 #include "net/http/http_util.h" | 23 #include "net/http/http_util.h" |
23 #include "net/proxy/proxy_config_service_fixed.h" | 24 #include "net/proxy/proxy_config_service_fixed.h" |
24 #include "net/proxy/proxy_script_fetcher_impl.h" | 25 #include "net/proxy/proxy_script_fetcher_impl.h" |
25 #include "net/proxy/proxy_service.h" | 26 #include "net/proxy/proxy_service.h" |
26 | 27 |
27 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
28 #include "chrome/browser/chromeos/cros/cros_library.h" | 29 #include "chrome/browser/chromeos/cros/cros_library.h" |
29 #include "chrome/browser/chromeos/cros/libcros_service_library.h" | 30 #include "chrome/browser/chromeos/cros/libcros_service_library.h" |
30 #include "chrome/browser/chromeos/proxy_config_service.h" | 31 #include "chrome/browser/chromeos/proxy_config_service.h" |
31 #endif // defined(OS_CHROMEOS) | 32 #endif // defined(OS_CHROMEOS) |
kuan
2011/02/18 16:29:31
is this defined block still needed?
while we're on
battre
2011/02/21 17:27:58
Done.
| |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 // ---------------------------------------------------------------------------- | 36 // ---------------------------------------------------------------------------- |
36 // CookieMonster::Delegate implementation | 37 // CookieMonster::Delegate implementation |
37 // ---------------------------------------------------------------------------- | 38 // ---------------------------------------------------------------------------- |
38 class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { | 39 class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { |
39 public: | 40 public: |
40 explicit ChromeCookieMonsterDelegate(Profile* profile) { | 41 explicit ChromeCookieMonsterDelegate(Profile* profile) { |
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 params->ssl_config_service = profile->GetSSLConfigService(); | 164 params->ssl_config_service = profile->GetSSLConfigService(); |
164 params->cookie_monster_delegate = new ChromeCookieMonsterDelegate(profile); | 165 params->cookie_monster_delegate = new ChromeCookieMonsterDelegate(profile); |
165 params->database_tracker = profile->GetDatabaseTracker(); | 166 params->database_tracker = profile->GetDatabaseTracker(); |
166 params->appcache_service = profile->GetAppCacheService(); | 167 params->appcache_service = profile->GetAppCacheService(); |
167 params->blob_storage_context = profile->GetBlobStorageContext(); | 168 params->blob_storage_context = profile->GetBlobStorageContext(); |
168 params->file_system_context = profile->GetFileSystemContext(); | 169 params->file_system_context = profile->GetFileSystemContext(); |
169 params->extension_info_map = profile->GetExtensionInfoMap(); | 170 params->extension_info_map = profile->GetExtensionInfoMap(); |
170 params->extension_io_event_router = profile->GetExtensionIOEventRouter(); | 171 params->extension_io_event_router = profile->GetExtensionIOEventRouter(); |
171 params->prerender_manager = profile->GetPrerenderManager(); | 172 params->prerender_manager = profile->GetPrerenderManager(); |
172 | 173 |
173 params->proxy_config_service.reset(CreateProxyConfigService(profile)); | 174 params->proxy_config_service.reset( |
175 ProxyServiceFactory::CreateProxyConfigService( | |
176 profile->GetProxyConfigTracker())); | |
174 } | 177 } |
175 | 178 |
176 ProfileIOData::RequestContext::RequestContext() {} | 179 ProfileIOData::RequestContext::RequestContext() {} |
177 ProfileIOData::RequestContext::~RequestContext() {} | 180 ProfileIOData::RequestContext::~RequestContext() {} |
178 | 181 |
179 ProfileIOData::ProfileParams::ProfileParams() | 182 ProfileIOData::ProfileParams::ProfileParams() |
180 : is_off_the_record(false), | 183 : is_off_the_record(false), |
181 clear_local_state_on_exit(false) {} | 184 clear_local_state_on_exit(false) {} |
182 ProfileIOData::ProfileParams::~ProfileParams() {} | 185 ProfileIOData::ProfileParams::~ProfileParams() {} |
183 | 186 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 context->set_ssl_config_service(profile_params.ssl_config_service); | 252 context->set_ssl_config_service(profile_params.ssl_config_service); |
250 context->set_database_tracker(profile_params.database_tracker); | 253 context->set_database_tracker(profile_params.database_tracker); |
251 context->set_appcache_service(profile_params.appcache_service); | 254 context->set_appcache_service(profile_params.appcache_service); |
252 context->set_blob_storage_context(profile_params.blob_storage_context); | 255 context->set_blob_storage_context(profile_params.blob_storage_context); |
253 context->set_file_system_context(profile_params.file_system_context); | 256 context->set_file_system_context(profile_params.file_system_context); |
254 context->set_extension_info_map(profile_params.extension_info_map); | 257 context->set_extension_info_map(profile_params.extension_info_map); |
255 context->set_extension_io_event_router( | 258 context->set_extension_io_event_router( |
256 profile_params.extension_io_event_router); | 259 profile_params.extension_io_event_router); |
257 context->set_prerender_manager(profile_params.prerender_manager); | 260 context->set_prerender_manager(profile_params.prerender_manager); |
258 } | 261 } |
259 | |
260 // static | |
261 net::ProxyConfigService* ProfileIOData::CreateProxyConfigService( | |
262 Profile* profile) { | |
263 // The linux gconf-based proxy settings getter relies on being initialized | |
264 // from the UI thread. | |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
266 | |
267 // Create a baseline service that provides proxy configuration in case nothing | |
268 // is configured through prefs (Note: prefs include command line and | |
269 // configuration policy). | |
270 net::ProxyConfigService* base_service = NULL; | |
271 | |
272 // TODO(port): the IO and FILE message loops are only used by Linux. Can | |
273 // that code be moved to chrome/browser instead of being in net, so that it | |
274 // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354. | |
275 #if defined(OS_CHROMEOS) | |
276 base_service = new chromeos::ProxyConfigService( | |
277 profile->GetChromeOSProxyConfigServiceImpl()); | |
278 #else | |
279 base_service = net::ProxyService::CreateSystemProxyConfigService( | |
280 g_browser_process->io_thread()->message_loop(), | |
281 g_browser_process->file_thread()->message_loop()); | |
282 #endif // defined(OS_CHROMEOS) | |
283 | |
284 return new PrefProxyConfigService(profile->GetProxyConfigTracker(), | |
285 base_service); | |
286 } | |
287 | |
288 // static | |
289 net::ProxyService* ProfileIOData::CreateProxyService( | |
290 net::NetLog* net_log, | |
291 net::URLRequestContext* context, | |
292 net::ProxyConfigService* proxy_config_service, | |
293 const CommandLine& command_line) { | |
294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
295 | |
296 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); | |
297 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { | |
298 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h | |
299 // to understand why we have this limitation. | |
300 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; | |
301 use_v8 = false; // Fallback to non-v8 implementation. | |
302 } | |
303 | |
304 size_t num_pac_threads = 0u; // Use default number of threads. | |
305 | |
306 // Check the command line for an override on the number of proxy resolver | |
307 // threads to use. | |
308 if (command_line.HasSwitch(switches::kNumPacThreads)) { | |
309 std::string s = command_line.GetSwitchValueASCII(switches::kNumPacThreads); | |
310 | |
311 // Parse the switch (it should be a positive integer formatted as decimal). | |
312 int n; | |
313 if (base::StringToInt(s, &n) && n > 0) { | |
314 num_pac_threads = static_cast<size_t>(n); | |
315 } else { | |
316 LOG(ERROR) << "Invalid switch for number of PAC threads: " << s; | |
317 } | |
318 } | |
319 | |
320 net::ProxyService* proxy_service; | |
321 if (use_v8) { | |
322 proxy_service = net::ProxyService::CreateUsingV8ProxyResolver( | |
323 proxy_config_service, | |
324 num_pac_threads, | |
325 new net::ProxyScriptFetcherImpl(context), | |
326 context->host_resolver(), | |
327 net_log); | |
328 } else { | |
329 proxy_service = net::ProxyService::CreateUsingSystemProxyResolver( | |
330 proxy_config_service, | |
331 num_pac_threads, | |
332 net_log); | |
333 } | |
334 | |
335 #if defined(OS_CHROMEOS) | |
336 if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { | |
337 chromeos::CrosLibrary::Get()->GetLibCrosServiceLibrary()-> | |
338 RegisterNetworkProxyHandler(proxy_service); | |
339 } | |
340 #endif // defined(OS_CHROMEOS) | |
341 | |
342 return proxy_service; | |
343 } | |
OLD | NEW |