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

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_resource_cache.cc

Issue 11348165: Remove PrefObserver usages, batch 10. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android 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/ui/webui/ntp/ntp_resource_cache.h" 5 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } // namespace 168 } // namespace
169 169
170 NTPResourceCache::NTPResourceCache(Profile* profile) 170 NTPResourceCache::NTPResourceCache(Profile* profile)
171 : profile_(profile), is_swipe_tracking_from_scroll_events_enabled_(false) { 171 : profile_(profile), is_swipe_tracking_from_scroll_events_enabled_(false) {
172 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 172 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
173 content::Source<ThemeService>( 173 content::Source<ThemeService>(
174 ThemeServiceFactory::GetForProfile(profile))); 174 ThemeServiceFactory::GetForProfile(profile)));
175 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, 175 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
176 content::NotificationService::AllSources()); 176 content::NotificationService::AllSources());
177 177
178 base::Closure callback = base::Bind(&NTPResourceCache::OnPreferenceChanged,
179 base::Unretained(this));
180
178 // Watch for pref changes that cause us to need to invalidate the HTML cache. 181 // Watch for pref changes that cause us to need to invalidate the HTML cache.
179 pref_change_registrar_.Init(profile_->GetPrefs()); 182 pref_change_registrar_.Init(profile_->GetPrefs());
180 pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, this); 183 pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, callback);
181 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); 184 pref_change_registrar_.Add(prefs::kShowBookmarkBar, callback);
182 pref_change_registrar_.Add(prefs::kNtpShownPage, this); 185 pref_change_registrar_.Add(prefs::kNtpShownPage, callback);
183 pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, this); 186 pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, callback);
184 } 187 }
185 188
186 NTPResourceCache::~NTPResourceCache() {} 189 NTPResourceCache::~NTPResourceCache() {}
187 190
188 bool NTPResourceCache::NewTabCacheNeedsRefresh() { 191 bool NTPResourceCache::NewTabCacheNeedsRefresh() {
189 #if defined(OS_MACOSX) 192 #if defined(OS_MACOSX)
190 // Invalidate if the current value is different from the cached value. 193 // Invalidate if the current value is different from the cached value.
191 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled(); 194 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled();
192 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) { 195 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) {
193 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled; 196 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled;
(...skipping 26 matching lines...) Expand all
220 CreateNewTabIncognitoCSS(); 223 CreateNewTabIncognitoCSS();
221 } else { 224 } else {
222 if (!new_tab_css_.get()) 225 if (!new_tab_css_.get())
223 CreateNewTabCSS(); 226 CreateNewTabCSS();
224 } 227 }
225 return is_incognito ? new_tab_incognito_css_.get() : 228 return is_incognito ? new_tab_incognito_css_.get() :
226 new_tab_css_.get(); 229 new_tab_css_.get();
227 } 230 }
228 231
229 void NTPResourceCache::Observe(int type, 232 void NTPResourceCache::Observe(int type,
230 const content::NotificationSource& source, 233 const content::NotificationSource& source,
231 const content::NotificationDetails& details) { 234 const content::NotificationDetails& details) {
232 // Invalidate the cache. 235 // Invalidate the cache.
233 if (chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type || 236 if (chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type ||
234 chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED == type) { 237 chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED == type) {
235 new_tab_incognito_html_ = NULL; 238 new_tab_incognito_html_ = NULL;
236 new_tab_html_ = NULL; 239 new_tab_html_ = NULL;
237 new_tab_incognito_css_ = NULL; 240 new_tab_incognito_css_ = NULL;
238 new_tab_css_ = NULL; 241 new_tab_css_ = NULL;
239 } else { 242 } else {
240 NOTREACHED(); 243 NOTREACHED();
241 } 244 }
242 } 245 }
243 246
244 void NTPResourceCache::OnPreferenceChanged(PrefServiceBase* service, 247 void NTPResourceCache::OnPreferenceChanged() {
Mattias Nissler (ping if slow) 2012/11/21 09:39:34 nit: This function should be named FlushCache.
Dan Beam 2012/11/22 00:32:49 FYI: you may notice there are various things that
245 const std::string& pref_name) {
246 // A change occurred to one of the preferences we care about, so flush the 248 // A change occurred to one of the preferences we care about, so flush the
247 // cache. 249 // cache.
248 new_tab_incognito_html_ = NULL; 250 new_tab_incognito_html_ = NULL;
249 new_tab_html_ = NULL; 251 new_tab_html_ = NULL;
250 new_tab_css_ = NULL; 252 new_tab_css_ = NULL;
251 } 253 }
252 254
253 void NTPResourceCache::CreateNewTabIncognitoHTML() { 255 void NTPResourceCache::CreateNewTabIncognitoHTML() {
254 DictionaryValue localized_strings; 256 DictionaryValue localized_strings;
255 localized_strings.SetString("title", 257 localized_strings.SetString("title",
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 // Get our template. 571 // Get our template.
570 static const base::StringPiece new_tab_theme_css( 572 static const base::StringPiece new_tab_theme_css(
571 ResourceBundle::GetSharedInstance().GetRawDataResource(is_ntp_search ? 573 ResourceBundle::GetSharedInstance().GetRawDataResource(is_ntp_search ?
572 IDR_NEW_TAB_SEARCH_THEME_CSS : IDR_NEW_TAB_4_THEME_CSS)); 574 IDR_NEW_TAB_SEARCH_THEME_CSS : IDR_NEW_TAB_4_THEME_CSS));
573 575
574 // Create the string from our template and the replacements. 576 // Create the string from our template and the replacements.
575 std::string css_string; 577 std::string css_string;
576 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); 578 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL);
577 new_tab_css_ = base::RefCountedString::TakeString(&css_string); 579 new_tab_css_ = base::RefCountedString::TakeString(&css_string);
578 } 580 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_resource_cache.h ('k') | chrome/browser/ui/webui/ntp/ntp_resource_cache_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698