| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // This class pulls data from a web resource (such as a JSON feed) which | 5 // This class pulls data from a web resource (such as a JSON feed) which |
| 6 // has been stored in the user's preferences file. Used mainly | 6 // has been stored in the user's preferences file. Used mainly |
| 7 // by the suggestions and tips area of the new tab page. | 7 // by the suggestions and tips area of the new tab page. |
| 8 | 8 |
| 9 #ifndef CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ | 9 #ifndef CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ |
| 10 #define CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ | 10 #define CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ |
| 11 | 11 |
| 12 #include <string> | |
| 13 | |
| 14 #include "chrome/browser/dom_ui/dom_ui.h" | 12 #include "chrome/browser/dom_ui/dom_ui.h" |
| 15 | 13 |
| 16 class DictionaryValue; | 14 class DictionaryValue; |
| 17 class DOMUI; | 15 class DOMUI; |
| 18 class PrefService; | 16 class PrefService; |
| 19 class Value; | 17 class Value; |
| 20 | 18 |
| 21 class TipsHandler : public DOMMessageHandler { | 19 class TipsHandler : public DOMMessageHandler { |
| 22 public: | 20 public: |
| 23 TipsHandler() : tips_cache_(NULL) {} | 21 TipsHandler() : tips_cache_(NULL) {} |
| 24 virtual ~TipsHandler() {} | 22 virtual ~TipsHandler() {} |
| 25 | 23 |
| 26 // DOMMessageHandler implementation and overrides. | 24 // DOMMessageHandler implementation and overrides. |
| 27 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); | 25 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
| 28 virtual void RegisterMessages(); | 26 virtual void RegisterMessages(); |
| 29 | 27 |
| 30 // Callback which pulls tips data from the preferences. | 28 // Callback which pulls tips data from the preferences. |
| 31 void HandleGetTips(const Value* content); | 29 void HandleGetTips(const Value* content); |
| 32 | 30 |
| 33 // Register tips cache with pref service. | 31 // Register tips cache with pref service. |
| 34 static void RegisterUserPrefs(PrefService* prefs); | 32 static void RegisterUserPrefs(PrefService* prefs); |
| 35 | 33 |
| 36 private: | 34 private: |
| 37 // Make sure the string we are pushing to the NTP is a valid URL. | 35 // Make sure the string we are pushing to the NTP is a valid URL. |
| 38 bool IsValidURL(const std::wstring& url_string); | 36 bool IsValidURL(const std::wstring& url_string); |
| 39 | 37 |
| 40 // Send a tip to the NTP. tip_type is "tip_html_text" if the tip is from | |
| 41 // the tip server, and "set_homepage_tip" if it's the tip to set the NTP | |
| 42 // as home page. | |
| 43 void SendTip(std::string tip, std::wstring tip_type, int tip_index); | |
| 44 | |
| 45 // So we can push data out to the page that has called this handler. | 38 // So we can push data out to the page that has called this handler. |
| 46 DOMUI* dom_ui_; | 39 DOMUI* dom_ui_; |
| 47 | 40 |
| 48 // Filled with data from cache in preferences. | 41 // Filled with data from cache in preferences. |
| 49 DictionaryValue* tips_cache_; | 42 DictionaryValue* tips_cache_; |
| 50 | 43 |
| 51 DISALLOW_COPY_AND_ASSIGN(TipsHandler); | 44 DISALLOW_COPY_AND_ASSIGN(TipsHandler); |
| 52 }; | 45 }; |
| 53 | 46 |
| 54 #endif // CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ | 47 #endif // CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ |
| 55 | 48 |
| OLD | NEW |