Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: chrome/browser/dom_ui/tips_handler.cc

Issue 6542003: Refactor WebResourceService class, making it more generic. Move all the prom... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: For the records Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/dom_ui/ntp_resource_cache.cc ('k') | chrome/browser/profiles/profile.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/dom_ui/tips_handler.h" 5 #include "chrome/browser/dom_ui/tips_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/web_resource/web_resource_service.h" 15 #include "chrome/browser/web_resource/promo_resource_service.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "chrome/common/web_resource/web_resource_unpacker.h" 17 #include "chrome/common/web_resource/web_resource_unpacker.h"
17 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
18 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
19 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
21 22
22 WebUIMessageHandler* TipsHandler::Attach(WebUI* web_ui) { 23 WebUIMessageHandler* TipsHandler::Attach(WebUI* web_ui) {
23 web_ui_ = web_ui; 24 web_ui_ = web_ui;
24 tips_cache_ = web_ui_->GetProfile()->GetPrefs()-> 25 tips_cache_ = web_ui_->GetProfile()->GetPrefs()->
25 GetMutableDictionary(prefs::kNTPWebResourceCache); 26 GetMutableDictionary(prefs::kNTPPromoResourceCache);
26 return WebUIMessageHandler::Attach(web_ui); 27 return WebUIMessageHandler::Attach(web_ui);
27 } 28 }
28 29
29 void TipsHandler::RegisterMessages() { 30 void TipsHandler::RegisterMessages() {
30 web_ui_->RegisterMessageCallback("getTips", 31 web_ui_->RegisterMessageCallback("getTips",
31 NewCallback(this, &TipsHandler::HandleGetTips)); 32 NewCallback(this, &TipsHandler::HandleGetTips));
32 } 33 }
33 34
34 void TipsHandler::HandleGetTips(const ListValue* args) { 35 void TipsHandler::HandleGetTips(const ListValue* args) {
35 // List containing the tips to be displayed. 36 // List containing the tips to be displayed.
(...skipping 15 matching lines...) Expand all
51 prefs::kNTPTipsResourceServer); 52 prefs::kNTPTipsResourceServer);
52 std::string locale = g_browser_process->GetApplicationLocale(); 53 std::string locale = g_browser_process->GetApplicationLocale();
53 if (!EndsWith(server, locale, false)) { 54 if (!EndsWith(server, locale, false)) {
54 web_ui_->CallJavascriptFunction(L"tips", list_value); 55 web_ui_->CallJavascriptFunction(L"tips", list_value);
55 return; 56 return;
56 } 57 }
57 } 58 }
58 59
59 if (tips_cache_ != NULL && !tips_cache_->empty()) { 60 if (tips_cache_ != NULL && !tips_cache_->empty()) {
60 if (tips_cache_->GetInteger( 61 if (tips_cache_->GetInteger(
61 WebResourceService::kCurrentTipPrefName, &current_tip_index) && 62 PromoResourceService::kCurrentTipPrefName, &current_tip_index) &&
62 tips_cache_->GetList( 63 tips_cache_->GetList(
63 WebResourceService::kTipCachePrefName, &wr_list) && 64 PromoResourceService::kTipCachePrefName, &wr_list) &&
64 wr_list && wr_list->GetSize() > 0) { 65 wr_list && wr_list->GetSize() > 0) {
65 if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index)) { 66 if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index)) {
66 // Check to see whether the home page is set to NTP; if not, add tip 67 // Check to see whether the home page is set to NTP; if not, add tip
67 // to set home page before resetting tip index to 0. 68 // to set home page before resetting tip index to 0.
68 current_tip_index = 0; 69 current_tip_index = 0;
69 const PrefService::Preference* pref = 70 const PrefService::Preference* pref =
70 web_ui_->GetProfile()->GetPrefs()->FindPreference( 71 web_ui_->GetProfile()->GetPrefs()->FindPreference(
71 prefs::kHomePageIsNewTabPage); 72 prefs::kHomePageIsNewTabPage);
72 bool value; 73 bool value;
73 if (pref && !pref->IsManaged() && 74 if (pref && !pref->IsManaged() &&
(...skipping 10 matching lines...) Expand all
84 } 85 }
85 } 86 }
86 87
87 void TipsHandler::SendTip(const std::string& tip, const std::string& tip_type, 88 void TipsHandler::SendTip(const std::string& tip, const std::string& tip_type,
88 int tip_index) { 89 int tip_index) {
89 // List containing the tips to be displayed. 90 // List containing the tips to be displayed.
90 ListValue list_value; 91 ListValue list_value;
91 DictionaryValue* tip_dict = new DictionaryValue(); 92 DictionaryValue* tip_dict = new DictionaryValue();
92 tip_dict->SetString(tip_type, tip); 93 tip_dict->SetString(tip_type, tip);
93 list_value.Append(tip_dict); 94 list_value.Append(tip_dict);
94 tips_cache_->SetInteger(WebResourceService::kCurrentTipPrefName, 95 tips_cache_->SetInteger(PromoResourceService::kCurrentTipPrefName,
95 tip_index); 96 tip_index);
96 // Send list of web resource items back out to the DOM. 97 // Send list of web resource items back out to the DOM.
97 web_ui_->CallJavascriptFunction(L"tips", list_value); 98 web_ui_->CallJavascriptFunction(L"tips", list_value);
98 } 99 }
99 100
100 // static 101 // static
101 void TipsHandler::RegisterUserPrefs(PrefService* prefs) { 102 void TipsHandler::RegisterUserPrefs(PrefService* prefs) {
102 prefs->RegisterDictionaryPref(prefs::kNTPWebResourceCache); 103 prefs->RegisterDictionaryPref(prefs::kNTPPromoResourceCache);
103 prefs->RegisterStringPref(prefs::kNTPWebResourceServer, 104 prefs->RegisterStringPref(prefs::kNTPPromoResourceServer,
104 WebResourceService::kDefaultWebResourceServer); 105 PromoResourceService::kDefaultPromoResourceServer);
105 } 106 }
106 107
107 bool TipsHandler::IsValidURL(const std::wstring& url_string) { 108 bool TipsHandler::IsValidURL(const std::wstring& url_string) {
108 GURL url(WideToUTF8(url_string)); 109 GURL url(WideToUTF8(url_string));
109 return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) || 110 return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) ||
110 url.SchemeIs(chrome::kHttpsScheme)); 111 url.SchemeIs(chrome::kHttpsScheme));
111 } 112 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/ntp_resource_cache.cc ('k') | chrome/browser/profiles/profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698