| 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 #ifndef CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
| 6 #define CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ | 6 #define CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "chrome/browser/web_resource/web_resource_service.h" | 11 #include "chrome/browser/web_resource/web_resource_service.h" |
| 12 #include "chrome/common/chrome_version_info.h" | 12 #include "chrome/common/chrome_version_info.h" |
| 13 | 13 |
| 14 class Profile; | 14 class Profile; |
| 15 | |
| 16 namespace PromoResourceServiceUtil { | |
| 17 | |
| 18 // Certain promotions should only be shown to certain classes of users. This | |
| 19 // function will change to reflect each kind of promotion. | |
| 20 bool CanShowPromo(Profile* profile); | |
| 21 | |
| 22 } // namespace PromoResourceServiceUtil | |
| 23 | |
| 24 class PrefService; | 15 class PrefService; |
| 25 | 16 |
| 26 // A PromoResourceService fetches data from a web resource server to be used to | 17 // A PromoResourceService fetches data from a web resource server to be used to |
| 27 // dynamically change the appearance of the New Tab Page. For example, it has | 18 // dynamically change the appearance of the New Tab Page. For example, it has |
| 28 // been used to fetch "tips" to be displayed on the NTP, or to display | 19 // been used to fetch "tips" to be displayed on the NTP, or to display |
| 29 // promotional messages to certain groups of Chrome users. | 20 // promotional messages to certain groups of Chrome users. |
| 30 // | 21 // |
| 31 // TODO(mirandac): Arrange for a server to be set up specifically for promo | 22 // TODO(mirandac): Arrange for a server to be set up specifically for promo |
| 32 // messages, which have until now been piggybacked onto the old tips server | 23 // messages, which have until now been piggybacked onto the old tips server |
| 33 // structure. (see http://crbug.com/70634 for details.) | 24 // structure. (see http://crbug.com/70634 for details.) |
| 34 class PromoResourceService | 25 class PromoResourceService |
| 35 : public WebResourceService { | 26 : public WebResourceService { |
| 36 public: | 27 public: |
| 37 static bool IsBuildTargeted(chrome::VersionInfo::Channel channel, | 28 // Checks for conditions to show promo: start/end times, channel, etc. |
| 38 int builds_targeted); | 29 static bool CanShowPromo(Profile* profile); |
| 39 | 30 |
| 40 static void RegisterPrefs(PrefService* local_state); | 31 static void RegisterPrefs(PrefService* local_state); |
| 41 | 32 |
| 42 static void RegisterUserPrefs(PrefService* prefs); | 33 static void RegisterUserPrefs(PrefService* prefs); |
| 43 | 34 |
| 44 explicit PromoResourceService(Profile* profile); | 35 explicit PromoResourceService(Profile* profile); |
| 45 | 36 |
| 46 // Default server of dynamically loaded NTP HTML elements. | 37 // Default server of dynamically loaded NTP HTML elements. |
| 47 static const char* kDefaultPromoResourceServer; | 38 static const char* kDefaultPromoResourceServer; |
| 48 | 39 |
| 49 private: | 40 private: |
| 41 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, IsBuildTargeted); |
| 50 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackLogoSignal); | 42 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackLogoSignal); |
| 51 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackPromoSignal); | 43 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackPromoSignal); |
| 52 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackWebStoreSignal); | 44 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackWebStoreSignal); |
| 53 FRIEND_TEST_ALL_PREFIXES( | 45 FRIEND_TEST_ALL_PREFIXES( |
| 54 PromoResourceServiceTest, UnpackPartialWebStoreSignal); | 46 PromoResourceServiceTest, UnpackPartialWebStoreSignal); |
| 55 | 47 |
| 56 // Identifies types of Chrome builds for promo targeting. | 48 // Identifies types of Chrome builds for promo targeting. |
| 57 enum BuildType { | 49 enum BuildType { |
| 58 NO_BUILD = 0, | 50 NO_BUILD = 0, |
| 59 DEV_BUILD = 1, | 51 DEV_BUILD = 1, |
| 60 BETA_BUILD = 1 << 1, | 52 BETA_BUILD = 1 << 1, |
| 61 STABLE_BUILD = 1 << 2, | 53 STABLE_BUILD = 1 << 2, |
| 62 CANARY_BUILD = 1 << 3, | 54 CANARY_BUILD = 1 << 3, |
| 63 }; | 55 }; |
| 64 | 56 |
| 65 virtual ~PromoResourceService(); | 57 virtual ~PromoResourceService(); |
| 66 | 58 |
| 67 int GetPromoServiceVersion(); | 59 int GetPromoServiceVersion(); |
| 68 | 60 |
| 69 // Gets the locale of the last promos fetched from the server. This is saved | 61 // Gets the locale of the last promos fetched from the server. This is saved |
| 70 // so we can fetch new data if the locale changes. | 62 // so we can fetch new data if the locale changes. |
| 71 std::string GetPromoLocale(); | 63 std::string GetPromoLocale(); |
| 72 | 64 |
| 73 void Init(); | 65 void Init(); |
| 74 | 66 |
| 67 static bool IsBuildTargeted(chrome::VersionInfo::Channel channel, |
| 68 int builds_targeted); |
| 69 |
| 75 // Returns true if |builds_targeted| includes the release channel Chrome | 70 // Returns true if |builds_targeted| includes the release channel Chrome |
| 76 // belongs to. For testing purposes, you can override the current channel | 71 // belongs to. For testing purposes, you can override the current channel |
| 77 // with set_channel. | 72 // with set_channel. |
| 78 bool IsThisBuildTargeted(int builds_targeted); | 73 bool IsThisBuildTargeted(int builds_targeted); |
| 79 | 74 |
| 80 // Schedule a notification that a web resource is either going to become | 75 // Schedule a notification that a web resource is either going to become |
| 81 // available or be no longer valid. | 76 // available or be no longer valid. |
| 82 void ScheduleNotification(double ms_start_time, double ms_end_time); | 77 void ScheduleNotification(double ms_start_time, double ms_end_time); |
| 83 | 78 |
| 84 // Schedules the initial notification for when the web resource is going | 79 // Schedules the initial notification for when the web resource is going |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // can write resource data back to user's pref file. | 191 // can write resource data back to user's pref file. |
| 197 base::DictionaryValue* web_resource_cache_; | 192 base::DictionaryValue* web_resource_cache_; |
| 198 | 193 |
| 199 // Overrides the current Chrome release channel for testing purposes. | 194 // Overrides the current Chrome release channel for testing purposes. |
| 200 chrome::VersionInfo::Channel channel_; | 195 chrome::VersionInfo::Channel channel_; |
| 201 | 196 |
| 202 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); | 197 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); |
| 203 }; | 198 }; |
| 204 | 199 |
| 205 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ | 200 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
| OLD | NEW |