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 CHROME_BROWSER_RLZ_RLZ_H_ |
6 #define CHROME_BROWSER_RLZ_RLZ_H_ | 6 #define CHROME_BROWSER_RLZ_RLZ_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/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/string16.h" | 17 #include "base/string16.h" |
18 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
| 19 #include "base/time.h" |
19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
21 #include "rlz/lib/rlz_lib.h" | 22 #include "rlz/lib/rlz_lib.h" |
22 | 23 |
23 class Profile; | 24 class Profile; |
24 namespace net { | 25 namespace net { |
25 class URLRequestContextGetter; | 26 class URLRequestContextGetter; |
26 } | 27 } |
27 | 28 |
28 // RLZ is a library which is used to measure distribution scenarios. | 29 // RLZ is a library which is used to measure distribution scenarios. |
29 // 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 |
30 // 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 |
31 // 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 |
32 // 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 |
33 // 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. |
34 // | 35 // |
35 // For partner or bundled installs, the RLZ might send more information | 36 // For partner or bundled installs, the RLZ might send more information |
36 // according to the terms disclosed in the EULA. | 37 // according to the terms disclosed in the EULA. |
37 | 38 |
38 class RLZTracker : public content::NotificationObserver { | 39 class RLZTracker : public content::NotificationObserver { |
39 public: | 40 public: |
40 // Initializes the RLZ library services for use in chrome. Schedules a | 41 // Initializes the RLZ library services for use in chrome. Schedules a delayed |
41 // delayed task (delayed by |delay| seconds) that performs the ping and | 42 // task that performs the ping and registers some events when 'first-run' is |
42 // registers some events when 'first-run' is true. | 43 // true. |
| 44 // |
| 45 // When |send_ping_immediately| is true, a financial ping should be sent |
| 46 // immediately after a first search is recorded, without waiting for |delay|. |
| 47 // However, we only want this behaviour on first run. |
43 // | 48 // |
44 // 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. |
45 static bool InitRlzFromProfileDelayed(Profile* profile, | 50 static bool InitRlzFromProfileDelayed(Profile* profile, |
46 bool first_run, | 51 bool first_run, |
47 int delay); | 52 bool send_ping_immediately, |
| 53 base::TimeDelta delay); |
48 | 54 |
49 // Records an RLZ event. Some events can be access point independent. | 55 // Records an RLZ event. Some events can be access point independent. |
50 // 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 |
51 // to the HKCU registry hive on windows. | 57 // to the HKCU registry hive on windows. |
52 static bool RecordProductEvent(rlz_lib::Product product, | 58 static bool RecordProductEvent(rlz_lib::Product product, |
53 rlz_lib::AccessPoint point, | 59 rlz_lib::AccessPoint point, |
54 rlz_lib::Event event_id); | 60 rlz_lib::Event event_id); |
55 | 61 |
56 // For the point parameter of RecordProductEvent. | 62 // For the point parameter of RecordProductEvent. |
57 static const rlz_lib::AccessPoint CHROME_OMNIBOX; | 63 static const rlz_lib::AccessPoint CHROME_OMNIBOX; |
(...skipping 27 matching lines...) Expand all Loading... |
85 static void EnableZeroDelayForTesting(); | 91 static void EnableZeroDelayForTesting(); |
86 | 92 |
87 // The following methods are made protected so that they can be used for | 93 // The following methods are made protected so that they can be used for |
88 // testing purposes. Production code should never need to call these. | 94 // testing purposes. Production code should never need to call these. |
89 protected: | 95 protected: |
90 RLZTracker(); | 96 RLZTracker(); |
91 virtual ~RLZTracker(); | 97 virtual ~RLZTracker(); |
92 | 98 |
93 // Called by InitRlzFromProfileDelayed with values taken from |profile|. | 99 // Called by InitRlzFromProfileDelayed with values taken from |profile|. |
94 static bool InitRlzDelayed(bool first_run, | 100 static bool InitRlzDelayed(bool first_run, |
95 int delay, | 101 bool send_ping_immediately, |
| 102 base::TimeDelta delay, |
96 bool is_google_default_search, | 103 bool is_google_default_search, |
97 bool is_google_homepage, | 104 bool is_google_homepage, |
98 bool is_google_in_startpages); | 105 bool is_google_in_startpages); |
99 | 106 |
100 // Performs initialization of RLZ tracker that is purposefully delayed so | 107 // Performs initialization of RLZ tracker that is purposefully delayed so |
101 // that it does not interfere with chrome startup time. | 108 // that it does not interfere with chrome startup time. |
102 virtual void DelayedInit(); | 109 virtual void DelayedInit(); |
103 | 110 |
104 // content::NotificationObserver implementation: | 111 // content::NotificationObserver implementation: |
105 virtual void Observe(int type, | 112 virtual void Observe(int type, |
(...skipping 10 matching lines...) Expand all Loading... |
116 // 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. |
117 // Protected so that its accessible from tests. | 124 // Protected so that its accessible from tests. |
118 void PingNowImpl(); | 125 void PingNowImpl(); |
119 | 126 |
120 private: | 127 private: |
121 friend struct DefaultSingletonTraits<RLZTracker>; | 128 friend struct DefaultSingletonTraits<RLZTracker>; |
122 friend class base::RefCountedThreadSafe<RLZTracker>; | 129 friend class base::RefCountedThreadSafe<RLZTracker>; |
123 | 130 |
124 // Implementation called from InitRlzDelayed() static method. | 131 // Implementation called from InitRlzDelayed() static method. |
125 bool Init(bool first_run, | 132 bool Init(bool first_run, |
126 int delay, | 133 bool send_ping_immediately, |
| 134 base::TimeDelta delay, |
127 bool google_default_search, | 135 bool google_default_search, |
128 bool google_default_homepage, | 136 bool google_default_homepage, |
129 bool is_google_in_startpages); | 137 bool is_google_in_startpages); |
130 | 138 |
131 // Implementation called from RecordProductEvent() static method. | 139 // Implementation called from RecordProductEvent() static method. |
132 bool RecordProductEventImpl(rlz_lib::Product product, | 140 bool RecordProductEventImpl(rlz_lib::Product product, |
133 rlz_lib::AccessPoint point, | 141 rlz_lib::AccessPoint point, |
134 rlz_lib::Event event_id); | 142 rlz_lib::Event event_id); |
135 | 143 |
136 // Records FIRST_SEARCH event. Called from Observe() on blocking task runner. | 144 // Records FIRST_SEARCH event. Called from Observe() on blocking task runner. |
137 void RecordFirstSearch(rlz_lib::AccessPoint point); | 145 void RecordFirstSearch(rlz_lib::AccessPoint point); |
138 | 146 |
139 // Implementation called from GetAccessPointRlz() static method. | 147 // Implementation called from GetAccessPointRlz() static method. |
140 bool GetAccessPointRlzImpl(rlz_lib::AccessPoint point, string16* rlz); | 148 bool GetAccessPointRlzImpl(rlz_lib::AccessPoint point, string16* rlz); |
141 | 149 |
142 // Schedules the delayed initialization. This method is virtual to allow | 150 // Schedules the delayed initialization. This method is virtual to allow |
143 // tests to override how the scheduling is done. | 151 // tests to override how the scheduling is done. |
144 virtual void ScheduleDelayedInit(int delay); | 152 virtual void ScheduleDelayedInit(base::TimeDelta delay); |
145 | 153 |
146 // Schedules a call to rlz_lib::RecordProductEvent(). This method is virtual | 154 // Schedules a call to rlz_lib::RecordProductEvent(). This method is virtual |
147 // to allow tests to override how the scheduling is done. | 155 // to allow tests to override how the scheduling is done. |
148 virtual bool ScheduleRecordProductEvent(rlz_lib::Product product, | 156 virtual bool ScheduleRecordProductEvent(rlz_lib::Product product, |
149 rlz_lib::AccessPoint point, | 157 rlz_lib::AccessPoint point, |
150 rlz_lib::Event event_id); | 158 rlz_lib::Event event_id); |
151 | 159 |
152 // Schedules a call to rlz_lib::RecordFirstSearch(). This method is virtual | 160 // Schedules a call to rlz_lib::RecordFirstSearch(). This method is virtual |
153 // to allow tests to override how the scheduling is done. | 161 // to allow tests to override how the scheduling is done. |
154 virtual bool ScheduleRecordFirstSearch(rlz_lib::AccessPoint point); | 162 virtual bool ScheduleRecordFirstSearch(rlz_lib::AccessPoint point); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 bool omnibox_used_; | 218 bool omnibox_used_; |
211 bool homepage_used_; | 219 bool homepage_used_; |
212 | 220 |
213 // Main and (optionally) reactivation brand codes, assigned on UI thread. | 221 // Main and (optionally) reactivation brand codes, assigned on UI thread. |
214 std::string brand_; | 222 std::string brand_; |
215 std::string reactivation_brand_; | 223 std::string reactivation_brand_; |
216 | 224 |
217 content::NotificationRegistrar registrar_; | 225 content::NotificationRegistrar registrar_; |
218 | 226 |
219 // Minimum delay before sending financial ping after initialization. | 227 // Minimum delay before sending financial ping after initialization. |
220 int min_delay_; | 228 base::TimeDelta min_init_delay_; |
221 | 229 |
222 DISALLOW_COPY_AND_ASSIGN(RLZTracker); | 230 DISALLOW_COPY_AND_ASSIGN(RLZTracker); |
223 }; | 231 }; |
224 | 232 |
225 #endif // defined(ENABLE_RLZ) | 233 #endif // defined(ENABLE_RLZ) |
226 | 234 |
227 #endif // CHROME_BROWSER_RLZ_RLZ_H_ | 235 #endif // CHROME_BROWSER_RLZ_RLZ_H_ |
OLD | NEW |