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

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

Issue 10539045: Purge Logo/WebstoreSignal. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: missed a file Created 8 years, 6 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
Index: chrome/browser/web_resource/promo_resource_service.cc
===================================================================
--- chrome/browser/web_resource/promo_resource_service.cc (revision 140512)
+++ chrome/browser/web_resource/promo_resource_service.cc (working copy)
@@ -5,20 +5,14 @@
#include "chrome/browser/web_resource/promo_resource_service.h"
#include "base/command_line.h"
-#include "base/rand_util.h"
-#include "base/string_number_conversions.h"
+#include "base/message_loop.h"
#include "base/threading/thread_restrictions.h"
-#include "base/time.h"
-#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/extensions/apps_promo.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
@@ -37,13 +31,6 @@
// to versions with different types of promos).
static const int kPromoServiceVersion = 7;
-// Properties used by the server.
-static const char kAnswerIdProperty[] = "answer_id";
-static const char kWebStoreHeaderProperty[] = "question";
-static const char kWebStoreButtonProperty[] = "inproduct_target";
-static const char kWebStoreLinkProperty[] = "inproduct";
-static const char kWebStoreExpireProperty[] = "tooltip";
-
GURL GetPromoResourceURL() {
const std::string promo_server_url = CommandLine::ForCurrentProcess()->
GetSwitchValueASCII(switches::kPromoServerURL);
@@ -72,46 +59,19 @@
prefs->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate,
"0",
PrefService::UNSYNCABLE_PREF);
+ NotificationPromo::RegisterUserPrefs(prefs);
+
+ // TODO(achuith): Delete this in M21
Dan Beam 2012/06/08 18:49:47 M21 or M22? . and end.
achuithb 2012/06/08 22:29:08 Will fix.
prefs->RegisterDoublePref(prefs::kNtpCustomLogoStart,
0,
PrefService::UNSYNCABLE_PREF);
prefs->RegisterDoublePref(prefs::kNtpCustomLogoEnd,
0,
PrefService::UNSYNCABLE_PREF);
- NotificationPromo::RegisterUserPrefs(prefs);
+ prefs->ClearPref(prefs::kNtpCustomLogoStart);
+ prefs->ClearPref(prefs::kNtpCustomLogoEnd);
}
-// static
-chrome::VersionInfo::Channel PromoResourceService::GetChannel() {
- // GetChannel hits the registry on Windows. See http://crbug.com/70898.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
- return chrome::VersionInfo::GetChannel();
-}
-
-// static
-bool PromoResourceService::IsBuildTargeted(chrome::VersionInfo::Channel channel,
- int builds_allowed) {
- if (builds_allowed == NO_BUILD ||
- builds_allowed < 0 ||
- builds_allowed > ALL_BUILDS) {
- return false;
- }
- switch (channel) {
- case chrome::VersionInfo::CHANNEL_CANARY:
- return (CANARY_BUILD & builds_allowed) != 0;
- case chrome::VersionInfo::CHANNEL_DEV:
- return (DEV_BUILD & builds_allowed) != 0;
- case chrome::VersionInfo::CHANNEL_BETA:
- return (BETA_BUILD & builds_allowed) != 0;
- case chrome::VersionInfo::CHANNEL_STABLE:
- return (STABLE_BUILD & builds_allowed) != 0;
- default:
- // Show promos for local builds when using a custom promo URL.
- return CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kPromoServerURL);
- }
-}
-
PromoResourceService::PromoResourceService(Profile* profile)
: WebResourceService(profile->GetPrefs(),
GetPromoResourceURL(),
@@ -120,34 +80,22 @@
kStartResourceFetchDelay,
GetCacheUpdateDelay()),
profile_(profile),
- channel_(chrome::VersionInfo::CHANNEL_UNKNOWN),
- ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
- web_resource_update_scheduled_(false) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ weak_ptr_factory_(this)),
+ web_resource_update_scheduled_(false) {
ScheduleNotificationOnInit();
}
-PromoResourceService::~PromoResourceService() { }
-
-bool PromoResourceService::IsBuildTargeted(int builds_targeted) {
- if (channel_ == chrome::VersionInfo::CHANNEL_UNKNOWN)
- channel_ = GetChannel();
-
- return IsBuildTargeted(channel_, builds_targeted);
+PromoResourceService::~PromoResourceService() {
}
-void PromoResourceService::Unpack(const DictionaryValue& parsed_json) {
- UnpackLogoSignal(parsed_json);
- UnpackNotificationSignal(parsed_json);
- UnpackWebStoreSignal(parsed_json);
-}
-
void PromoResourceService::ScheduleNotification(double promo_start,
double promo_end) {
if (promo_start > 0 && promo_end > 0) {
- int64 ms_until_start =
+ const int64 ms_until_start =
static_cast<int64>((base::Time::FromDoubleT(
promo_start) - base::Time::Now()).InMilliseconds());
- int64 ms_until_end =
+ const int64 ms_until_end =
static_cast<int64>((base::Time::FromDoubleT(
promo_end) - base::Time::Now()).InMilliseconds());
if (ms_until_start > 0)
@@ -175,7 +123,6 @@
local_state->SetInteger(prefs::kNtpPromoVersion, kPromoServiceVersion);
local_state->SetString(prefs::kNtpPromoLocale, locale);
prefs_->ClearPref(prefs::kNtpPromoResourceCacheUpdate);
- AppsPromo::ClearPromo();
PostNotification(0);
} else {
// If the promo start is in the future, set a notification task to
@@ -222,8 +169,7 @@
return local_state->GetString(prefs::kNtpPromoLocale);
}
-void PromoResourceService::UnpackNotificationSignal(
- const DictionaryValue& parsed_json) {
+void PromoResourceService::Unpack(const DictionaryValue& parsed_json) {
NotificationPromo notification_promo(profile_);
notification_promo.InitFromJson(parsed_json);
@@ -238,154 +184,3 @@
notification_promo.InitFromPrefs();
return notification_promo.CanShow();
}
-
-void PromoResourceService::UnpackWebStoreSignal(
- const DictionaryValue& parsed_json) {
- DictionaryValue* topic_dict;
- ListValue* answer_list;
-
- bool is_webstore_active = false;
- bool signal_found = false;
- AppsPromo::PromoData promo_data;
- std::string promo_link = "";
- std::string promo_logo = "";
- int target_builds = 0;
-
- if (!parsed_json.GetDictionary("topic", &topic_dict) ||
- !topic_dict->GetList("answers", &answer_list))
- return;
-
- for (ListValue::const_iterator answer_iter = answer_list->begin();
- answer_iter != answer_list->end(); ++answer_iter) {
- if (!(*answer_iter)->IsType(Value::TYPE_DICTIONARY))
- continue;
- DictionaryValue* a_dic =
- static_cast<DictionaryValue*>(*answer_iter);
-
- // The "name" field has three different values packed into it, each
- // separated by a ':'.
- std::string name;
- if (!a_dic->GetString("name", &name))
- continue;
-
- // (1) the string "webstore_promo"
- size_t split = name.find(":");
- if (split == std::string::npos || name.substr(0, split) != "webstore_promo")
- continue;
-
- // If the "webstore_promo" string was found, that's enough to activate the
- // apps section even if the rest of the promo fails parsing.
- is_webstore_active = true;
-
- // (2) an integer specifying which builds the promo targets
- name = name.substr(split+1);
- split = name.find(':');
- if (split == std::string::npos ||
- !base::StringToInt(name.substr(0, split), &target_builds))
- continue;
-
- // (3) an integer specifying what users should maximize the promo
- name = name.substr(split+1);
- split = name.find(':');
- if (split == std::string::npos ||
- !base::StringToInt(name.substr(0, split), &promo_data.user_group))
- continue;
-
- // (4) optional text that specifies a URL of a logo image
- promo_logo = name.substr(split+1);
-
- if (!a_dic->GetString(kAnswerIdProperty, &promo_data.id) ||
- !a_dic->GetString(kWebStoreHeaderProperty, &promo_data.header) ||
- !a_dic->GetString(kWebStoreButtonProperty, &promo_data.button) ||
- !a_dic->GetString(kWebStoreLinkProperty, &promo_link) ||
- !a_dic->GetString(kWebStoreExpireProperty, &promo_data.expire))
- continue;
-
- if (IsBuildTargeted(target_builds)) {
- // The downloader will set the promo prefs and send the
- // NOTIFICATION_WEB_STORE_PROMO_LOADED notification.
- promo_data.link = GURL(promo_link);
- promo_data.logo = GURL(promo_logo);
- apps_promo_logo_fetcher_.reset(
- new AppsPromoLogoFetcher(profile_, promo_data));
- signal_found = true;
- break;
- }
- }
-
- if (!signal_found) {
- // If no web store promos target this build, then clear all the prefs.
- AppsPromo::ClearPromo();
- }
-
- AppsPromo::SetWebStoreSupportedForLocale(is_webstore_active);
-
- return;
-}
-
-void PromoResourceService::UnpackLogoSignal(
- const DictionaryValue& parsed_json) {
- DictionaryValue* topic_dict;
- ListValue* answer_list;
- double old_logo_start = 0;
- double old_logo_end = 0;
- double logo_start = 0;
- double logo_end = 0;
-
- // Check for preexisting start and end values.
- if (prefs_->HasPrefPath(prefs::kNtpCustomLogoStart) &&
- prefs_->HasPrefPath(prefs::kNtpCustomLogoEnd)) {
- old_logo_start = prefs_->GetDouble(prefs::kNtpCustomLogoStart);
- old_logo_end = prefs_->GetDouble(prefs::kNtpCustomLogoEnd);
- }
-
- // Check for newly received start and end values.
- if (parsed_json.GetDictionary("topic", &topic_dict)) {
- if (topic_dict->GetList("answers", &answer_list)) {
- std::string logo_start_string = "";
- std::string logo_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))
- continue;
- DictionaryValue* a_dic =
- static_cast<DictionaryValue*>(*answer_iter);
- std::string logo_signal;
- if (a_dic->GetString("name", &logo_signal)) {
- if (logo_signal == "custom_logo_start") {
- a_dic->GetString("inproduct", &logo_start_string);
- } else if (logo_signal == "custom_logo_end") {
- a_dic->GetString("inproduct", &logo_end_string);
- }
- }
- }
- if (!logo_start_string.empty() &&
- logo_start_string.length() > 0 &&
- !logo_end_string.empty() &&
- logo_end_string.length() > 0) {
- base::Time start_time;
- base::Time end_time;
- if (base::Time::FromString(logo_start_string.c_str(), &start_time) &&
- base::Time::FromString(logo_end_string.c_str(), &end_time)) {
- logo_start = start_time.ToDoubleT();
- logo_end = end_time.ToDoubleT();
- }
- }
- }
- }
-
- // If logo 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.
- if (!(old_logo_start == logo_start) ||
- !(old_logo_end == logo_end)) {
- prefs_->SetDouble(prefs::kNtpCustomLogoStart, logo_start);
- prefs_->SetDouble(prefs::kNtpCustomLogoEnd, logo_end);
- content::NotificationService* service =
- content::NotificationService::current();
- service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
- content::Source<WebResourceService>(this),
- content::NotificationService::NoDetails());
- }
-}

Powered by Google App Engine
This is Rietveld 408576698