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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NTP_RESOURCE_CACHE_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_NTP_RESOURCE_CACHE_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/prefs/pref_change_registrar.h"
12 #include "base/strings/string16.h"
13 #include "components/keyed_service/core/keyed_service.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
20 class RefCountedMemory;
24 class RenderProcessHost;
27 // This class keeps a cache of NTP resources (HTML and CSS) so we don't have to
28 // regenerate them all the time.
29 class NTPResourceCache : public content::NotificationObserver,
38 explicit NTPResourceCache(Profile* profile);
39 virtual ~NTPResourceCache();
41 base::RefCountedMemory* GetNewTabHTML(WindowType win_type);
42 base::RefCountedMemory* GetNewTabCSS(WindowType win_type);
44 void set_should_show_apps_page(bool should_show_apps_page) {
45 should_show_apps_page_ = should_show_apps_page;
47 void set_should_show_most_visited_page(bool should_show_most_visited_page) {
48 should_show_most_visited_page_ = should_show_most_visited_page;
50 void set_should_show_other_devices_menu(bool should_show_other_devices_menu) {
51 should_show_other_devices_menu_ = should_show_other_devices_menu;
53 void set_should_show_recently_closed_menu(
54 bool should_show_recently_closed_menu) {
55 should_show_recently_closed_menu_ = should_show_recently_closed_menu;
57 // content::NotificationObserver interface.
58 virtual void Observe(int type,
59 const content::NotificationSource& source,
60 const content::NotificationDetails& details) OVERRIDE;
62 static WindowType GetWindowType(
63 Profile* profile, content::RenderProcessHost* render_host);
66 void OnPreferenceChanged();
68 void CreateNewTabHTML();
70 // Helper to determine if the resource cache should be invalidated.
71 // This is called on every page load, and can be used to check values that
72 // don't generate a notification when changed (e.g., system preferences).
73 bool NewTabCacheNeedsRefresh();
77 scoped_refptr<base::RefCountedMemory> new_tab_html_;
79 // Returns a message describing any newly-added sync types, or an empty
80 // string if all types have already been acknowledged.
81 base::string16 GetSyncTypeMessage();
83 void CreateNewTabIncognitoHTML();
84 void CreateNewTabIncognitoCSS();
86 void CreateNewTabGuestHTML();
87 void CreateNewTabGuestCSS();
89 void CreateNewTabCSS();
91 scoped_refptr<base::RefCountedMemory> new_tab_guest_html_;
92 scoped_refptr<base::RefCountedMemory> new_tab_guest_css_;
93 scoped_refptr<base::RefCountedMemory> new_tab_incognito_html_;
94 scoped_refptr<base::RefCountedMemory> new_tab_incognito_css_;
95 scoped_refptr<base::RefCountedMemory> new_tab_css_;
96 content::NotificationRegistrar registrar_;
97 PrefChangeRegistrar profile_pref_change_registrar_;
98 PrefChangeRegistrar local_state_pref_change_registrar_;
100 // Set based on platform_util::IsSwipeTrackingFromScrollEventsEnabled.
101 bool is_swipe_tracking_from_scroll_events_enabled_;
102 // Set based on NewTabUI::ShouldShowApps.
103 bool should_show_apps_page_;
104 // The next three all default to true and can be manually set, e.g., by the
105 // chrome://apps page.
106 bool should_show_most_visited_page_;
107 bool should_show_other_devices_menu_;
108 bool should_show_recently_closed_menu_;
110 DISALLOW_COPY_AND_ASSIGN(NTPResourceCache);
113 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_RESOURCE_CACHE_H_