| OLD | NEW |
| 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" |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 main_context, protocol_handler_interceptor.Pass())); | 288 main_context, protocol_handler_interceptor.Pass())); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void ChromeURLRequestContextGetter::CleanupOnUIThread() { | 291 void ChromeURLRequestContextGetter::CleanupOnUIThread() { |
| 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 293 // Unregister for pref notifications. | 293 // Unregister for pref notifications. |
| 294 DCHECK(!registrar_.IsEmpty()) << "Called more than once!"; | 294 DCHECK(!registrar_.IsEmpty()) << "Called more than once!"; |
| 295 registrar_.RemoveAll(); | 295 registrar_.RemoveAll(); |
| 296 } | 296 } |
| 297 | 297 |
| 298 // content::NotificationObserver implementation. | 298 void ChromeURLRequestContextGetter::OnPreferenceChanged( |
| 299 void ChromeURLRequestContextGetter::Observe( | 299 PrefServiceBase* prefs, |
| 300 int type, | 300 const std::string& pref_name_in) { |
| 301 const content::NotificationSource& source, | |
| 302 const content::NotificationDetails& details) { | |
| 303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 304 | 302 |
| 305 if (chrome::NOTIFICATION_PREF_CHANGED == type) { | 303 DCHECK(prefs); |
| 306 std::string* pref_name_in = content::Details<std::string>(details).ptr(); | 304 if (pref_name_in == prefs::kAcceptLanguages) { |
| 307 PrefService* prefs = content::Source<PrefService>(source).ptr(); | 305 std::string accept_language = |
| 308 DCHECK(pref_name_in && prefs); | 306 prefs->GetString(prefs::kAcceptLanguages); |
| 309 if (*pref_name_in == prefs::kAcceptLanguages) { | 307 BrowserThread::PostTask( |
| 310 std::string accept_language = | 308 BrowserThread::IO, FROM_HERE, |
| 311 prefs->GetString(prefs::kAcceptLanguages); | 309 base::Bind( |
| 312 BrowserThread::PostTask( | 310 &ChromeURLRequestContextGetter::OnAcceptLanguageChange, |
| 313 BrowserThread::IO, FROM_HERE, | 311 this, |
| 314 base::Bind( | 312 accept_language)); |
| 315 &ChromeURLRequestContextGetter::OnAcceptLanguageChange, | 313 } else if (pref_name_in == prefs::kDefaultCharset) { |
| 316 this, | 314 std::string default_charset = prefs->GetString(prefs::kDefaultCharset); |
| 317 accept_language)); | 315 BrowserThread::PostTask( |
| 318 } else if (*pref_name_in == prefs::kDefaultCharset) { | 316 BrowserThread::IO, FROM_HERE, |
| 319 std::string default_charset = prefs->GetString(prefs::kDefaultCharset); | 317 base::Bind( |
| 320 BrowserThread::PostTask( | 318 &ChromeURLRequestContextGetter::OnDefaultCharsetChange, |
| 321 BrowserThread::IO, FROM_HERE, | 319 this, |
| 322 base::Bind( | 320 default_charset)); |
| 323 &ChromeURLRequestContextGetter::OnDefaultCharsetChange, | |
| 324 this, | |
| 325 default_charset)); | |
| 326 } | |
| 327 } else { | |
| 328 NOTREACHED(); | |
| 329 } | 321 } |
| 330 } | 322 } |
| 331 | 323 |
| 332 void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) { | 324 void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) { |
| 333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 334 | 326 |
| 335 registrar_.Init(profile->GetPrefs()); | 327 registrar_.Init(profile->GetPrefs()); |
| 336 registrar_.Add(prefs::kAcceptLanguages, this); | 328 registrar_.Add(prefs::kAcceptLanguages, this); |
| 337 registrar_.Add(prefs::kDefaultCharset, this); | 329 registrar_.Add(prefs::kDefaultCharset, this); |
| 338 } | 330 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 set_accept_language( | 391 set_accept_language( |
| 400 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); | 392 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); |
| 401 } | 393 } |
| 402 | 394 |
| 403 void ChromeURLRequestContext::OnDefaultCharsetChange( | 395 void ChromeURLRequestContext::OnDefaultCharsetChange( |
| 404 const std::string& default_charset) { | 396 const std::string& default_charset) { |
| 405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 406 set_accept_charset( | 398 set_accept_charset( |
| 407 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); | 399 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); |
| 408 } | 400 } |
| OLD | NEW |