OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_RLZ_RLZ_H_ | 5 #ifndef COMPONENTS_RLZ_RLZ_TRACKER_H_ |
6 #define CHROME_BROWSER_RLZ_RLZ_H_ | 6 #define COMPONENTS_RLZ_RLZ_TRACKER_H_ |
7 | |
8 #include "build/build_config.h" | |
9 | |
10 #if defined(ENABLE_RLZ) | |
11 | 7 |
12 #include <map> | 8 #include <map> |
13 #include <string> | 9 #include <string> |
14 | 10 |
15 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
17 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
18 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
19 #include "base/time/time.h" | 16 #include "base/time/time.h" |
20 #include "content/public/browser/notification_observer.h" | |
21 #include "content/public/browser/notification_registrar.h" | |
22 #include "rlz/lib/rlz_lib.h" | 17 #include "rlz/lib/rlz_lib.h" |
23 | 18 |
24 class Profile; | |
25 namespace net { | 19 namespace net { |
26 class URLRequestContextGetter; | 20 class URLRequestContextGetter; |
27 } | 21 } |
28 | 22 |
| 23 namespace rlz { |
| 24 |
| 25 class RLZTrackerDelegate; |
| 26 |
29 // RLZ is a library which is used to measure distribution scenarios. | 27 // RLZ is a library which is used to measure distribution scenarios. |
30 // Its job is to record certain lifetime events in the registry and to send | 28 // Its job is to record certain lifetime events in the registry and to send |
31 // them encoded as a compact string at most twice. The sent data does | 29 // them encoded as a compact string at most twice. The sent data does |
32 // not contain information that can be used to identify a user or to infer | 30 // not contain information that can be used to identify a user or to infer |
33 // browsing habits. The API in this file is a wrapper around the open source | 31 // browsing habits. The API in this file is a wrapper around the open source |
34 // RLZ library which can be found at http://code.google.com/p/rlz. | 32 // RLZ library which can be found at http://code.google.com/p/rlz. |
35 // | 33 // |
36 // For partner or bundled installs, the RLZ might send more information | 34 // For partner or bundled installs, the RLZ might send more information |
37 // according to the terms disclosed in the EULA. | 35 // according to the terms disclosed in the EULA. |
38 | 36 |
39 class RLZTracker : public content::NotificationObserver { | 37 class RLZTracker { |
40 public: | 38 public: |
| 39 // Sets the RLZTrackerDelegate that should be used by the global RLZTracker |
| 40 // instance. Must be called before calling any other method of RLZTracker. |
| 41 static void SetRlzDelegate(scoped_ptr<RLZTrackerDelegate> delegate); |
| 42 |
41 // Initializes the RLZ library services for use in chrome. Schedules a delayed | 43 // Initializes the RLZ library services for use in chrome. Schedules a delayed |
42 // task that performs the ping and registers some events when 'first-run' is | 44 // task that performs the ping and registers some events when 'first-run' is |
43 // true. | 45 // true. |
44 // | 46 // |
45 // When |send_ping_immediately| is true, a financial ping should be sent | 47 // When |send_ping_immediately| is true, a financial ping should be sent |
46 // immediately after a first search is recorded, without waiting for |delay|. | 48 // immediately after a first search is recorded, without waiting for |delay|. |
47 // However, we only want this behaviour on first run. | 49 // However, we only want this behaviour on first run. |
48 // | 50 // |
49 // If the chrome brand is organic (no partners) then the pings don't occur. | 51 // If the chrome brand is organic (no partners) then the pings don't occur. |
50 static bool InitRlzFromProfileDelayed(Profile* profile, | 52 static bool InitRlzDelayed(bool first_run, |
51 bool first_run, | 53 bool send_ping_immediately, |
52 bool send_ping_immediately, | 54 base::TimeDelta delay, |
53 base::TimeDelta delay); | 55 bool is_google_default_search, |
| 56 bool is_google_homepage, |
| 57 bool is_google_in_startpages); |
54 | 58 |
55 // Records an RLZ event. Some events can be access point independent. | 59 // Records an RLZ event. Some events can be access point independent. |
56 // Returns false it the event could not be recorded. Requires write access | 60 // Returns false it the event could not be recorded. Requires write access |
57 // to the HKCU registry hive on windows. | 61 // to the HKCU registry hive on windows. |
58 static bool RecordProductEvent(rlz_lib::Product product, | 62 static bool RecordProductEvent(rlz_lib::Product product, |
59 rlz_lib::AccessPoint point, | 63 rlz_lib::AccessPoint point, |
60 rlz_lib::Event event_id); | 64 rlz_lib::Event event_id); |
61 | 65 |
62 // For the point parameter of RecordProductEvent. | 66 // For the point parameter of RecordProductEvent. |
63 static rlz_lib::AccessPoint ChromeOmnibox(); | 67 static rlz_lib::AccessPoint ChromeOmnibox(); |
(...skipping 20 matching lines...) Expand all Loading... |
84 | 88 |
85 #if defined(OS_CHROMEOS) | 89 #if defined(OS_CHROMEOS) |
86 // Clears all product state. Should be called when turning RLZ off. On other | 90 // Clears all product state. Should be called when turning RLZ off. On other |
87 // platforms, this is done by product uninstaller. | 91 // platforms, this is done by product uninstaller. |
88 static void ClearRlzState(); | 92 static void ClearRlzState(); |
89 #endif | 93 #endif |
90 | 94 |
91 // This method is public for use by the Singleton class. | 95 // This method is public for use by the Singleton class. |
92 static RLZTracker* GetInstance(); | 96 static RLZTracker* GetInstance(); |
93 | 97 |
94 // Enables zero delay for InitRlzFromProfileDelayed. For testing only. | 98 // Enables zero delay for InitRlzDelayed. For testing only. |
95 static void EnableZeroDelayForTesting(); | 99 static void EnableZeroDelayForTesting(); |
96 | 100 |
97 #if !defined(OS_IOS) | 101 #if !defined(OS_IOS) |
98 // Records that the app list search has been used. | 102 // Records that the app list search has been used. |
99 static void RecordAppListSearch(); | 103 static void RecordAppListSearch(); |
100 #endif | 104 #endif |
101 | 105 |
102 // The following methods are made protected so that they can be used for | 106 // The following methods are made protected so that they can be used for |
103 // testing purposes. Production code should never need to call these. | 107 // testing purposes. Production code should never need to call these. |
104 protected: | 108 protected: |
105 RLZTracker(); | 109 RLZTracker(); |
106 ~RLZTracker() override; | 110 virtual ~RLZTracker(); |
107 | |
108 // Called by InitRlzFromProfileDelayed with values taken from |profile|. | |
109 static bool InitRlzDelayed(bool first_run, | |
110 bool send_ping_immediately, | |
111 base::TimeDelta delay, | |
112 bool is_google_default_search, | |
113 bool is_google_homepage, | |
114 bool is_google_in_startpages); | |
115 | 111 |
116 // Performs initialization of RLZ tracker that is purposefully delayed so | 112 // Performs initialization of RLZ tracker that is purposefully delayed so |
117 // that it does not interfere with chrome startup time. | 113 // that it does not interfere with chrome startup time. |
118 virtual void DelayedInit(); | 114 virtual void DelayedInit(); |
119 | 115 |
120 // content::NotificationObserver implementation: | |
121 void Observe(int type, | |
122 const content::NotificationSource& source, | |
123 const content::NotificationDetails& details) override; | |
124 | |
125 // Used by test code to override the default RLZTracker instance returned | 116 // Used by test code to override the default RLZTracker instance returned |
126 // by GetInstance(). | 117 // by GetInstance(). |
127 void set_tracker(RLZTracker* tracker) { | 118 void set_tracker(RLZTracker* tracker) { tracker_ = tracker; } |
128 tracker_ = tracker; | |
129 } | |
130 | 119 |
131 // Sends the financial ping to the RLZ servers and invalidates the RLZ string | 120 // Sends the financial ping to the RLZ servers and invalidates the RLZ string |
132 // cache since the response from the RLZ server may have changed then. | 121 // cache since the response from the RLZ server may have changed then. |
133 // Protected so that its accessible from tests. | 122 // Protected so that its accessible from tests. |
134 void PingNowImpl(); | 123 void PingNowImpl(); |
135 | 124 |
136 private: | 125 private: |
137 friend struct DefaultSingletonTraits<RLZTracker>; | 126 friend struct DefaultSingletonTraits<RLZTracker>; |
138 friend class base::RefCountedThreadSafe<RLZTracker>; | 127 friend class base::RefCountedThreadSafe<RLZTracker>; |
139 | 128 |
| 129 // Implementation called from SetRlzDelegate() static method. |
| 130 void SetDelegate(scoped_ptr<RLZTrackerDelegate> delegate); |
| 131 |
140 // Implementation called from InitRlzDelayed() static method. | 132 // Implementation called from InitRlzDelayed() static method. |
141 bool Init(bool first_run, | 133 bool Init(bool first_run, |
142 bool send_ping_immediately, | 134 bool send_ping_immediately, |
143 base::TimeDelta delay, | 135 base::TimeDelta delay, |
144 bool google_default_search, | 136 bool is_google_default_search, |
145 bool google_default_homepage, | 137 bool is_google_homepage, |
146 bool is_google_in_startpages); | 138 bool is_google_in_startpages); |
147 | 139 |
| 140 // Implementation called from CleanupRlz static method. |
| 141 void Cleanup(); |
| 142 |
148 // Implementation called from RecordProductEvent() static method. | 143 // Implementation called from RecordProductEvent() static method. |
149 bool RecordProductEventImpl(rlz_lib::Product product, | 144 bool RecordProductEventImpl(rlz_lib::Product product, |
150 rlz_lib::AccessPoint point, | 145 rlz_lib::AccessPoint point, |
151 rlz_lib::Event event_id); | 146 rlz_lib::Event event_id); |
152 | 147 |
153 // Records FIRST_SEARCH event. Called from Observe() on blocking task runner. | 148 // Records FIRST_SEARCH event. Passed as bound callback to RLZTrackerDelegate. |
154 void RecordFirstSearch(rlz_lib::AccessPoint point); | 149 void RecordFirstSearch(rlz_lib::AccessPoint point); |
155 | 150 |
156 // Implementation called from GetAccessPointRlz() static method. | 151 // Implementation called from GetAccessPointRlz() static method. |
157 bool GetAccessPointRlzImpl(rlz_lib::AccessPoint point, base::string16* rlz); | 152 bool GetAccessPointRlzImpl(rlz_lib::AccessPoint point, base::string16* rlz); |
158 | 153 |
159 // Schedules the delayed initialization. This method is virtual to allow | 154 // Schedules the delayed initialization. This method is virtual to allow |
160 // tests to override how the scheduling is done. | 155 // tests to override how the scheduling is done. |
161 virtual void ScheduleDelayedInit(base::TimeDelta delay); | 156 virtual void ScheduleDelayedInit(base::TimeDelta delay); |
162 | 157 |
163 // Schedules a call to rlz_lib::RecordProductEvent(). This method is virtual | 158 // Schedules a call to rlz_lib::RecordProductEvent(). This method is virtual |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 #endif | 191 #endif |
197 | 192 |
198 // Returns a pointer to the bool corresponding to whether |point| has been | 193 // Returns a pointer to the bool corresponding to whether |point| has been |
199 // used but not reported. | 194 // used but not reported. |
200 bool* GetAccessPointRecord(rlz_lib::AccessPoint point); | 195 bool* GetAccessPointRecord(rlz_lib::AccessPoint point); |
201 | 196 |
202 // Tracker used for testing purposes only. If this value is non-NULL, it | 197 // Tracker used for testing purposes only. If this value is non-NULL, it |
203 // will be returned from GetInstance() instead of the regular singleton. | 198 // will be returned from GetInstance() instead of the regular singleton. |
204 static RLZTracker* tracker_; | 199 static RLZTracker* tracker_; |
205 | 200 |
| 201 // Delegate abstracting embedder specific knowledge. Must not be null. |
| 202 scoped_ptr<RLZTrackerDelegate> delegate_; |
| 203 |
206 // Configuation data for RLZ tracker. Set by call to Init(). | 204 // Configuation data for RLZ tracker. Set by call to Init(). |
207 bool first_run_; | 205 bool first_run_; |
208 bool send_ping_immediately_; | 206 bool send_ping_immediately_; |
209 bool is_google_default_search_; | 207 bool is_google_default_search_; |
210 bool is_google_homepage_; | 208 bool is_google_homepage_; |
211 bool is_google_in_startpages_; | 209 bool is_google_in_startpages_; |
212 | 210 |
213 // Unique sequence token so that tasks posted by RLZTracker are executed | 211 // Unique sequence token so that tasks posted by RLZTracker are executed |
214 // sequentially in the blocking pool. | 212 // sequentially in the blocking pool. |
215 base::SequencedWorkerPool::SequenceToken worker_pool_token_; | 213 base::SequencedWorkerPool::SequenceToken worker_pool_token_; |
(...skipping 10 matching lines...) Expand all Loading... |
226 | 224 |
227 // Keeps track of whether the omnibox, home page or app list have been used. | 225 // Keeps track of whether the omnibox, home page or app list have been used. |
228 bool omnibox_used_; | 226 bool omnibox_used_; |
229 bool homepage_used_; | 227 bool homepage_used_; |
230 bool app_list_used_; | 228 bool app_list_used_; |
231 | 229 |
232 // Main and (optionally) reactivation brand codes, assigned on UI thread. | 230 // Main and (optionally) reactivation brand codes, assigned on UI thread. |
233 std::string brand_; | 231 std::string brand_; |
234 std::string reactivation_brand_; | 232 std::string reactivation_brand_; |
235 | 233 |
236 content::NotificationRegistrar registrar_; | |
237 | |
238 // Minimum delay before sending financial ping after initialization. | 234 // Minimum delay before sending financial ping after initialization. |
239 base::TimeDelta min_init_delay_; | 235 base::TimeDelta min_init_delay_; |
240 | 236 |
241 DISALLOW_COPY_AND_ASSIGN(RLZTracker); | 237 DISALLOW_COPY_AND_ASSIGN(RLZTracker); |
242 }; | 238 }; |
243 | 239 |
244 #endif // defined(ENABLE_RLZ) | 240 } // namespace rlz |
245 | 241 |
246 #endif // CHROME_BROWSER_RLZ_RLZ_H_ | 242 #endif // COMPONENTS_RLZ_RLZ_TRACKER_H_ |
OLD | NEW |