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