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/thread.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
19 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
21 #include "rlz/lib/rlz_lib.h" | 21 #include "rlz/lib/rlz_lib.h" |
22 | 22 |
| 23 class Profile; |
23 namespace net { | 24 namespace net { |
24 class URLRequestContextGetter; | 25 class URLRequestContextGetter; |
25 } | 26 } |
26 | 27 |
27 // RLZ is a library which is used to measure distribution scenarios. | 28 // 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 | 29 // 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 | 30 // 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 | 31 // 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 | 32 // 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. | 33 // RLZ library which can be found at http://code.google.com/p/rlz. |
33 // | 34 // |
34 // For partner or bundled installs, the RLZ might send more information | 35 // For partner or bundled installs, the RLZ might send more information |
35 // according to the terms disclosed in the EULA. | 36 // according to the terms disclosed in the EULA. |
36 | 37 |
37 class RLZTracker : public content::NotificationObserver { | 38 class RLZTracker : public content::NotificationObserver { |
38 public: | 39 public: |
39 // Initializes the RLZ library services for use in chrome. Schedules a | 40 // Initializes the RLZ library services for use in chrome. Schedules a |
40 // delayed task (delayed by |delay| seconds) that performs the ping and | 41 // delayed task (delayed by |delay| seconds) that performs the ping and |
41 // registers some events when 'first-run' is true. | 42 // registers some events when 'first-run' is true. |
42 // | 43 // |
43 // If the chrome brand is organic (no partners) then the pings don't occur. | 44 // If the chrome brand is organic (no partners) then the pings don't occur. |
44 static bool InitRlzDelayed(bool first_run, | 45 static bool InitRlzFromProfileDelayed(Profile* profile, |
45 int delay, | 46 bool first_run, |
46 bool is_google_default_search, | 47 int delay); |
47 bool is_google_homepage, | |
48 bool is_google_in_startpages); | |
49 | 48 |
50 // Records an RLZ event. Some events can be access point independent. | 49 // Records an RLZ event. Some events can be access point independent. |
51 // Returns false it the event could not be recorded. Requires write access | 50 // Returns false it the event could not be recorded. Requires write access |
52 // to the HKCU registry hive on windows. | 51 // to the HKCU registry hive on windows. |
53 static bool RecordProductEvent(rlz_lib::Product product, | 52 static bool RecordProductEvent(rlz_lib::Product product, |
54 rlz_lib::AccessPoint point, | 53 rlz_lib::AccessPoint point, |
55 rlz_lib::Event event_id); | 54 rlz_lib::Event event_id); |
56 | 55 |
57 // For the point parameter of RecordProductEvent. | 56 // For the point parameter of RecordProductEvent. |
58 static const rlz_lib::AccessPoint CHROME_OMNIBOX; | 57 static const rlz_lib::AccessPoint CHROME_OMNIBOX; |
(...skipping 16 matching lines...) Expand all Loading... |
75 | 74 |
76 // This method is public for use by the Singleton class. | 75 // This method is public for use by the Singleton class. |
77 static RLZTracker* GetInstance(); | 76 static RLZTracker* GetInstance(); |
78 | 77 |
79 // The following methods are made protected so that they can be used for | 78 // The following methods are made protected so that they can be used for |
80 // testing purposes. Production code should never need to call these. | 79 // testing purposes. Production code should never need to call these. |
81 protected: | 80 protected: |
82 RLZTracker(); | 81 RLZTracker(); |
83 virtual ~RLZTracker(); | 82 virtual ~RLZTracker(); |
84 | 83 |
| 84 // Called by InitRlzFromProfileDelayed with values taken from |profile|. |
| 85 static bool InitRlzDelayed(bool first_run, |
| 86 int delay, |
| 87 bool is_google_default_search, |
| 88 bool is_google_homepage, |
| 89 bool is_google_in_startpages); |
| 90 |
85 // Performs initialization of RLZ tracker that is purposefully delayed so | 91 // Performs initialization of RLZ tracker that is purposefully delayed so |
86 // that it does not interfere with chrome startup time. | 92 // that it does not interfere with chrome startup time. |
87 virtual void DelayedInit(); | 93 virtual void DelayedInit(); |
88 | 94 |
89 // content::NotificationObserver implementation: | 95 // content::NotificationObserver implementation: |
90 virtual void Observe(int type, | 96 virtual void Observe(int type, |
91 const content::NotificationSource& source, | 97 const content::NotificationSource& source, |
92 const content::NotificationDetails& details) OVERRIDE; | 98 const content::NotificationDetails& details) OVERRIDE; |
93 | 99 |
94 // Used by test code to override the default RLZTracker instance returned | 100 // Used by test code to override the default RLZTracker instance returned |
(...skipping 11 matching lines...) Expand all Loading... |
106 friend struct DefaultSingletonTraits<RLZTracker>; | 112 friend struct DefaultSingletonTraits<RLZTracker>; |
107 friend class base::RefCountedThreadSafe<RLZTracker>; | 113 friend class base::RefCountedThreadSafe<RLZTracker>; |
108 | 114 |
109 // Implementation called from InitRlzDelayed() static method. | 115 // Implementation called from InitRlzDelayed() static method. |
110 bool Init(bool first_run, | 116 bool Init(bool first_run, |
111 int delay, | 117 int delay, |
112 bool google_default_search, | 118 bool google_default_search, |
113 bool google_default_homepage, | 119 bool google_default_homepage, |
114 bool is_google_in_startpages); | 120 bool is_google_in_startpages); |
115 | 121 |
116 // Initializes task runners for tasks that access RlzValueStore and perform | |
117 // disk I/O. | |
118 virtual bool InitWorkers(); | |
119 | |
120 // Implementation called from RecordProductEvent() static method. | 122 // Implementation called from RecordProductEvent() static method. |
121 bool RecordProductEventImpl(rlz_lib::Product product, | 123 bool RecordProductEventImpl(rlz_lib::Product product, |
122 rlz_lib::AccessPoint point, | 124 rlz_lib::AccessPoint point, |
123 rlz_lib::Event event_id); | 125 rlz_lib::Event event_id); |
124 | 126 |
125 // Records FIRST_SEARCH event. Called from Observe() on blocking task runner. | 127 // Records FIRST_SEARCH event. Called from Observe() on blocking task runner. |
126 void RecordFirstSearch(rlz_lib::AccessPoint point); | 128 void RecordFirstSearch(rlz_lib::AccessPoint point); |
127 | 129 |
128 // Implementation called from GetAccessPointRlz() static method. | 130 // Implementation called from GetAccessPointRlz() static method. |
129 bool GetAccessPointRlzImpl(rlz_lib::AccessPoint point, string16* rlz); | 131 bool GetAccessPointRlzImpl(rlz_lib::AccessPoint point, string16* rlz); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // will be returned from GetInstance() instead of the regular singleton. | 164 // will be returned from GetInstance() instead of the regular singleton. |
163 static RLZTracker* tracker_; | 165 static RLZTracker* tracker_; |
164 | 166 |
165 // Configuation data for RLZ tracker. Set by call to Init(). | 167 // Configuation data for RLZ tracker. Set by call to Init(). |
166 bool first_run_; | 168 bool first_run_; |
167 bool send_ping_immediately_; | 169 bool send_ping_immediately_; |
168 bool is_google_default_search_; | 170 bool is_google_default_search_; |
169 bool is_google_homepage_; | 171 bool is_google_homepage_; |
170 bool is_google_in_startpages_; | 172 bool is_google_in_startpages_; |
171 | 173 |
172 // Dedicated RLZ thread for accessing RlzValueStore and doing I/O. | 174 // Unique sequence token so that tasks posted by RLZTracker are executed |
173 base::Thread rlz_thread_; | 175 // sequentially in the blocking pool. |
174 | 176 base::SequencedWorkerPool::SequenceToken worker_pool_token_; |
175 // Sequenced task runner used to post blocking tasks that access | |
176 // RlzValueStore. | |
177 base::SequencedTaskRunner* blocking_task_runner_; | |
178 | 177 |
179 // URLRequestContextGetter used by RLZ library. | 178 // URLRequestContextGetter used by RLZ library. |
180 net::URLRequestContextGetter* url_request_context_; | 179 net::URLRequestContextGetter* url_request_context_; |
181 | 180 |
182 // Keeps track if the RLZ tracker has already performed its delayed | 181 // Keeps track if the RLZ tracker has already performed its delayed |
183 // initialization. | 182 // initialization. |
184 bool already_ran_; | 183 bool already_ran_; |
185 | 184 |
186 // Keeps a cache of RLZ access point strings, since they rarely change. | 185 // Keeps a cache of RLZ access point strings, since they rarely change. |
187 // The cache must be protected by a lock since it may be accessed from | 186 // The cache must be protected by a lock since it may be accessed from |
188 // the UI thread for reading and the IO thread for reading and/or writing. | 187 // the UI thread for reading and the IO thread for reading and/or writing. |
189 base::Lock cache_lock_; | 188 base::Lock cache_lock_; |
190 std::map<rlz_lib::AccessPoint, string16> rlz_cache_; | 189 std::map<rlz_lib::AccessPoint, string16> rlz_cache_; |
191 | 190 |
192 // Keeps track of whether the omnibox or host page have been used. | 191 // Keeps track of whether the omnibox or host page have been used. |
193 bool omnibox_used_; | 192 bool omnibox_used_; |
194 bool homepage_used_; | 193 bool homepage_used_; |
195 | 194 |
| 195 // Main and (optionally) reactivation brand codes, assigned on UI thread. |
| 196 std::string brand_; |
| 197 std::string reactivation_brand_; |
| 198 |
196 content::NotificationRegistrar registrar_; | 199 content::NotificationRegistrar registrar_; |
197 | 200 |
198 DISALLOW_COPY_AND_ASSIGN(RLZTracker); | 201 DISALLOW_COPY_AND_ASSIGN(RLZTracker); |
199 }; | 202 }; |
200 | 203 |
201 #endif // defined(ENABLE_RLZ) | 204 #endif // defined(ENABLE_RLZ) |
202 | 205 |
203 #endif // CHROME_BROWSER_RLZ_RLZ_H_ | 206 #endif // CHROME_BROWSER_RLZ_RLZ_H_ |
OLD | NEW |