Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / ntp / ntp_resource_cache.h
blobcc76dd27b5f656920f421a9a9baa859b0e9845e2
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/browser_context_keyed_service/browser_context_keyed_service.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
17 class Profile;
19 namespace base {
20 class RefCountedMemory;
23 namespace content {
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,
30 public BrowserContextKeyedService {
31 public:
32 enum WindowType {
33 NORMAL,
34 INCOGNITO,
35 GUEST,
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);
65 private:
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();
75 Profile* profile_;
77 scoped_refptr<base::RefCountedMemory> new_tab_html_;
79 #if !defined(OS_ANDROID)
80 // Returns a message describing any newly-added sync types, or an empty
81 // string if all types have already been acknowledged.
82 base::string16 GetSyncTypeMessage();
84 void CreateNewTabIncognitoHTML();
85 void CreateNewTabIncognitoCSS();
87 void CreateNewTabGuestHTML();
88 void CreateNewTabGuestCSS();
90 void CreateNewTabCSS();
92 scoped_refptr<base::RefCountedMemory> new_tab_guest_html_;
93 scoped_refptr<base::RefCountedMemory> new_tab_guest_css_;
94 scoped_refptr<base::RefCountedMemory> new_tab_incognito_html_;
95 scoped_refptr<base::RefCountedMemory> new_tab_incognito_css_;
96 scoped_refptr<base::RefCountedMemory> new_tab_css_;
97 content::NotificationRegistrar registrar_;
98 PrefChangeRegistrar profile_pref_change_registrar_;
99 PrefChangeRegistrar local_state_pref_change_registrar_;
100 #endif
102 // Set based on platform_util::IsSwipeTrackingFromScrollEventsEnabled.
103 bool is_swipe_tracking_from_scroll_events_enabled_;
104 // Set based on NewTabUI::ShouldShowApps.
105 bool should_show_apps_page_;
106 // The next three all default to true and can be manually set, e.g., by the
107 // chrome://apps page.
108 bool should_show_most_visited_page_;
109 bool should_show_other_devices_menu_;
110 bool should_show_recently_closed_menu_;
112 DISALLOW_COPY_AND_ASSIGN(NTPResourceCache);
115 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_RESOURCE_CACHE_H_