OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
| 6 #define CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "chrome/browser/web_resource/web_resource_service.h" |
| 10 |
| 11 namespace PromoResourceServiceUtil { |
| 12 |
| 13 // Certain promotions should only be shown to certain classes of users. This |
| 14 // function will change to reflect each kind of promotion. |
| 15 bool CanShowPromo(Profile* profile); |
| 16 |
| 17 } // namespace PromoResourceServiceUtil |
| 18 |
| 19 // A PromoResourceService fetches data from a web resource server to be used to |
| 20 // dynamically change the appearance of the New Tab Page. For example, it has |
| 21 // been used to fetch "tips" to be displayed on the NTP, or to display |
| 22 // promotional messages to certain groups of Chrome users. |
| 23 // |
| 24 // TODO(mirandac): Arrange for a server to be set up specifically for promo |
| 25 // messages, which have until now been piggybacked onto the old tips server |
| 26 // structure. (see http://crbug.com/70634 for details.) |
| 27 class PromoResourceService |
| 28 : public WebResourceService { |
| 29 public: |
| 30 explicit PromoResourceService(Profile* profile); |
| 31 |
| 32 // Unpack the web resource as a set of tips. Expects json in the form of: |
| 33 // { |
| 34 // "lang": "en", |
| 35 // "topic": { |
| 36 // "topid_id": "24013", |
| 37 // "topics": [ |
| 38 // ], |
| 39 // "answers": [ |
| 40 // { |
| 41 // "answer_id": "18625", |
| 42 // "inproduct": "Text here will be shown as a tip", |
| 43 // }, |
| 44 // ... |
| 45 // ] |
| 46 // } |
| 47 // } |
| 48 // |
| 49 // Public for unit testing. |
| 50 void UnpackTips(const DictionaryValue& parsed_json); |
| 51 |
| 52 // Unpack the web resource as a custom promo signal. Expects a start and end |
| 53 // signal, with the promo to be shown in the tooltip of the start signal |
| 54 // field. Delivery will be in json in the form of: |
| 55 // { |
| 56 // "topic": { |
| 57 // "answers": [ |
| 58 // { |
| 59 // "answer_id": "1067976", |
| 60 // "name": "promo_start", |
| 61 // "question": "1:24", |
| 62 // "tooltip": |
| 63 // "Click \u003ca href=http://www.google.com\u003ehere\u003c/a\u003e!", |
| 64 // "inproduct": "10/8/09 12:00", |
| 65 // "inproduct_target": null |
| 66 // }, |
| 67 // { |
| 68 // "answer_id": "1067976", |
| 69 // "name": "promo_end", |
| 70 // "question": "", |
| 71 // "tooltip": "", |
| 72 // "inproduct": "10/8/11 12:00", |
| 73 // "inproduct_target": null |
| 74 // }, |
| 75 // ... |
| 76 // ] |
| 77 // } |
| 78 // } |
| 79 // |
| 80 // Because the promo signal data is piggybacked onto the tip server, the |
| 81 // values don't exactly correspond with the field names: |
| 82 // |
| 83 // For "promo_start" or "promo_end", the date to start or stop showing the |
| 84 // promotional line is given by the "inproduct" line. |
| 85 // For "promo_start", the promotional line itself is given in the "tooltip" |
| 86 // field. The "question" field gives the type of builds that should be shown |
| 87 // this promo (see the BuildType enum in web_resource_service.cc) and the |
| 88 // number of hours that each promo group should see it, separated by ":". |
| 89 // For example, "7:24" would indicate that all builds should see the promo, |
| 90 // and each group should see it for 24 hours. |
| 91 // |
| 92 // Public for unit testing. |
| 93 void UnpackPromoSignal(const DictionaryValue& parsed_json); |
| 94 |
| 95 // Unpack the promo resource as a custom logo signal. Expects a start and end |
| 96 // signal. Delivery will be in json in the form of: |
| 97 // { |
| 98 // "topic": { |
| 99 // "answers": [ |
| 100 // { |
| 101 // "answer_id": "107366", |
| 102 // "name": "custom_logo_start", |
| 103 // "question": "", |
| 104 // "tooltip": "", |
| 105 // "inproduct": "10/8/09 12:00", |
| 106 // "inproduct_target": null |
| 107 // }, |
| 108 // { |
| 109 // "answer_id": "107366", |
| 110 // "name": "custom_logo_end", |
| 111 // "question": "", |
| 112 // "tooltip": "", |
| 113 // "inproduct": "10/8/09 12:00", |
| 114 // "inproduct_target": null |
| 115 // }, |
| 116 // ... |
| 117 // ] |
| 118 // } |
| 119 // } |
| 120 // |
| 121 // Public for unit testing. |
| 122 void UnpackLogoSignal(const DictionaryValue& parsed_json); |
| 123 |
| 124 static const char* kCurrentTipPrefName; |
| 125 static const char* kTipCachePrefName; |
| 126 |
| 127 // Default server of dynamically loaded NTP HTML elements (promotions, tips): |
| 128 static const char* kDefaultPromoResourceServer; |
| 129 |
| 130 private: |
| 131 virtual ~PromoResourceService(); |
| 132 |
| 133 virtual void Unpack(const DictionaryValue& parsed_json); |
| 134 |
| 135 void Init(); |
| 136 |
| 137 // Schedule a notification that a web resource is either going to become |
| 138 // available or be no longer valid. |
| 139 void ScheduleNotification(double ms_start_time, double ms_end_time); |
| 140 |
| 141 // Gets mutable dictionary attached to user's preferences, so that we |
| 142 // can write resource data back to user's pref file. |
| 143 DictionaryValue* web_resource_cache_; |
| 144 |
| 145 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); |
| 146 }; |
| 147 |
| 148 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
| 149 |
OLD | NEW |