Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_resource/promo_resource_service.h" | 5 #include "chrome/browser/web_resource/promo_resource_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Delay on first fetch so we don't interfere with startup. | 29 // Delay on first fetch so we don't interfere with startup. |
| 30 static const int kStartResourceFetchDelay = 5000; | 30 static const int kStartResourceFetchDelay = 5000; |
| 31 | 31 |
| 32 // Delay between calls to update the cache (12 hours), and 3 min in debug mode. | 32 // Delay between calls to update the cache (12 hours), and 3 min in debug mode. |
| 33 static const int kCacheUpdateDelay = 12 * 60 * 60 * 1000; | 33 static const int kCacheUpdateDelay = 12 * 60 * 60 * 1000; |
| 34 static const int kTestCacheUpdateDelay = 3 * 60 * 1000; | 34 static const int kTestCacheUpdateDelay = 3 * 60 * 1000; |
|
Dan Beam
2012/06/04 18:41:04
I think this should be a separate flag, personally
achuithb
2012/06/04 19:52:59
We probably already have too many chrome flags. We
| |
| 35 | 35 |
| 36 // The version of the service (used to expire the cache when upgrading Chrome | 36 // The version of the service (used to expire the cache when upgrading Chrome |
| 37 // to versions with different types of promos). | 37 // to versions with different types of promos). |
| 38 static const int kPromoServiceVersion = 7; | 38 static const int kPromoServiceVersion = 7; |
| 39 | 39 |
| 40 // Properties used by the server. | 40 // Properties used by the server. |
| 41 static const char kAnswerIdProperty[] = "answer_id"; | 41 static const char kAnswerIdProperty[] = "answer_id"; |
| 42 static const char kWebStoreHeaderProperty[] = "question"; | 42 static const char kWebStoreHeaderProperty[] = "question"; |
| 43 static const char kWebStoreButtonProperty[] = "inproduct_target"; | 43 static const char kWebStoreButtonProperty[] = "inproduct_target"; |
| 44 static const char kWebStoreLinkProperty[] = "inproduct"; | 44 static const char kWebStoreLinkProperty[] = "inproduct"; |
| 45 static const char kWebStoreExpireProperty[] = "tooltip"; | 45 static const char kWebStoreExpireProperty[] = "tooltip"; |
| 46 | 46 |
| 47 GURL GetPromoResourceURL(bool legacy) { | 47 GURL GetPromoResourceURL(bool legacy) { |
| 48 const std::string promo_server_url = CommandLine::ForCurrentProcess()-> | 48 const std::string promo_server_url = CommandLine::ForCurrentProcess()-> |
| 49 GetSwitchValueASCII(switches::kPromoServerURL); | 49 GetSwitchValueASCII(switches::kPromoServerURL); |
| 50 if (!promo_server_url.empty()) | 50 if (!promo_server_url.empty()) |
| 51 return GURL(promo_server_url); | 51 return GURL(promo_server_url); |
| 52 return legacy ? GURL(PromoResourceService::kDefaultPromoResourceServer) : | 52 return legacy ? GURL(PromoResourceService::kDefaultPromoResourceServer) : |
| 53 NotificationPromo::PromoServerURL(); | 53 NotificationPromo::PromoServerURL(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool IsTest() { | 56 bool IsTest() { |
| 57 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kPromoServerURL); | 57 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kPromoServerURL); |
|
Dan Beam
2012/06/04 18:20:08
is it time to add something else here that delays
achuithb
2012/06/04 19:52:59
Let's punt this for now.
| |
| 58 } | 58 } |
| 59 | 59 |
| 60 int GetCacheUpdateDelay() { | 60 int GetCacheUpdateDelay() { |
| 61 return IsTest() ? kTestCacheUpdateDelay : kCacheUpdateDelay; | 61 return IsTest() ? kTestCacheUpdateDelay : kCacheUpdateDelay; |
|
Dan Beam
2012/06/04 18:41:04
I'd prefer to separate this logic / control this w
achuithb
2012/06/04 19:52:59
Punt for now.
| |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 // Server for dynamically loaded NTP HTML elements. | 66 // Server for dynamically loaded NTP HTML elements. |
| 67 const char* PromoResourceService::kDefaultPromoResourceServer = | 67 const char* PromoResourceService::kDefaultPromoResourceServer = |
|
Dan Beam
2012/06/04 18:41:04
legacy
achuithb
2012/06/04 19:52:59
Done.
| |
| 68 "https://www.google.com/support/chrome/bin/topic/1142433/inproduct?hl="; | 68 "https://www.google.com/support/chrome/bin/topic/1142433/inproduct?hl="; |
| 69 | 69 |
| 70 | 70 |
| 71 | 71 |
| 72 // static | 72 // static |
| 73 void PromoResourceService::RegisterPrefs(PrefService* local_state) { | 73 void PromoResourceService::RegisterPrefs(PrefService* local_state) { |
| 74 local_state->RegisterIntegerPref(prefs::kNtpPromoVersion, 0); | 74 local_state->RegisterIntegerPref(prefs::kNtpPromoVersion, 0); |
|
Dan Beam
2012/06/04 18:41:04
is this still truly global, or can there be differ
achuithb
2012/06/04 19:52:59
It makes sense for it to be truly global, but I do
| |
| 75 local_state->RegisterStringPref(prefs::kNtpPromoLocale, std::string()); | 75 local_state->RegisterStringPref(prefs::kNtpPromoLocale, std::string()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // static | 78 // static |
| 79 void PromoResourceService::RegisterUserPrefs(PrefService* prefs) { | 79 void PromoResourceService::RegisterUserPrefs(PrefService* prefs) { |
| 80 prefs->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate, | 80 prefs->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate, |
| 81 "0", | 81 "0", |
| 82 PrefService::UNSYNCABLE_PREF); | 82 PrefService::UNSYNCABLE_PREF); |
| 83 prefs->RegisterDoublePref(prefs::kNtpCustomLogoStart, | 83 prefs->RegisterDoublePref(prefs::kNtpCustomLogoStart, |
| 84 0, | 84 0, |
| 85 PrefService::UNSYNCABLE_PREF); | 85 PrefService::UNSYNCABLE_PREF); |
| 86 prefs->RegisterDoublePref(prefs::kNtpCustomLogoEnd, | 86 prefs->RegisterDoublePref(prefs::kNtpCustomLogoEnd, |
| 87 0, | 87 0, |
| 88 PrefService::UNSYNCABLE_PREF); | 88 PrefService::UNSYNCABLE_PREF); |
| 89 NotificationPromo::RegisterUserPrefs(prefs); | 89 NotificationPromo::RegisterUserPrefs(prefs); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // static | 92 // static |
| 93 chrome::VersionInfo::Channel PromoResourceService::GetChannel() { | 93 chrome::VersionInfo::Channel PromoResourceService::GetChannel() { |
| 94 // GetChannel hits the registry on Windows. See http://crbug.com/70898. | 94 // GetChannel hits the registry on Windows. See http://crbug.com/70898. |
| 95 base::ThreadRestrictions::ScopedAllowIO allow_io; | 95 base::ThreadRestrictions::ScopedAllowIO allow_io; |
|
Dan Beam
2012/06/04 18:41:04
would it be worth doing an #if defined(OS_WINDOWS)
achuithb
2012/06/04 19:52:59
Hopefully we can delete this.
| |
| 96 return chrome::VersionInfo::GetChannel(); | 96 return chrome::VersionInfo::GetChannel(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // static | 99 // static |
| 100 bool PromoResourceService::IsBuildTargeted(chrome::VersionInfo::Channel channel, | 100 bool PromoResourceService::IsBuildTargeted(chrome::VersionInfo::Channel channel, |
|
Dan Beam
2012/06/04 18:41:04
why do we still need this? or perhaps only keep th
achuithb
2012/06/04 19:52:59
flag check?
It's used in UnpackWebstoreSignal
Dan Beam
2012/06/04 21:26:32
return CommandLine::ForCurrentProcess()->HasSwitch
| |
| 101 int builds_allowed) { | 101 int builds_allowed) { |
| 102 if (builds_allowed == NO_BUILD || | 102 if (builds_allowed == NO_BUILD || |
| 103 builds_allowed < 0 || | 103 builds_allowed < 0 || |
| 104 builds_allowed > ALL_BUILDS) { | 104 builds_allowed > ALL_BUILDS) { |
| 105 return false; | 105 return false; |
| 106 } | 106 } |
| 107 switch (channel) { | 107 switch (channel) { |
| 108 case chrome::VersionInfo::CHANNEL_CANARY: | 108 case chrome::VersionInfo::CHANNEL_CANARY: |
| 109 return (CANARY_BUILD & builds_allowed) != 0; | 109 return (CANARY_BUILD & builds_allowed) != 0; |
| 110 case chrome::VersionInfo::CHANNEL_DEV: | 110 case chrome::VersionInfo::CHANNEL_DEV: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 | 142 |
| 143 return IsBuildTargeted(channel_, builds_targeted); | 143 return IsBuildTargeted(channel_, builds_targeted); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) { | 146 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) { |
| 147 UnpackLogoSignal(parsed_json); | 147 UnpackLogoSignal(parsed_json); |
| 148 UnpackNotificationSignal(parsed_json); | 148 UnpackNotificationSignal(parsed_json); |
| 149 UnpackWebStoreSignal(parsed_json); | 149 UnpackWebStoreSignal(parsed_json); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void PromoResourceService::OnNotificationParsed(double start, double end, | |
| 153 bool new_notification) { | |
| 154 if (new_notification) { | |
| 155 ScheduleNotification(start, end); | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 void PromoResourceService::ScheduleNotification(double promo_start, | 152 void PromoResourceService::ScheduleNotification(double promo_start, |
| 160 double promo_end) { | 153 double promo_end) { |
| 161 if (promo_start > 0 && promo_end > 0) { | 154 if (promo_start > 0 && promo_end > 0) { |
| 162 int64 ms_until_start = | 155 int64 ms_until_start = |
| 163 static_cast<int64>((base::Time::FromDoubleT( | 156 static_cast<int64>((base::Time::FromDoubleT( |
| 164 promo_start) - base::Time::Now()).InMilliseconds()); | 157 promo_start) - base::Time::Now()).InMilliseconds()); |
| 165 int64 ms_until_end = | 158 int64 ms_until_end = |
| 166 static_cast<int64>((base::Time::FromDoubleT( | 159 static_cast<int64>((base::Time::FromDoubleT( |
| 167 promo_end) - base::Time::Now()).InMilliseconds()); | 160 promo_end) - base::Time::Now()).InMilliseconds()); |
| 168 if (ms_until_start > 0) | 161 if (ms_until_start > 0) |
| 169 PostNotification(ms_until_start); | 162 PostNotification(ms_until_start); |
| 170 if (ms_until_end > 0) { | 163 if (ms_until_end > 0) { |
| 171 PostNotification(ms_until_end); | 164 PostNotification(ms_until_end); |
| 172 if (ms_until_start <= 0) { | 165 if (ms_until_start <= 0) { |
| 173 // Notify immediately if time is between start and end. | 166 // Notify immediately if time is between start and end. |
| 174 PostNotification(0); | 167 PostNotification(0); |
| 175 } | 168 } |
| 176 } | 169 } |
| 177 } | 170 } |
| 178 } | 171 } |
| 179 | 172 |
| 180 void PromoResourceService::ScheduleNotificationOnInit() { | 173 void PromoResourceService::ScheduleNotificationOnInit() { |
| 181 std::string locale = g_browser_process->GetApplicationLocale(); | 174 std::string locale = g_browser_process->GetApplicationLocale(); |
| 182 if ((GetPromoServiceVersion() != kPromoServiceVersion) || | 175 if ((GetPromoServiceVersion() != kPromoServiceVersion) || |
|
Dan Beam
2012/06/04 18:41:04
less ()
achuithb
2012/06/04 19:52:59
Done.
| |
| 183 (GetPromoLocale() != locale)) { | 176 (GetPromoLocale() != locale)) { |
| 184 // If the promo service has been upgraded or Chrome switched locales, | 177 // If the promo service has been upgraded or Chrome switched locales, |
| 185 // refresh the promos. | 178 // refresh the promos. |
| 186 PrefService* local_state = g_browser_process->local_state(); | 179 PrefService* local_state = g_browser_process->local_state(); |
| 187 local_state->SetInteger(prefs::kNtpPromoVersion, kPromoServiceVersion); | 180 local_state->SetInteger(prefs::kNtpPromoVersion, kPromoServiceVersion); |
| 188 local_state->SetString(prefs::kNtpPromoLocale, locale); | 181 local_state->SetString(prefs::kNtpPromoLocale, locale); |
| 189 prefs_->ClearPref(prefs::kNtpPromoResourceCacheUpdate); | 182 prefs_->ClearPref(prefs::kNtpPromoResourceCacheUpdate); |
| 190 AppsPromo::ClearPromo(); | 183 AppsPromo::ClearPromo(); |
| 191 PostNotification(0); | 184 PostNotification(0); |
| 192 } else { | 185 } else { |
| 193 // If the promo start is in the future, set a notification task to | 186 // If the promo start is in the future, set a notification task to |
| 194 // invalidate the NTP cache at the time of the promo start. | 187 // invalidate the NTP cache at the time of the promo start. |
| 195 double promo_start = prefs_->GetDouble(prefs::kNtpPromoStart); | 188 double promo_start = prefs_->GetDouble(prefs::kNtpPromoStart); |
| 196 double promo_end = prefs_->GetDouble(prefs::kNtpPromoEnd); | 189 double promo_end = prefs_->GetDouble(prefs::kNtpPromoEnd); |
| 197 ScheduleNotification(promo_start, promo_end); | 190 ScheduleNotification(promo_start, promo_end); |
| 198 } | 191 } |
| 199 } | 192 } |
| 200 | 193 |
| 201 void PromoResourceService::PostNotification(int64 delay_ms) { | 194 void PromoResourceService::PostNotification(int64 delay_ms) { |
| 202 if (web_resource_update_scheduled_) | 195 if (web_resource_update_scheduled_) |
| 203 return; | 196 return; |
| 204 if (delay_ms > 0) { | 197 if (delay_ms > 0) { |
| 205 web_resource_update_scheduled_ = true; | 198 web_resource_update_scheduled_ = true; |
| 206 MessageLoop::current()->PostDelayedTask( | 199 MessageLoop::current()->PostDelayedTask( |
| 207 FROM_HERE, | 200 FROM_HERE, |
| 208 base::Bind(&PromoResourceService::PromoResourceStateChange, | 201 base::Bind(&PromoResourceService::PromoResourceStateChange, |
| 209 weak_ptr_factory_.GetWeakPtr()), | 202 weak_ptr_factory_.GetWeakPtr()), |
| 210 base::TimeDelta::FromMilliseconds(delay_ms)); | 203 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 211 } else if (delay_ms == 0) { | 204 } else if (delay_ms == 0) { |
|
Dan Beam
2012/06/04 18:41:04
I think we should still post a task with 0 ms isnt
achuithb
2012/06/04 19:52:59
I tried that, and it crashes on Init, possibly bec
Dan Beam
2012/06/04 21:26:32
TODO() or comment, then?
achuithb
2012/06/04 23:06:08
Done.
| |
| 212 PromoResourceStateChange(); | 205 PromoResourceStateChange(); |
| 213 } | 206 } |
| 214 } | 207 } |
| 215 | 208 |
| 216 void PromoResourceService::PromoResourceStateChange() { | 209 void PromoResourceService::PromoResourceStateChange() { |
| 217 web_resource_update_scheduled_ = false; | 210 web_resource_update_scheduled_ = false; |
| 218 content::NotificationService* service = | 211 content::NotificationService* service = |
| 219 content::NotificationService::current(); | 212 content::NotificationService::current(); |
| 220 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 213 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
| 221 content::Source<WebResourceService>(this), | 214 content::Source<WebResourceService>(this), |
| 222 content::NotificationService::NoDetails()); | 215 content::NotificationService::NoDetails()); |
| 223 } | 216 } |
| 224 | 217 |
| 225 int PromoResourceService::GetPromoServiceVersion() { | 218 int PromoResourceService::GetPromoServiceVersion() { |
| 226 PrefService* local_state = g_browser_process->local_state(); | 219 PrefService* local_state = g_browser_process->local_state(); |
| 227 return local_state->GetInteger(prefs::kNtpPromoVersion); | 220 return local_state->GetInteger(prefs::kNtpPromoVersion); |
| 228 } | 221 } |
| 229 | 222 |
| 230 std::string PromoResourceService::GetPromoLocale() { | 223 std::string PromoResourceService::GetPromoLocale() { |
| 231 PrefService* local_state = g_browser_process->local_state(); | 224 PrefService* local_state = g_browser_process->local_state(); |
| 232 return local_state->GetString(prefs::kNtpPromoLocale); | 225 return local_state->GetString(prefs::kNtpPromoLocale); |
| 233 } | 226 } |
| 234 | 227 |
| 235 void PromoResourceService::UnpackNotificationSignal( | 228 void PromoResourceService::UnpackNotificationSignal( |
| 236 const DictionaryValue& parsed_json) { | 229 const DictionaryValue& parsed_json) { |
| 237 scoped_refptr<NotificationPromo> notification_promo = | 230 NotificationPromo notification_promo(profile_); |
| 238 NotificationPromo::Create(profile_, this); | 231 notification_promo.InitFromJson(parsed_json); |
| 239 notification_promo->InitFromJson(parsed_json); | 232 |
| 233 if (notification_promo.new_notification()) { | |
| 234 ScheduleNotification(notification_promo.StartTimeForGroup(), | |
| 235 notification_promo.EndTime()); | |
| 236 } | |
| 240 } | 237 } |
| 241 | 238 |
| 242 bool PromoResourceService::CanShowNotificationPromo(Profile* profile) { | 239 bool PromoResourceService::CanShowNotificationPromo(Profile* profile) { |
| 243 scoped_refptr<NotificationPromo> notification_promo = | 240 NotificationPromo notification_promo(profile); |
| 244 NotificationPromo::Create(profile, NULL); | 241 notification_promo.InitFromPrefs(); |
| 245 notification_promo->InitFromPrefs(); | 242 return notification_promo.CanShow(); |
| 246 return notification_promo->CanShow(); | |
| 247 } | 243 } |
| 248 | 244 |
| 249 void PromoResourceService::UnpackWebStoreSignal( | 245 void PromoResourceService::UnpackWebStoreSignal( |
|
Dan Beam
2012/06/04 18:41:04
if we're not using the tips server, how is any of
achuithb
2012/06/04 19:52:59
Chatted about this; Tips server continues to be us
| |
| 250 const DictionaryValue& parsed_json) { | 246 const DictionaryValue& parsed_json) { |
| 251 DictionaryValue* topic_dict; | 247 DictionaryValue* topic_dict; |
| 252 ListValue* answer_list; | 248 ListValue* answer_list; |
| 253 | 249 |
| 254 bool is_webstore_active = false; | 250 bool is_webstore_active = false; |
| 255 bool signal_found = false; | 251 bool signal_found = false; |
| 256 AppsPromo::PromoData promo_data; | 252 AppsPromo::PromoData promo_data; |
| 257 std::string promo_link = ""; | 253 std::string promo_link = ""; |
| 258 std::string promo_logo = ""; | 254 std::string promo_logo = ""; |
| 259 int target_builds = 0; | 255 int target_builds = 0; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 // NOTIFICATION_WEB_STORE_PROMO_LOADED notification. | 309 // NOTIFICATION_WEB_STORE_PROMO_LOADED notification. |
| 314 promo_data.link = GURL(promo_link); | 310 promo_data.link = GURL(promo_link); |
| 315 promo_data.logo = GURL(promo_logo); | 311 promo_data.logo = GURL(promo_logo); |
| 316 apps_promo_logo_fetcher_.reset( | 312 apps_promo_logo_fetcher_.reset( |
| 317 new AppsPromoLogoFetcher(profile_, promo_data)); | 313 new AppsPromoLogoFetcher(profile_, promo_data)); |
| 318 signal_found = true; | 314 signal_found = true; |
| 319 break; | 315 break; |
| 320 } | 316 } |
| 321 } | 317 } |
| 322 | 318 |
| 323 if (!signal_found) { | 319 if (!signal_found) { |
|
Dan Beam
2012/06/04 18:41:04
move comment out and remove curlies, IMO
achuithb
2012/06/04 19:52:59
Hopefully we'll delete this code.
| |
| 324 // If no web store promos target this build, then clear all the prefs. | 320 // If no web store promos target this build, then clear all the prefs. |
| 325 AppsPromo::ClearPromo(); | 321 AppsPromo::ClearPromo(); |
| 326 } | 322 } |
| 327 | 323 |
| 328 AppsPromo::SetWebStoreSupportedForLocale(is_webstore_active); | 324 AppsPromo::SetWebStoreSupportedForLocale(is_webstore_active); |
| 329 | 325 |
| 330 return; | 326 return; |
| 331 } | 327 } |
| 332 | 328 |
| 333 void PromoResourceService::UnpackLogoSignal( | 329 void PromoResourceService::UnpackLogoSignal( |
|
Dan Beam
2012/06/04 18:41:04
same story here with legacy code probably not bein
achuithb
2012/06/04 19:52:59
Will send an email, etc.
| |
| 334 const DictionaryValue& parsed_json) { | 330 const DictionaryValue& parsed_json) { |
| 335 DictionaryValue* topic_dict; | 331 DictionaryValue* topic_dict; |
| 336 ListValue* answer_list; | 332 ListValue* answer_list; |
| 337 double old_logo_start = 0; | 333 double old_logo_start = 0; |
| 338 double old_logo_end = 0; | 334 double old_logo_end = 0; |
| 339 double logo_start = 0; | 335 double logo_start = 0; |
| 340 double logo_end = 0; | 336 double logo_end = 0; |
| 341 | 337 |
| 342 // Check for preexisting start and end values. | 338 // Check for preexisting start and end values. |
| 343 if (prefs_->HasPrefPath(prefs::kNtpCustomLogoStart) && | 339 if (prefs_->HasPrefPath(prefs::kNtpCustomLogoStart) && |
| 344 prefs_->HasPrefPath(prefs::kNtpCustomLogoEnd)) { | 340 prefs_->HasPrefPath(prefs::kNtpCustomLogoEnd)) { |
| 345 old_logo_start = prefs_->GetDouble(prefs::kNtpCustomLogoStart); | 341 old_logo_start = prefs_->GetDouble(prefs::kNtpCustomLogoStart); |
| 346 old_logo_end = prefs_->GetDouble(prefs::kNtpCustomLogoEnd); | 342 old_logo_end = prefs_->GetDouble(prefs::kNtpCustomLogoEnd); |
| 347 } | 343 } |
| 348 | 344 |
| 349 // Check for newly received start and end values. | 345 // Check for newly received start and end values. |
| 350 if (parsed_json.GetDictionary("topic", &topic_dict)) { | 346 if (parsed_json.GetDictionary("topic", &topic_dict)) { |
| 351 if (topic_dict->GetList("answers", &answer_list)) { | 347 if (topic_dict->GetList("answers", &answer_list)) { |
| 352 std::string logo_start_string = ""; | 348 std::string logo_start_string = ""; |
| 353 std::string logo_end_string = ""; | 349 std::string logo_end_string = ""; |
| 354 for (ListValue::const_iterator answer_iter = answer_list->begin(); | 350 for (ListValue::const_iterator answer_iter = answer_list->begin(); |
| 355 answer_iter != answer_list->end(); ++answer_iter) { | 351 answer_iter != answer_list->end(); ++answer_iter) { |
| 356 if (!(*answer_iter)->IsType(Value::TYPE_DICTIONARY)) | 352 if (!(*answer_iter)->IsType(Value::TYPE_DICTIONARY)) |
| 357 continue; | 353 continue; |
| 358 DictionaryValue* a_dic = | 354 DictionaryValue* a_dic = |
| 359 static_cast<DictionaryValue*>(*answer_iter); | 355 static_cast<DictionaryValue*>(*answer_iter); |
| 360 std::string logo_signal; | 356 std::string logo_signal; |
| 361 if (a_dic->GetString("name", &logo_signal)) { | 357 if (a_dic->GetString("name", &logo_signal)) { |
| 362 if (logo_signal == "custom_logo_start") { | 358 if (logo_signal == "custom_logo_start") { |
|
Dan Beam
2012/06/04 18:41:04
no curlies
achuithb
2012/06/04 19:52:59
Hopefully delete this
| |
| 363 a_dic->GetString("inproduct", &logo_start_string); | 359 a_dic->GetString("inproduct", &logo_start_string); |
| 364 } else if (logo_signal == "custom_logo_end") { | 360 } else if (logo_signal == "custom_logo_end") { |
| 365 a_dic->GetString("inproduct", &logo_end_string); | 361 a_dic->GetString("inproduct", &logo_end_string); |
| 366 } | 362 } |
| 367 } | 363 } |
| 368 } | 364 } |
| 369 if (!logo_start_string.empty() && | 365 if (!logo_start_string.empty() && |
| 370 logo_start_string.length() > 0 && | 366 logo_start_string.length() > 0 && |
| 371 !logo_end_string.empty() && | 367 !logo_end_string.empty() && |
| 372 logo_end_string.length() > 0) { | 368 logo_end_string.length() > 0) { |
| 373 base::Time start_time; | 369 base::Time start_time; |
| 374 base::Time end_time; | 370 base::Time end_time; |
| 375 if (base::Time::FromString(logo_start_string.c_str(), &start_time) && | 371 if (base::Time::FromString(logo_start_string.c_str(), &start_time) && |
| 376 base::Time::FromString(logo_end_string.c_str(), &end_time)) { | 372 base::Time::FromString(logo_end_string.c_str(), &end_time)) { |
| 377 logo_start = start_time.ToDoubleT(); | 373 logo_start = start_time.ToDoubleT(); |
| 378 logo_end = end_time.ToDoubleT(); | 374 logo_end = end_time.ToDoubleT(); |
| 379 } | 375 } |
| 380 } | 376 } |
| 381 } | 377 } |
| 382 } | 378 } |
| 383 | 379 |
| 384 // If logo start or end times have changed, trigger a new web resource | 380 // If logo start or end times have changed, trigger a new web resource |
| 385 // notification, so that the logo on the NTP is updated. This check is | 381 // notification, so that the logo on the NTP is updated. This check is |
| 386 // outside the reading of the web resource data, because the absence of | 382 // outside the reading of the web resource data, because the absence of |
| 387 // dates counts as a triggering change if there were dates before. | 383 // dates counts as a triggering change if there were dates before. |
| 388 if (!(old_logo_start == logo_start) || | 384 if (!(old_logo_start == logo_start) || |
|
Dan Beam
2012/06/04 18:41:04
demorgan's law + less ()
achuithb
2012/06/04 19:52:59
hopefully delete this.
| |
| 389 !(old_logo_end == logo_end)) { | 385 !(old_logo_end == logo_end)) { |
| 390 prefs_->SetDouble(prefs::kNtpCustomLogoStart, logo_start); | 386 prefs_->SetDouble(prefs::kNtpCustomLogoStart, logo_start); |
| 391 prefs_->SetDouble(prefs::kNtpCustomLogoEnd, logo_end); | 387 prefs_->SetDouble(prefs::kNtpCustomLogoEnd, logo_end); |
| 392 content::NotificationService* service = | 388 content::NotificationService* service = |
| 393 content::NotificationService::current(); | 389 content::NotificationService::current(); |
| 394 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 390 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
| 395 content::Source<WebResourceService>(this), | 391 content::Source<WebResourceService>(this), |
| 396 content::NotificationService::NoDetails()); | 392 content::NotificationService::NoDetails()); |
| 397 } | 393 } |
| 398 } | 394 } |
| OLD | NEW |