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