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 "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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // 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. |
180 // 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 |
181 // 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. |
182 base::Lock cache_lock_; | 188 base::Lock cache_lock_; |
183 std::map<rlz_lib::AccessPoint, string16> rlz_cache_; | 189 std::map<rlz_lib::AccessPoint, string16> rlz_cache_; |
184 | 190 |
185 // 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. |
186 bool omnibox_used_; | 192 bool omnibox_used_; |
187 bool homepage_used_; | 193 bool homepage_used_; |
188 | 194 |
| 195 // Main and (optionally) reactivation brand codes, assigned on UI thread. |
| 196 std::string brand_; |
| 197 std::string reactivation_brand_; |
| 198 |
189 content::NotificationRegistrar registrar_; | 199 content::NotificationRegistrar registrar_; |
190 | 200 |
191 DISALLOW_COPY_AND_ASSIGN(RLZTracker); | 201 DISALLOW_COPY_AND_ASSIGN(RLZTracker); |
192 }; | 202 }; |
193 | 203 |
194 #endif // defined(ENABLE_RLZ) | 204 #endif // defined(ENABLE_RLZ) |
195 | 205 |
196 #endif // CHROME_BROWSER_RLZ_RLZ_H_ | 206 #endif // CHROME_BROWSER_RLZ_RLZ_H_ |
OLD | NEW |