| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/dom_ui/ntp_resource_cache.h" | 5 #include "chrome/browser/dom_ui/ntp_resource_cache.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "app/animation.h" | 10 #include "app/animation.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 return BrowserThemeProvider::TilingToString(repeat_mode); | 126 return BrowserThemeProvider::TilingToString(repeat_mode); |
| 127 } | 127 } |
| 128 | 128 |
| 129 } // namespace | 129 } // namespace |
| 130 | 130 |
| 131 NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { | 131 NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { |
| 132 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 132 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 133 NotificationService::AllSources()); | 133 NotificationService::AllSources()); |
| 134 | 134 |
| 135 // Watch for pref changes that cause us to need to invalidate the HTML cache. | 135 // Watch for pref changes that cause us to need to invalidate the HTML cache. |
| 136 PrefService* pref_service = profile_->GetPrefs(); | 136 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 137 pref_service->AddPrefObserver(prefs::kShowBookmarkBar, this); | 137 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
| 138 pref_service->AddPrefObserver(prefs::kNTPShownSections, this); | 138 pref_change_registrar_.Add(prefs::kNTPShownSections, this); |
| 139 } | |
| 140 | |
| 141 NTPResourceCache::~NTPResourceCache() { | |
| 142 PrefService* pref_service = profile_->GetPrefs(); | |
| 143 pref_service->RemovePrefObserver(prefs::kShowBookmarkBar, this); | |
| 144 pref_service->RemovePrefObserver(prefs::kNTPShownSections, this); | |
| 145 } | 139 } |
| 146 | 140 |
| 147 RefCountedBytes* NTPResourceCache::GetNewTabHTML(bool is_off_the_record) { | 141 RefCountedBytes* NTPResourceCache::GetNewTabHTML(bool is_off_the_record) { |
| 148 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 142 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 149 if (is_off_the_record) { | 143 if (is_off_the_record) { |
| 150 if (!new_tab_incognito_html_.get()) | 144 if (!new_tab_incognito_html_.get()) |
| 151 CreateNewTabIncognitoHTML(); | 145 CreateNewTabIncognitoHTML(); |
| 152 } else { | 146 } else { |
| 153 if (!new_tab_html_.get()) | 147 if (!new_tab_html_.get()) |
| 154 CreateNewTabHTML(); | 148 CreateNewTabHTML(); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 std::string css_string; | 479 std::string css_string; |
| 486 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 480 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
| 487 css_string = ReplaceStringPlaceholders(css_string, subst2, NULL); | 481 css_string = ReplaceStringPlaceholders(css_string, subst2, NULL); |
| 488 css_string = ReplaceStringPlaceholders(css_string, subst3, NULL); | 482 css_string = ReplaceStringPlaceholders(css_string, subst3, NULL); |
| 489 | 483 |
| 490 new_tab_css_ = new RefCountedBytes; | 484 new_tab_css_ = new RefCountedBytes; |
| 491 new_tab_css_->data.resize(css_string.size()); | 485 new_tab_css_->data.resize(css_string.size()); |
| 492 std::copy(css_string.begin(), css_string.end(), | 486 std::copy(css_string.begin(), css_string.end(), |
| 493 new_tab_css_->data.begin()); | 487 new_tab_css_->data.begin()); |
| 494 } | 488 } |
| OLD | NEW |