| 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/platform_util.h" | |
| 14 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/sync/sync_ui_util.h" | 15 #include "chrome/browser/sync/sync_ui_util.h" |
| 16 #include "chrome/common/chrome_version_info.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "content/browser/browser_thread.h" | 18 #include "content/browser/browser_thread.h" |
| 19 #include "content/common/notification_service.h" | 19 #include "content/common/notification_service.h" |
| 20 #include "content/common/notification_type.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; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 prefs->RegisterIntegerPref( | 86 prefs->RegisterIntegerPref( |
| 87 prefs::kNTPPromoBuild, | 87 prefs::kNTPPromoBuild, |
| 88 CANARY_BUILD | DEV_BUILD | BETA_BUILD | STABLE_BUILD, | 88 CANARY_BUILD | DEV_BUILD | BETA_BUILD | STABLE_BUILD, |
| 89 PrefService::UNSYNCABLE_PREF); | 89 PrefService::UNSYNCABLE_PREF); |
| 90 prefs->RegisterIntegerPref(prefs::kNTPPromoGroupTimeSlice, | 90 prefs->RegisterIntegerPref(prefs::kNTPPromoGroupTimeSlice, |
| 91 0, | 91 0, |
| 92 PrefService::UNSYNCABLE_PREF); | 92 PrefService::UNSYNCABLE_PREF); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // static | 95 // static |
| 96 bool PromoResourceService::IsBuildTargeted(platform_util::Channel channel, | 96 bool PromoResourceService::IsBuildTargeted(chrome::VersionInfo::Channel channel, |
| 97 int builds_allowed) { | 97 int builds_allowed) { |
| 98 if (builds_allowed == NO_BUILD) | 98 if (builds_allowed == NO_BUILD) |
| 99 return false; | 99 return false; |
| 100 switch (channel) { | 100 switch (channel) { |
| 101 case platform_util::CHANNEL_CANARY: | 101 case chrome::VersionInfo::CHANNEL_CANARY: |
| 102 return (CANARY_BUILD & builds_allowed) != 0; | 102 return (CANARY_BUILD & builds_allowed) != 0; |
| 103 case platform_util::CHANNEL_DEV: | 103 case chrome::VersionInfo::CHANNEL_DEV: |
| 104 return (DEV_BUILD & builds_allowed) != 0; | 104 return (DEV_BUILD & builds_allowed) != 0; |
| 105 case platform_util::CHANNEL_BETA: | 105 case chrome::VersionInfo::CHANNEL_BETA: |
| 106 return (BETA_BUILD & builds_allowed) != 0; | 106 return (BETA_BUILD & builds_allowed) != 0; |
| 107 case platform_util::CHANNEL_STABLE: | 107 case chrome::VersionInfo::CHANNEL_STABLE: |
| 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, | 115 : WebResourceService(profile, |
| 116 profile->GetPrefs(), | 116 profile->GetPrefs(), |
| 117 PromoResourceService::kDefaultPromoResourceServer, | 117 PromoResourceService::kDefaultPromoResourceServer, |
| 118 true, // append locale to URL | 118 true, // append locale to URL |
| 119 NotificationType::PROMO_RESOURCE_STATE_CHANGED, | 119 NotificationType::PROMO_RESOURCE_STATE_CHANGED, |
| 120 prefs::kNTPPromoResourceCacheUpdate, | 120 prefs::kNTPPromoResourceCacheUpdate, |
| 121 kStartResourceFetchDelay, | 121 kStartResourceFetchDelay, |
| 122 kCacheUpdateDelay), | 122 kCacheUpdateDelay), |
| 123 web_resource_cache_(NULL), | 123 web_resource_cache_(NULL), |
| 124 channel_(platform_util::CHANNEL_UNKNOWN) { | 124 channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) { |
| 125 Init(); | 125 Init(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 PromoResourceService::~PromoResourceService() { } | 128 PromoResourceService::~PromoResourceService() { } |
| 129 | 129 |
| 130 void PromoResourceService::Init() { | 130 void PromoResourceService::Init() { |
| 131 ScheduleNotificationOnInit(); | 131 ScheduleNotificationOnInit(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool PromoResourceService::IsThisBuildTargeted(int builds_targeted) { | 134 bool PromoResourceService::IsThisBuildTargeted(int builds_targeted) { |
| 135 if (channel_ == platform_util::CHANNEL_UNKNOWN) { | 135 if (channel_ == chrome::VersionInfo::CHANNEL_UNKNOWN) { |
| 136 // GetChannel hits the registry on Windows. See http://crbug.com/70898. | 136 // GetChannel hits the registry on Windows. See http://crbug.com/70898. |
| 137 base::ThreadRestrictions::ScopedAllowIO allow_io; | 137 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 138 channel_ = platform_util::GetChannel(); | 138 channel_ = chrome::VersionInfo::GetChannel(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 return IsBuildTargeted(channel_, builds_targeted); | 141 return IsBuildTargeted(channel_, builds_targeted); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) { | 144 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) { |
| 145 UnpackLogoSignal(parsed_json); | 145 UnpackLogoSignal(parsed_json); |
| 146 UnpackPromoSignal(parsed_json); | 146 UnpackPromoSignal(parsed_json); |
| 147 UnpackWebStoreSignal(parsed_json); | 147 UnpackWebStoreSignal(parsed_json); |
| 148 } | 148 } |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 // Only show if not synced. | 468 // Only show if not synced. |
| 469 bool is_synced = | 469 bool is_synced = |
| 470 (profile->HasProfileSyncService() && | 470 (profile->HasProfileSyncService() && |
| 471 sync_ui_util::GetStatus( | 471 sync_ui_util::GetStatus( |
| 472 profile->GetProfileSyncService()) == sync_ui_util::SYNCED); | 472 profile->GetProfileSyncService()) == sync_ui_util::SYNCED); |
| 473 | 473 |
| 474 bool is_promo_build = false; | 474 bool is_promo_build = false; |
| 475 if (prefs->HasPrefPath(prefs::kNTPPromoBuild)) { | 475 if (prefs->HasPrefPath(prefs::kNTPPromoBuild)) { |
| 476 // GetChannel hits the registry on Windows. See http://crbug.com/70898. | 476 // GetChannel hits the registry on Windows. See http://crbug.com/70898. |
| 477 base::ThreadRestrictions::ScopedAllowIO allow_io; | 477 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 478 platform_util::Channel channel = platform_util::GetChannel(); | 478 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 479 is_promo_build = PromoResourceService::IsBuildTargeted( | 479 is_promo_build = PromoResourceService::IsBuildTargeted( |
| 480 channel, prefs->GetInteger(prefs::kNTPPromoBuild)); | 480 channel, prefs->GetInteger(prefs::kNTPPromoBuild)); |
| 481 } | 481 } |
| 482 | 482 |
| 483 return !promo_closed && !is_synced && is_promo_build; | 483 return !promo_closed && !is_synced && is_promo_build; |
| 484 } | 484 } |
| 485 | 485 |
| 486 } // namespace PromoResourceServiceUtil | 486 } // namespace PromoResourceServiceUtil |
| OLD | NEW |