Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(854)

Side by Side Diff: chrome/browser/web_resource/web_resource_service.h

Issue 4804001: Add new promotional line for NTP.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_WEB_RESOURCE_SERVICE_H_ 5 #ifndef CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_
6 #define CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ 6 #define CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/utility_process_host.h" 13 #include "chrome/browser/utility_process_host.h"
14 #include "chrome/common/web_resource/web_resource_unpacker.h" 14 #include "chrome/common/web_resource/web_resource_unpacker.h"
15 15
16 class Profile; 16 class Profile;
17 17
18 namespace WebResourceServiceUtil {
19
20 // Certain promotions should only be shown to certain classes of users. This
21 // function will change to reflect each kind of promotion.
22 bool CanShowPromo(Profile* profile);
23
24 } // namespace WebResourceService
25
18 class WebResourceService 26 class WebResourceService
19 : public UtilityProcessHost::Client { 27 : public UtilityProcessHost::Client {
20 public: 28 public:
21 explicit WebResourceService(Profile* profile); 29 explicit WebResourceService(Profile* profile);
22 30
23 // Sleep until cache needs to be updated, but always for at least 5 seconds 31 // Sleep until cache needs to be updated, but always for at least 5 seconds
24 // so we don't interfere with startup. Then begin updating resources. 32 // so we don't interfere with startup. Then begin updating resources.
25 void StartAfterDelay(); 33 void StartAfterDelay();
26 34
27 // We have successfully pulled data from a resource server; now launch 35 // We have successfully pulled data from a resource server; now launch
(...skipping 13 matching lines...) Expand all
41 // "inproduct": "Text here will be shown as a tip", 49 // "inproduct": "Text here will be shown as a tip",
42 // }, 50 // },
43 // ... 51 // ...
44 // ] 52 // ]
45 // } 53 // }
46 // } 54 // }
47 // 55 //
48 // Public for unit testing. 56 // Public for unit testing.
49 void UnpackTips(const DictionaryValue& parsed_json); 57 void UnpackTips(const DictionaryValue& parsed_json);
50 58
51 // Unpack the web resource as a custom logo signal. Expects json in the form 59 // Unpack the web resource as a custom promo signal. Expects a start and end
52 // of: 60 // signal, with the promo to be shown in the tooltip of the start signal
61 // field. Delivery will be in json in the form of:
53 // { 62 // {
54 // "topic": { 63 // "topic": {
55 // "answers": [ 64 // "answers": [
56 // { 65 // {
57 // "custom_logo_start": "31/12/10 01:00", 66 // "answer_id": "1067976",
58 // "custom_logo_end": "31/01/11 01:00" 67 // "name": "promo_start",
68 // "question": "",
69 // "tooltip":
70 // "Click \u003ca href=http://www.google.com\u003ehere\u003c/a\u003e!",
71 // "inproduct": "10/8/09 12:00",
72 // "inproduct_target": null
73 // },
74 // {
75 // "answer_id": "1067976",
76 // "name": "promo_end",
77 // "question": "",
78 // "tooltip": "",
79 // "inproduct": "10/8/11 12:00",
80 // "inproduct_target": null
81 // },
82 // ...
83 // ]
84 // }
85 // }
86 //
87 // Public for unit testing.
88 void UnpackPromoSignal(const DictionaryValue& parsed_json);
89
90 // Unpack the web resource as a custom logo signal. Expects a start and end
91 // signal. Delivery will be in json in the form of:
92 // {
93 // "topic": {
94 // "answers": [
95 // {
96 // "answer_id": "107366",
97 // "name": "custom_logo_start",
98 // "question": "",
99 // "tooltip": "",
100 // "inproduct": "10/8/09 12:00",
101 // "inproduct_target": null
102 // },
103 // {
104 // "answer_id": "107366",
105 // "name": "custom_logo_end",
106 // "question": "",
107 // "tooltip": "",
108 // "inproduct": "10/8/09 12:00",
109 // "inproduct_target": null
59 // }, 110 // },
60 // ... 111 // ...
61 // ] 112 // ]
62 // } 113 // }
63 // } 114 // }
64 // 115 //
65 // Public for unit testing. 116 // Public for unit testing.
66 void UnpackLogoSignal(const DictionaryValue& parsed_json); 117 void UnpackLogoSignal(const DictionaryValue& parsed_json);
67 118
119 int cache_update_delay() const { return cache_update_delay_; }
120
68 static const char* kCurrentTipPrefName; 121 static const char* kCurrentTipPrefName;
69 static const char* kTipCachePrefName; 122 static const char* kTipCachePrefName;
70 123
71 // Default server from which to gather resources. 124 // Default server of dynamically loaded NTP HTML elements (promotions, tips):
72 static const char* kDefaultResourceServer; 125 static const char* kDefaultWebResourceServer;
73 126
74 private: 127 private:
75 class WebResourceFetcher; 128 class WebResourceFetcher;
76 friend class WebResourceFetcher; 129 friend class WebResourceFetcher;
77 130
78 class UnpackerClient; 131 class UnpackerClient;
79 132
80 ~WebResourceService(); 133 ~WebResourceService();
81 134
82 void Init(); 135 void Init();
83 136
84 // Set in_fetch_ to false, clean up temp directories (in the future). 137 // Set in_fetch_ to false, clean up temp directories (in the future).
85 void EndFetch(); 138 void EndFetch();
86 139
87 // Puts parsed json data in the right places, and writes to prefs file. 140 // Puts parsed json data in the right places, and writes to prefs file.
88 void OnWebResourceUnpacked(const DictionaryValue& parsed_json); 141 void OnWebResourceUnpacked(const DictionaryValue& parsed_json);
89 142
90 // We need to be able to load parsed resource data into preferences file, 143 // We need to be able to load parsed resource data into preferences file,
91 // and get proper install directory. 144 // and get proper install directory.
92 PrefService* prefs_; 145 PrefService* prefs_;
93 146
147 // Display and fetch of promo lines depends on data associated with a user's
148 // profile.
149 Profile* profile_;
150
94 // Server from which we are currently pulling web resource data. 151 // Server from which we are currently pulling web resource data.
95 std::string web_resource_server_; 152 std::string web_resource_server_;
96 153
97 scoped_ptr<WebResourceFetcher> web_resource_fetcher_; 154 scoped_ptr<WebResourceFetcher> web_resource_fetcher_;
98 155
99 ResourceDispatcherHost* resource_dispatcher_host_; 156 ResourceDispatcherHost* resource_dispatcher_host_;
100 157
101 // Gets mutable dictionary attached to user's preferences, so that we 158 // Gets mutable dictionary attached to user's preferences, so that we
102 // can write resource data back to user's pref file. 159 // can write resource data back to user's pref file.
103 DictionaryValue* web_resource_cache_; 160 DictionaryValue* web_resource_cache_;
104 161
105 // True if we are currently mid-fetch. If we are asked to start a fetch 162 // True if we are currently mid-fetch. If we are asked to start a fetch
106 // when we are still fetching resource data, schedule another one in 163 // when we are still fetching resource data, schedule another one in
107 // kCacheUpdateDelay time, and silently exit. 164 // kCacheUpdateDelay time, and silently exit.
108 bool in_fetch_; 165 bool in_fetch_;
109 166
110 // Delay on first fetch so we don't interfere with startup. 167 // Delay between calls to update the web resource cache. This delay may be
111 static const int kStartResourceFetchDelay = 5000; 168 // different for different builds of Chrome.
112 169 int cache_update_delay_;
113 // Delay between calls to update the cache (48 hours).
114 static const int kCacheUpdateDelay = 48 * 60 * 60 * 1000;
115 170
116 DISALLOW_COPY_AND_ASSIGN(WebResourceService); 171 DISALLOW_COPY_AND_ASSIGN(WebResourceService);
117 }; 172 };
118 173
119 #endif // CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ 174 #endif // CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/resources/new_new_tab.js ('k') | chrome/browser/web_resource/web_resource_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698