• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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.
4 
5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_RESOURCE_CACHE_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_RESOURCE_CACHE_H_
7 #pragma once
8 
9 #include "base/basictypes.h"
10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/prefs/pref_change_registrar.h"
12 #include "content/common/notification_observer.h"
13 #include "content/common/notification_registrar.h"
14 
15 class Profile;
16 class RefCountedBytes;
17 
18 // This class keeps a cache of NTP resources (HTML and CSS) so we don't have to
19 // regenerate them all the time.
20 class NTPResourceCache : public NotificationObserver {
21  public:
22   explicit NTPResourceCache(Profile* profile);
23   virtual ~NTPResourceCache();
24 
25   RefCountedBytes* GetNewTabHTML(bool is_incognito);
26   RefCountedBytes* GetNewTabCSS(bool is_incognito);
27 
28   // NotificationObserver interface.
29   virtual void Observe(NotificationType type,
30                        const NotificationSource& source,
31                        const NotificationDetails& details);
32 
33  private:
34   Profile* profile_;
35 
36   void CreateNewTabIncognitoHTML();
37   scoped_refptr<RefCountedBytes> new_tab_incognito_html_;
38   void CreateNewTabHTML();
39   scoped_refptr<RefCountedBytes> new_tab_html_;
40 
41   void CreateNewTabIncognitoCSS();
42   scoped_refptr<RefCountedBytes> new_tab_incognito_css_;
43   void CreateNewTabCSS();
44   scoped_refptr<RefCountedBytes> new_tab_css_;
45 
46   NotificationRegistrar registrar_;
47   PrefChangeRegistrar pref_change_registrar_;
48 
49   DISALLOW_COPY_AND_ASSIGN(NTPResourceCache);
50 };
51 
52 #endif  // CHROME_BROWSER_UI_WEBUI_NTP_RESOURCE_CACHE_H_
53