| OLD | NEW |
| 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/web_resource/promo_resource_service.h" | 5 #include "chrome/browser/web_resource/promo_resource_service.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/extensions/apps_promo.h" | 12 #include "chrome/browser/extensions/apps_promo.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sync/sync_ui_util.h" | 15 #include "chrome/browser/sync/sync_ui_util.h" |
| 16 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
| 19 #include "content/common/notification_service.h" | 20 #include "content/common/notification_service.h" |
| 20 #include "content/common/notification_type.h" | |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Delay on first fetch so we don't interfere with startup. | 25 // Delay on first fetch so we don't interfere with startup. |
| 26 static const int kStartResourceFetchDelay = 5000; | 26 static const int kStartResourceFetchDelay = 5000; |
| 27 | 27 |
| 28 // Delay between calls to update the cache (48 hours). | 28 // Delay between calls to update the cache (48 hours). |
| 29 static const int kCacheUpdateDelay = 48 * 60 * 60 * 1000; | 29 static const int kCacheUpdateDelay = 48 * 60 * 60 * 1000; |
| 30 | 30 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 return (STABLE_BUILD & builds_allowed) != 0; | 108 return (STABLE_BUILD & builds_allowed) != 0; |
| 109 default: | 109 default: |
| 110 return false; | 110 return false; |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 PromoResourceService::PromoResourceService(Profile* profile) | 114 PromoResourceService::PromoResourceService(Profile* profile) |
| 115 : WebResourceService(profile->GetPrefs(), | 115 : WebResourceService(profile->GetPrefs(), |
| 116 PromoResourceService::kDefaultPromoResourceServer, | 116 PromoResourceService::kDefaultPromoResourceServer, |
| 117 true, // append locale to URL | 117 true, // append locale to URL |
| 118 NotificationType::PROMO_RESOURCE_STATE_CHANGED, | 118 chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
| 119 prefs::kNTPPromoResourceCacheUpdate, | 119 prefs::kNTPPromoResourceCacheUpdate, |
| 120 kStartResourceFetchDelay, | 120 kStartResourceFetchDelay, |
| 121 kCacheUpdateDelay), | 121 kCacheUpdateDelay), |
| 122 web_resource_cache_(NULL), | 122 web_resource_cache_(NULL), |
| 123 channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) { | 123 channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) { |
| 124 Init(); | 124 Init(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 PromoResourceService::~PromoResourceService() { } | 127 PromoResourceService::~PromoResourceService() { } |
| 128 | 128 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } | 374 } |
| 375 | 375 |
| 376 if (!signal_found) { | 376 if (!signal_found) { |
| 377 // If no web store promos target this build, then clear all the prefs. | 377 // If no web store promos target this build, then clear all the prefs. |
| 378 AppsPromo::ClearPromo(); | 378 AppsPromo::ClearPromo(); |
| 379 } | 379 } |
| 380 | 380 |
| 381 AppsPromo::SetWebStoreSupportedForLocale(is_webstore_active); | 381 AppsPromo::SetWebStoreSupportedForLocale(is_webstore_active); |
| 382 | 382 |
| 383 NotificationService::current()->Notify( | 383 NotificationService::current()->Notify( |
| 384 NotificationType::WEB_STORE_PROMO_LOADED, | 384 chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, |
| 385 Source<PromoResourceService>(this), | 385 Source<PromoResourceService>(this), |
| 386 NotificationService::NoDetails()); | 386 NotificationService::NoDetails()); |
| 387 | 387 |
| 388 return; | 388 return; |
| 389 } | 389 } |
| 390 | 390 |
| 391 void PromoResourceService::UnpackLogoSignal( | 391 void PromoResourceService::UnpackLogoSignal( |
| 392 const DictionaryValue& parsed_json) { | 392 const DictionaryValue& parsed_json) { |
| 393 DictionaryValue* topic_dict; | 393 DictionaryValue* topic_dict; |
| 394 ListValue* answer_list; | 394 ListValue* answer_list; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 443 |
| 444 // If logo start or end times have changed, trigger a new web resource | 444 // If logo start or end times have changed, trigger a new web resource |
| 445 // notification, so that the logo on the NTP is updated. This check is | 445 // notification, so that the logo on the NTP is updated. This check is |
| 446 // outside the reading of the web resource data, because the absence of | 446 // outside the reading of the web resource data, because the absence of |
| 447 // dates counts as a triggering change if there were dates before. | 447 // dates counts as a triggering change if there were dates before. |
| 448 if (!(old_logo_start == logo_start) || | 448 if (!(old_logo_start == logo_start) || |
| 449 !(old_logo_end == logo_end)) { | 449 !(old_logo_end == logo_end)) { |
| 450 prefs_->SetDouble(prefs::kNTPCustomLogoStart, logo_start); | 450 prefs_->SetDouble(prefs::kNTPCustomLogoStart, logo_start); |
| 451 prefs_->SetDouble(prefs::kNTPCustomLogoEnd, logo_end); | 451 prefs_->SetDouble(prefs::kNTPCustomLogoEnd, logo_end); |
| 452 NotificationService* service = NotificationService::current(); | 452 NotificationService* service = NotificationService::current(); |
| 453 service->Notify(NotificationType::PROMO_RESOURCE_STATE_CHANGED, | 453 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
| 454 Source<WebResourceService>(this), | 454 Source<WebResourceService>(this), |
| 455 NotificationService::NoDetails()); | 455 NotificationService::NoDetails()); |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 | 458 |
| 459 namespace PromoResourceServiceUtil { | 459 namespace PromoResourceServiceUtil { |
| 460 | 460 |
| 461 bool CanShowPromo(Profile* profile) { | 461 bool CanShowPromo(Profile* profile) { |
| 462 bool promo_closed = false; | 462 bool promo_closed = false; |
| 463 PrefService* prefs = profile->GetPrefs(); | 463 PrefService* prefs = profile->GetPrefs(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 476 base::ThreadRestrictions::ScopedAllowIO allow_io; | 476 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 477 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 477 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 478 is_promo_build = PromoResourceService::IsBuildTargeted( | 478 is_promo_build = PromoResourceService::IsBuildTargeted( |
| 479 channel, prefs->GetInteger(prefs::kNTPPromoBuild)); | 479 channel, prefs->GetInteger(prefs::kNTPPromoBuild)); |
| 480 } | 480 } |
| 481 | 481 |
| 482 return !promo_closed && !is_synced && is_promo_build; | 482 return !promo_closed && !is_synced && is_promo_build; |
| 483 } | 483 } |
| 484 | 484 |
| 485 } // namespace PromoResourceServiceUtil | 485 } // namespace PromoResourceServiceUtil |
| OLD | NEW |