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

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

Issue 3304015: Use PrefChangeRegistrar everywhere (Closed)
Patch Set: final version for commit Created 10 years, 2 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 519
520 } // namespace 520 } // namespace
521 521
522 // ---------------------------------------------------------------------------- 522 // ----------------------------------------------------------------------------
523 // ChromeURLRequestContextGetter 523 // ChromeURLRequestContextGetter
524 // ---------------------------------------------------------------------------- 524 // ----------------------------------------------------------------------------
525 525
526 ChromeURLRequestContextGetter::ChromeURLRequestContextGetter( 526 ChromeURLRequestContextGetter::ChromeURLRequestContextGetter(
527 Profile* profile, 527 Profile* profile,
528 ChromeURLRequestContextFactory* factory) 528 ChromeURLRequestContextFactory* factory)
529 : prefs_(NULL), 529 : factory_(factory),
530 factory_(factory),
531 url_request_context_(NULL) { 530 url_request_context_(NULL) {
532 DCHECK(factory); 531 DCHECK(factory);
533 532
534 // If a base profile was specified, listen for changes to the preferences. 533 // If a base profile was specified, listen for changes to the preferences.
535 if (profile) 534 if (profile)
536 RegisterPrefsObserver(profile); 535 RegisterPrefsObserver(profile);
537 } 536 }
538 537
539 ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() { 538 ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() {
540 CheckCurrentlyOnIOThread(); 539 CheckCurrentlyOnIOThread();
541 540
542 DCHECK(!prefs_) << "Probably didn't call CleanupOnUIThread"; 541 DCHECK(registrar_.IsEmpty()) << "Probably didn't call CleanupOnUIThread";
543 542
544 // Either we already transformed the factory into a URLRequestContext, or 543 // Either we already transformed the factory into a URLRequestContext, or
545 // we still have a pending factory. 544 // we still have a pending factory.
546 DCHECK((factory_.get() && !url_request_context_.get()) || 545 DCHECK((factory_.get() && !url_request_context_.get()) ||
547 (!factory_.get() && url_request_context_.get())); 546 (!factory_.get() && url_request_context_.get()));
548 547
549 // The scoped_refptr / scoped_ptr destructors take care of releasing 548 // The scoped_refptr / scoped_ptr destructors take care of releasing
550 // |factory_| and |url_request_context_| now. 549 // |factory_| and |url_request_context_| now.
551 } 550 }
552 551
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 ChromeURLRequestContextGetter* 644 ChromeURLRequestContextGetter*
646 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( 645 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(
647 Profile* profile) { 646 Profile* profile) {
648 DCHECK(profile->IsOffTheRecord()); 647 DCHECK(profile->IsOffTheRecord());
649 return new ChromeURLRequestContextGetter( 648 return new ChromeURLRequestContextGetter(
650 profile, new FactoryForExtensions(profile, FilePath(), true)); 649 profile, new FactoryForExtensions(profile, FilePath(), true));
651 } 650 }
652 651
653 void ChromeURLRequestContextGetter::CleanupOnUIThread() { 652 void ChromeURLRequestContextGetter::CleanupOnUIThread() {
654 CheckCurrentlyOnMainThread(); 653 CheckCurrentlyOnMainThread();
655 654 // Unregister for pref notifications.
656 if (prefs_) { 655 registrar_.RemoveAll();
657 // Unregister for pref notifications.
658 prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this);
659 prefs_->RemovePrefObserver(prefs::kDefaultCharset, this);
660 prefs_ = NULL;
661 }
662 } 656 }
663 657
664 void ChromeURLRequestContextGetter::OnNewExtensions( 658 void ChromeURLRequestContextGetter::OnNewExtensions(
665 const std::string& id, 659 const std::string& id,
666 ChromeURLRequestContext::ExtensionInfo* info) { 660 ChromeURLRequestContext::ExtensionInfo* info) {
667 GetIOContext()->OnNewExtensions(id, info); 661 GetIOContext()->OnNewExtensions(id, info);
668 } 662 }
669 663
670 void ChromeURLRequestContextGetter::OnUnloadedExtension( 664 void ChromeURLRequestContextGetter::OnUnloadedExtension(
671 const std::string& id) { 665 const std::string& id) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 default_charset)); 697 default_charset));
704 } 698 }
705 } else { 699 } else {
706 NOTREACHED(); 700 NOTREACHED();
707 } 701 }
708 } 702 }
709 703
710 void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) { 704 void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) {
711 CheckCurrentlyOnMainThread(); 705 CheckCurrentlyOnMainThread();
712 706
713 prefs_ = profile->GetPrefs(); 707 registrar_.Init(profile->GetPrefs());
714 708 registrar_.Add(prefs::kAcceptLanguages, this);
715 prefs_->AddPrefObserver(prefs::kAcceptLanguages, this); 709 registrar_.Add(prefs::kDefaultCharset, this);
716 prefs_->AddPrefObserver(prefs::kDefaultCharset, this);
717 } 710 }
718 711
719 // static 712 // static
720 ChromeURLRequestContextGetter* 713 ChromeURLRequestContextGetter*
721 ChromeURLRequestContextGetter::CreateRequestContextForMedia( 714 ChromeURLRequestContextGetter::CreateRequestContextForMedia(
722 Profile* profile, const FilePath& disk_cache_path, int cache_size, 715 Profile* profile, const FilePath& disk_cache_path, int cache_size,
723 bool off_the_record) { 716 bool off_the_record) {
724 return new ChromeURLRequestContextGetter( 717 return new ChromeURLRequestContextGetter(
725 profile, 718 profile,
726 new FactoryForMedia(profile, 719 new FactoryForMedia(profile,
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 prefs::kProxyAutoDetect)); 1095 prefs::kProxyAutoDetect));
1103 1096
1104 if (pref_service->HasPrefPath(prefs::kProxyBypassList)) { 1097 if (pref_service->HasPrefPath(prefs::kProxyBypassList)) {
1105 std::string proxy_bypass = 1098 std::string proxy_bypass =
1106 pref_service->GetString(prefs::kProxyBypassList); 1099 pref_service->GetString(prefs::kProxyBypassList);
1107 proxy_config->proxy_rules().bypass_rules.ParseFromString(proxy_bypass); 1100 proxy_config->proxy_rules().bypass_rules.ParseFromString(proxy_bypass);
1108 } 1101 }
1109 1102
1110 return proxy_config; 1103 return proxy_config;
1111 } 1104 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.h ('k') | chrome/browser/notifications/desktop_notification_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698