Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / ntp / ntp_resource_cache.h
bloba3ab619676a9b80957a5c56da387f3c4198c53be
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 "components/web_resource/promo_resource_service.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
18 class Profile;
20 namespace base {
21 class RefCountedMemory;
24 namespace content {
25 class RenderProcessHost;
28 // This class keeps a cache of NTP resources (HTML and CSS) so we don't have to
29 // regenerate them all the time.
30 class NTPResourceCache : public content::NotificationObserver,
31 public KeyedService {
32 public:
33 enum WindowType {
34 NORMAL,
35 INCOGNITO,
36 GUEST,
39 explicit NTPResourceCache(Profile* profile);
40 ~NTPResourceCache() override;
42 base::RefCountedMemory* GetNewTabHTML(WindowType win_type);
43 base::RefCountedMemory* GetNewTabCSS(WindowType win_type);
45 void set_should_show_apps_page(bool should_show_apps_page) {
46 should_show_apps_page_ = should_show_apps_page;
48 void set_should_show_other_devices_menu(bool should_show_other_devices_menu) {
49 should_show_other_devices_menu_ = should_show_other_devices_menu;
51 // content::NotificationObserver interface.
52 void Observe(int type,
53 const content::NotificationSource& source,
54 const content::NotificationDetails& details) override;
56 static WindowType GetWindowType(
57 Profile* profile, content::RenderProcessHost* render_host);
59 private:
60 void OnPreferenceChanged();
62 void CreateNewTabHTML();
64 // Invalidates the NTPResourceCache.
65 void Invalidate();
67 // Helper to determine if the resource cache should be invalidated.
68 // This is called on every page load, and can be used to check values that
69 // don't generate a notification when changed (e.g., system preferences).
70 bool NewTabCacheNeedsRefresh();
72 Profile* profile_;
74 scoped_refptr<base::RefCountedMemory> new_tab_html_;
76 // Returns a message describing any newly-added sync types, or an empty
77 // string if all types have already been acknowledged.
78 base::string16 GetSyncTypeMessage();
80 void CreateNewTabIncognitoHTML();
81 void CreateNewTabIncognitoCSS();
83 void CreateNewTabGuestHTML();
84 void CreateNewTabGuestCSS();
86 void CreateNewTabCSS();
88 scoped_refptr<base::RefCountedMemory> new_tab_guest_html_;
89 scoped_refptr<base::RefCountedMemory> new_tab_guest_css_;
90 scoped_refptr<base::RefCountedMemory> new_tab_incognito_html_;
91 scoped_refptr<base::RefCountedMemory> new_tab_incognito_css_;
92 scoped_refptr<base::RefCountedMemory> new_tab_css_;
93 content::NotificationRegistrar registrar_;
94 PrefChangeRegistrar profile_pref_change_registrar_;
95 PrefChangeRegistrar local_state_pref_change_registrar_;
96 scoped_ptr<web_resource::PromoResourceService::StateChangedSubscription>
97 promo_resource_subscription_;
99 // Set based on platform_util::IsSwipeTrackingFromScrollEventsEnabled.
100 bool is_swipe_tracking_from_scroll_events_enabled_;
101 // Set based on NewTabUI::ShouldShowApps.
102 bool should_show_apps_page_;
103 bool should_show_other_devices_menu_;
105 DISALLOW_COPY_AND_ASSIGN(NTPResourceCache);
108 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_RESOURCE_CACHE_H_