Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NTP_RESOURCE_CACHE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NTP_RESOURCE_CACHE_H_ | 
| 6 #define CHROME_BROWSER_UI_WEBUI_NTP_NTP_RESOURCE_CACHE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_NTP_NTP_RESOURCE_CACHE_H_ | 
| 7 | 7 | 
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" | 
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" | 
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" | 
| 11 #include "base/prefs/public/pref_change_registrar.h" | 11 #include "base/prefs/public/pref_change_registrar.h" | 
| 12 #include "base/prefs/public/pref_observer.h" | |
| 13 #include "base/string16.h" | 12 #include "base/string16.h" | 
| 14 #include "chrome/browser/profiles/profile_keyed_service.h" | 13 #include "chrome/browser/profiles/profile_keyed_service.h" | 
| 15 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" | 
| 16 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" | 
| 17 | 16 | 
| 18 class Profile; | 17 class Profile; | 
| 19 | 18 | 
| 20 namespace base { | 19 namespace base { | 
| 21 class RefCountedMemory; | 20 class RefCountedMemory; | 
| 22 } | 21 } | 
| 23 | 22 | 
| 24 // This class keeps a cache of NTP resources (HTML and CSS) so we don't have to | 23 // This class keeps a cache of NTP resources (HTML and CSS) so we don't have to | 
| 25 // regenerate them all the time. | 24 // regenerate them all the time. | 
| 26 class NTPResourceCache : public content::NotificationObserver, | 25 class NTPResourceCache : public content::NotificationObserver, | 
| 27 public PrefObserver, | |
| 28 public ProfileKeyedService { | 26 public ProfileKeyedService { | 
| 29 public: | 27 public: | 
| 30 explicit NTPResourceCache(Profile* profile); | 28 explicit NTPResourceCache(Profile* profile); | 
| 31 virtual ~NTPResourceCache(); | 29 virtual ~NTPResourceCache(); | 
| 32 | 30 | 
| 33 base::RefCountedMemory* GetNewTabHTML(bool is_incognito); | 31 base::RefCountedMemory* GetNewTabHTML(bool is_incognito); | 
| 34 base::RefCountedMemory* GetNewTabCSS(bool is_incognito); | 32 base::RefCountedMemory* GetNewTabCSS(bool is_incognito); | 
| 35 | 33 | 
| 36 // content::NotificationObserver interface. | 34 // content::NotificationObserver interface. | 
| 37 virtual void Observe(int type, | 35 virtual void Observe(int type, | 
| 38 const content::NotificationSource& source, | 36 const content::NotificationSource& source, | 
| 39 const content::NotificationDetails& details) OVERRIDE; | 37 const content::NotificationDetails& details) OVERRIDE; | 
| 40 | 38 | 
| 41 // PrefObserver interface. | |
| 42 virtual void OnPreferenceChanged(PrefServiceBase* service, | |
| 43 const std::string& pref_name) OVERRIDE; | |
| 44 | |
| 45 private: | 39 private: | 
| 46 Profile* profile_; | 40 void OnPreferencesChanged(); | 
| 
 
Jói
2012/11/20 22:11:55
same suggestion as before: singular OnPreferenceCh
 
tfarina
2012/11/20 23:41:20
Done.
 
 | |
| 47 | 41 | 
| 48 void CreateNewTabHTML(); | 42 void CreateNewTabHTML(); | 
| 49 scoped_refptr<base::RefCountedMemory> new_tab_html_; | |
| 50 | 43 | 
| 51 // Helper to determine if the resource cache should be invalidated. | 44 // Helper to determine if the resource cache should be invalidated. | 
| 52 // This is called on every page load, and can be used to check values that | 45 // This is called on every page load, and can be used to check values that | 
| 53 // don't generate a notification when changed (e.g., system preferences). | 46 // don't generate a notification when changed (e.g., system preferences). | 
| 54 bool NewTabCacheNeedsRefresh(); | 47 bool NewTabCacheNeedsRefresh(); | 
| 55 | 48 | 
| 49 Profile* profile_; | |
| 50 | |
| 51 scoped_refptr<base::RefCountedMemory> new_tab_html_; | |
| 52 | |
| 56 #if !defined(OS_ANDROID) | 53 #if !defined(OS_ANDROID) | 
| 57 // Returns a message describing any newly-added sync types, or an empty | 54 // Returns a message describing any newly-added sync types, or an empty | 
| 58 // string if all types have already been acknowledged. | 55 // string if all types have already been acknowledged. | 
| 59 string16 GetSyncTypeMessage(); | 56 string16 GetSyncTypeMessage(); | 
| 60 | 57 | 
| 61 void CreateNewTabIncognitoHTML(); | 58 void CreateNewTabIncognitoHTML(); | 
| 62 scoped_refptr<base::RefCountedMemory> new_tab_incognito_html_; | |
| 63 | 59 | 
| 64 void CreateNewTabIncognitoCSS(); | 60 void CreateNewTabIncognitoCSS(); | 
| 61 | |
| 62 void CreateNewTabCSS(); | |
| 63 | |
| 64 scoped_refptr<base::RefCountedMemory> new_tab_incognito_html_; | |
| 65 scoped_refptr<base::RefCountedMemory> new_tab_incognito_css_; | 65 scoped_refptr<base::RefCountedMemory> new_tab_incognito_css_; | 
| 66 void CreateNewTabCSS(); | |
| 67 scoped_refptr<base::RefCountedMemory> new_tab_css_; | 66 scoped_refptr<base::RefCountedMemory> new_tab_css_; | 
| 68 | |
| 69 content::NotificationRegistrar registrar_; | 67 content::NotificationRegistrar registrar_; | 
| 70 PrefChangeRegistrar pref_change_registrar_; | 68 PrefChangeRegistrar pref_change_registrar_; | 
| 71 #endif | 69 #endif | 
| 72 | 70 | 
| 73 bool is_swipe_tracking_from_scroll_events_enabled_; | 71 bool is_swipe_tracking_from_scroll_events_enabled_; | 
| 74 | 72 | 
| 75 DISALLOW_COPY_AND_ASSIGN(NTPResourceCache); | 73 DISALLOW_COPY_AND_ASSIGN(NTPResourceCache); | 
| 76 }; | 74 }; | 
| 77 | 75 | 
| 78 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_RESOURCE_CACHE_H_ | 76 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_RESOURCE_CACHE_H_ | 
| OLD | NEW |