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

Side by Side Diff: chrome/browser/net/chrome_url_request_context.cc

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

Powered by Google App Engine
This is Rietveld 408576698