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

Unified Diff: chrome/browser/web_resource/promo_resource_service.cc

Issue 7655008: promo_resource_service fixes/cleanup for promos. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/web_resource/promo_resource_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/web_resource/promo_resource_service.cc
===================================================================
--- chrome/browser/web_resource/promo_resource_service.cc (revision 97318)
+++ chrome/browser/web_resource/promo_resource_service.cc (working copy)
@@ -48,10 +48,15 @@
static const char kWebStoreLinkProperty[] = "inproduct";
static const char kWebStoreExpireProperty[] = "tooltip";
+chrome::VersionInfo::Channel GetChannel() {
+ // GetChannel hits the registry on Windows. See http://crbug.com/70898.
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+ return chrome::VersionInfo::GetChannel();
+}
+
} // namespace
-// Server for dynamically loaded NTP HTML elements. TODO(mirandac): append
-// locale for future usage, when we're serving localizable strings.
+// Server for dynamically loaded NTP HTML elements.
const char* PromoResourceService::kDefaultPromoResourceServer =
"https://www.google.com/support/chrome/bin/topic/1142433/inproduct?hl=";
@@ -132,11 +137,8 @@
}
bool PromoResourceService::IsThisBuildTargeted(int builds_targeted) {
- if (channel_ == chrome::VersionInfo::CHANNEL_UNKNOWN) {
- // GetChannel hits the registry on Windows. See http://crbug.com/70898.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
- channel_ = chrome::VersionInfo::GetChannel();
- }
+ if (channel_ == chrome::VersionInfo::CHANNEL_UNKNOWN)
+ channel_ = GetChannel();
return IsBuildTargeted(channel_, builds_targeted);
}
@@ -202,28 +204,14 @@
void PromoResourceService::UnpackPromoSignal(
const DictionaryValue& parsed_json) {
DictionaryValue* topic_dict;
- ListValue* answer_list;
- double old_promo_start = 0;
- double old_promo_end = 0;
- double promo_start = 0;
- double promo_end = 0;
- // Check for preexisting start and end values.
- if (prefs_->HasPrefPath(prefs::kNTPPromoStart) &&
- prefs_->HasPrefPath(prefs::kNTPPromoEnd)) {
- old_promo_start = prefs_->GetDouble(prefs::kNTPPromoStart);
- old_promo_end = prefs_->GetDouble(prefs::kNTPPromoEnd);
- }
-
// Check for newly received start and end values.
+ double promo_start = 0.0, promo_end = 0.0;
+ int time_slice_hrs = 0;
if (parsed_json.GetDictionary("topic", &topic_dict)) {
+ ListValue* answer_list;
if (topic_dict->GetList("answers", &answer_list)) {
- std::string promo_start_string = "";
- std::string promo_end_string = "";
- std::string promo_string = "";
- std::string promo_build = "";
- int promo_build_type = 0;
- int time_slice_hrs = 0;
+ std::string promo_start_string, promo_end_string;
for (ListValue::const_iterator answer_iter = answer_list->begin();
answer_iter != answer_list->end(); ++answer_iter) {
if (!(*answer_iter)->IsType(Value::TYPE_DICTIONARY))
@@ -233,8 +221,10 @@
std::string promo_signal;
if (a_dic->GetString("name", &promo_signal)) {
if (promo_signal == "promo_start") {
+ std::string promo_build;
a_dic->GetString("question", &promo_build);
size_t split = promo_build.find(":");
+ int promo_build_type = 0;
if (split != std::string::npos &&
base::StringToInt(promo_build.substr(0, split),
&promo_build_type) &&
@@ -253,8 +243,9 @@
prefs_->SetInteger(prefs::kNTPPromoGroupTimeSlice, 0);
}
a_dic->GetString("inproduct", &promo_start_string);
- a_dic->GetString("tooltip", &promo_string);
- prefs_->SetString(prefs::kNTPPromoLine, promo_string);
+ std::string promo_line;
+ a_dic->GetString("tooltip", &promo_line);
+ prefs_->SetString(prefs::kNTPPromoLine, promo_line);
srand(static_cast<uint32>(time(NULL)));
prefs_->SetInteger(prefs::kNTPPromoGroup,
rand() % kNTPPromoGroupSize);
@@ -263,10 +254,8 @@
}
}
}
- if (!promo_start_string.empty() &&
- promo_start_string.length() > 0 &&
- !promo_end_string.empty() &&
- promo_end_string.length() > 0) {
+
+ if (!promo_start_string.empty() && !promo_end_string.empty()) {
base::Time start_time;
base::Time end_time;
if (base::Time::FromString(promo_start_string.c_str(), &start_time) &&
@@ -282,13 +271,21 @@
}
}
+ // Check for pre-existing start and end values.
+ double old_promo_start = 0.0, old_promo_end = 0.0;
+ if (prefs_->HasPrefPath(prefs::kNTPPromoStart) &&
+ prefs_->HasPrefPath(prefs::kNTPPromoEnd)) {
+ old_promo_start = prefs_->GetDouble(prefs::kNTPPromoStart);
+ old_promo_end = prefs_->GetDouble(prefs::kNTPPromoEnd);
+ }
+
// If start or end times have changed, trigger a new web resource
// notification, so that the logo on the NTP is updated. This check is
// outside the reading of the web resource data, because the absence of
// dates counts as a triggering change if there were dates before.
// Also reset the promo closed preference, to signal a new promo.
- if (!(old_promo_start == promo_start) ||
- !(old_promo_end == promo_end)) {
+ if (old_promo_start != promo_start ||
+ old_promo_end != promo_end) {
prefs_->SetDouble(prefs::kNTPPromoStart, promo_start);
prefs_->SetDouble(prefs::kNTPPromoEnd, promo_end);
prefs_->SetBoolean(prefs::kNTPPromoClosed, false);
@@ -453,30 +450,27 @@
}
}
-namespace PromoResourceServiceUtil {
-
-bool CanShowPromo(Profile* profile) {
- bool promo_closed = false;
+bool PromoResourceService::CanShowPromo(Profile* profile) {
jstritar 2011/08/19 14:56:13 What do you think of renaming this something more
achuithb 2011/08/19 20:16:14 Do you have any suggestions? It looks like this cl
jstritar 2011/08/22 18:06:39 Hmmm... not sure. I guess this type of promo is ca
PrefService* prefs = profile->GetPrefs();
- if (prefs->HasPrefPath(prefs::kNTPPromoClosed))
- promo_closed = prefs->GetBoolean(prefs::kNTPPromoClosed);
- // Only show if not synced.
- bool is_synced =
- (profile->HasProfileSyncService() &&
- sync_ui_util::GetStatus(
- profile->GetProfileSyncService()) == sync_ui_util::SYNCED);
+ // Check if promo has been closed by the user.
+ if (prefs->HasPrefPath(prefs::kNTPPromoClosed) &&
+ prefs->GetBoolean(prefs::kNTPPromoClosed))
+ return false;
- bool is_promo_build = false;
- if (prefs->HasPrefPath(prefs::kNTPPromoBuild)) {
- // GetChannel hits the registry on Windows. See http://crbug.com/70898.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
- chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
- is_promo_build = PromoResourceService::IsBuildTargeted(
- channel, prefs->GetInteger(prefs::kNTPPromoBuild));
- }
+ // Check if our build is appropriate for this promo.
+ if (!prefs->HasPrefPath(prefs::kNTPPromoBuild) ||
+ !IsBuildTargeted(GetChannel(), prefs->GetInteger(prefs::kNTPPromoBuild)))
+ return false;
jstritar 2011/08/19 14:56:13 If we want to avoid calling GetChannel() on the UI
achuithb 2011/08/19 20:16:14 So I looked into doing this. CanShowPromo is a sta
jstritar 2011/08/22 18:06:39 I was thinking something like what we do in Unpack
- return !promo_closed && !is_synced && is_promo_build;
-}
+ // Check if we are in the right time window for this promo.
+ if (!prefs->FindPreference(prefs::kNTPPromoStart) ||
+ !prefs->FindPreference(prefs::kNTPPromoEnd) ||
+ base::Time::FromDoubleT(prefs->GetDouble(prefs::kNTPPromoStart)) >
+ base::Time::Now() ||
+ base::Time::FromDoubleT(prefs->GetDouble(prefs::kNTPPromoEnd)) <
+ base::Time::Now())
+ return false;
-} // namespace PromoResourceServiceUtil
+ return prefs->HasPrefPath(prefs::kNTPPromoLine);
+}
« no previous file with comments | « chrome/browser/web_resource/promo_resource_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698