diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 00:32:11 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 00:32:11 +0000 |
commit | 61a523f378291307081d46277cca5dd087fb30ac (patch) | |
tree | 76a60b79fafd0f01c2e94b5740db63e88cd9ef99 /chrome/browser/dom_ui | |
parent | 5bbf2884b6ff9466d95e3c6f177ebb7a39b70268 (diff) | |
download | chromium_src-61a523f378291307081d46277cca5dd087fb30ac.zip chromium_src-61a523f378291307081d46277cca5dd087fb30ac.tar.gz chromium_src-61a523f378291307081d46277cca5dd087fb30ac.tar.bz2 |
Add single line of tips to NNTP.
BUG= http://crbug.com/19162
TEST= Start browser with NNTP, note line of tips at bottom.
Review URL: http://codereview.chromium.org/173087
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24384 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.cc | 53 | ||||
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.h | 12 |
2 files changed, 18 insertions, 47 deletions
diff --git a/chrome/browser/dom_ui/tips_handler.cc b/chrome/browser/dom_ui/tips_handler.cc index c495a0d..4690c27 100644 --- a/chrome/browser/dom_ui/tips_handler.cc +++ b/chrome/browser/dom_ui/tips_handler.cc @@ -12,19 +12,10 @@ #include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" -namespace { - - // TODO(mrc): l10n - // This title should only appear the very first time Chrome is run with - // web resources enabled; otherwise the cache should be populated. - static const wchar_t* kTipsTitleAtStartup = - L"Tips and recommendations to help you discover interesting websites."; -} - DOMMessageHandler* TipsHandler::Attach(DOMUI* dom_ui) { dom_ui_ = dom_ui; tips_cache_ = dom_ui_->GetProfile()->GetPrefs()-> - GetDictionary(prefs::kNTPTipsCache); + GetMutableDictionary(prefs::kNTPTipsCache); return DOMMessageHandler::Attach(dom_ui); } @@ -38,36 +29,26 @@ void TipsHandler::HandleGetTips(const Value* content) { ListValue list_value; // Holds the web resource data found in the preferences cache. - DictionaryValue* wr_dict; + ListValue* wr_list; - // These values hold the data for each web resource item. As the web - // resource server solidifies, these may change. - std::wstring title; - std::wstring thumb; - std::wstring source; - std::wstring snipp; - std::wstring url; + // These values hold the data for each web resource item. + int current_tip_index; + std::string current_tip; - // This should only be true on the very first Chrome run; otherwise, - // the cache should be populated. - if (tips_cache_ == NULL || tips_cache_->GetSize() < 1) { - title = kTipsTitleAtStartup; - DictionaryValue* tip_dict = new DictionaryValue(); - tip_dict->SetString(WebResourceService::kWebResourceTitle, title); - tip_dict->SetString(WebResourceService::kWebResourceURL, L""); - list_value.Append(tip_dict); - } else { - int tip_counter = 0; - while (tips_cache_->GetDictionary(IntToWString(tip_counter++), &wr_dict)) { - if (wr_dict && - wr_dict->GetSize() > 0 && - wr_dict->GetString(WebResourceService::kWebResourceTitle, &title) && - wr_dict->GetString(WebResourceService::kWebResourceURL, &url) && - IsValidURL(url)) { + if (tips_cache_ != NULL && tips_cache_->GetSize() >= 0) { + if (tips_cache_->GetInteger( + WebResourceService::kCurrentTipPrefName, ¤t_tip_index) && + tips_cache_->GetList( + WebResourceService::kTipCachePrefName, &wr_list)) { + if (wr_list && wr_list->GetSize() > 0) + if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index)) + current_tip_index = 0; + if (wr_list->GetString(current_tip_index, ¤t_tip)) { DictionaryValue* tip_dict = new DictionaryValue(); - tip_dict->SetString(WebResourceService::kWebResourceTitle, title); - tip_dict->SetString(WebResourceService::kWebResourceURL, url); + tip_dict->SetString(L"tip_html_text", current_tip); list_value.Append(tip_dict); + tips_cache_->SetInteger(WebResourceService::kCurrentTipPrefName, + current_tip_index + 1); } } } diff --git a/chrome/browser/dom_ui/tips_handler.h b/chrome/browser/dom_ui/tips_handler.h index e5afe38..a5915ec 100644 --- a/chrome/browser/dom_ui/tips_handler.h +++ b/chrome/browser/dom_ui/tips_handler.h @@ -6,16 +6,6 @@ // has been stored in the user's preferences file. Used mainly // by the suggestions and tips area of the new tab page. -// Current sketch of tip cache format, hardcoded for popgadget data in -// basic text form: - -// "tip_cache": { -// "0": { -// "title": text giving title of item -// "url": link to item's page -// }, -// [up to number of items in kMaxWebResourceCacheSize] - #ifndef CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ #define CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ @@ -49,7 +39,7 @@ class TipsHandler : public DOMMessageHandler { DOMUI* dom_ui_; // Filled with data from cache in preferences. - const DictionaryValue* tips_cache_; + DictionaryValue* tips_cache_; DISALLOW_COPY_AND_ASSIGN(TipsHandler); }; |