OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
12 | 12 |
13 #include <map> | |
13 #include <string> | 14 #include <string> |
14 | 15 |
15 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/memory/ref_counted.h" | |
18 #include "base/memory/singleton.h" | |
19 #include "base/task.h" | |
20 #include "content/common/notification_observer.h" | |
21 #include "content/common/notification_registrar.h" | |
16 #include "rlz/win/lib/rlz_lib.h" | 22 #include "rlz/win/lib/rlz_lib.h" |
17 | 23 |
18 // RLZ is a library which is used to measure distribution scenarios. | 24 // RLZ is a library which is used to measure distribution scenarios. |
19 // Its job is to record certain lifetime events in the registry and to send | 25 // Its job is to record certain lifetime events in the registry and to send |
20 // them encoded as a compact string at most twice. The sent data does | 26 // them encoded as a compact string at most twice. The sent data does |
21 // not contain information that can be used to identify a user or to infer | 27 // not contain information that can be used to identify a user or to infer |
22 // browsing habits. The API in this file is a wrapper around the open source | 28 // browsing habits. The API in this file is a wrapper around the open source |
23 // RLZ library which can be found at http://code.google.com/p/rlz. | 29 // RLZ library which can be found at http://code.google.com/p/rlz. |
24 // | 30 // |
25 // For partner or bundled installs, the RLZ might send more information | 31 // For partner or bundled installs, the RLZ might send more information |
26 // according to the terms disclosed in the EULA. | 32 // according to the terms disclosed in the EULA. |
27 | 33 |
28 class RLZTracker { | 34 class RLZTracker : public NotificationObserver { |
29 | |
30 public: | 35 public: |
31 // Like InitRlz() this function initializes the RLZ library services for use | 36 // Initializes the RLZ library services for use in chrome. Schedules a |
32 // in chrome. Besides binding the dll, it schedules a delayed task (delayed | 37 // delayed task (delayed by |delay| seconds) that performs the ping and |
33 // by |delay| seconds) that performs the ping and registers some events | 38 // registers some events when 'first-run' is true. |
34 // when 'first-run' is true. | |
35 // | 39 // |
36 // If the chrome brand is organic (no partners) then the RLZ library is not | 40 // If the chrome brand is organic (no partners) then the pings don't occur. |
37 // loaded or initialized and the pings don't ocurr. | |
38 static bool InitRlzDelayed(bool first_run, int delay, | 41 static bool InitRlzDelayed(bool first_run, int delay, |
39 bool google_default_search); | 42 bool google_default_search, |
43 bool google_default_homepage); | |
40 | 44 |
41 // Records an RLZ event. Some events can be access point independent. | 45 // Records an RLZ event. Some events can be access point independent. |
42 // Returns false it the event could not be recorded. Requires write access | 46 // Returns false it the event could not be recorded. Requires write access |
43 // to the HKCU registry hive on windows. | 47 // to the HKCU registry hive on windows. |
44 static bool RecordProductEvent(rlz_lib::Product product, | 48 static bool RecordProductEvent(rlz_lib::Product product, |
45 rlz_lib::AccessPoint point, | 49 rlz_lib::AccessPoint point, |
46 rlz_lib::Event event_id); | 50 rlz_lib::Event event_id); |
47 | 51 |
48 // Get the RLZ value of the access point. | 52 // Get the RLZ value of the access point. |
49 // Returns false if the rlz string could not be obtained. In some cases | 53 // Returns false if the rlz string could not be obtained. In some cases |
50 // an empty string can be returned which is not an error. | 54 // an empty string can be returned which is not an error. |
51 static bool GetAccessPointRlz(rlz_lib::AccessPoint point, std::wstring* rlz); | 55 static bool GetAccessPointRlz(rlz_lib::AccessPoint point, std::wstring* rlz); |
52 | 56 |
53 // Invoked during shutdown to clean up any state created by RLZTracker. | 57 // Invoked during shutdown to clean up any state created by RLZTracker. |
54 static void CleanupRlz(); | 58 static void CleanupRlz(); |
55 | 59 |
60 // This method is public for use by the Singleton class. | |
61 static RLZTracker* GetInstance(); | |
62 | |
63 // The following methods are made protected so that they can be used for | |
64 // testing purposes. Production code should never need to call these. | |
65 protected: | |
66 RLZTracker(); | |
67 ~RLZTracker(); | |
68 | |
69 // This is a temporary constant used here until the home page change is | |
70 // committed, which will happen before 2011-09-01. This constant will be | |
cpu_(ooo_6.6-7.5)
2011/08/26 21:37:51
In the existing code here there is only one space
Roger Tawa OOO till Jul 10th
2011/08/27 02:00:06
Did global search and replace in all files.
| |
71 // replaced with PageTransition::HOME_PAGE. | |
72 static const int RLZ_PAGETRANSITION_HOME_PAGE = 0x02000000; | |
73 | |
74 // Thread function entry point, see ScheduleFinancialPing(). Assumes argument | |
75 // is a pointer to an RLZTracker. | |
76 static void _cdecl PingNow(void* tracker); | |
77 | |
78 // Performs initialization of RLZ tracker that is purposfully delayed so | |
cpu_(ooo_6.6-7.5)
2011/08/26 21:37:51
purposfully: typo
Roger Tawa OOO till Jul 10th
2011/08/27 02:00:06
Done.
| |
79 // that it does not interfere with chrome startup time. | |
cpu_(ooo_6.6-7.5)
2011/08/26 21:37:51
That
Roger Tawa OOO till Jul 10th
2011/08/27 02:00:06
Not sure what you mean.
| |
80 virtual void DelayedInit(); | |
81 | |
82 // NotificationObserver implementation: | |
83 virtual void Observe(int type, | |
84 const NotificationSource& source, | |
85 const NotificationDetails& details) OVERRIDE; | |
86 | |
87 // Used by test code to override the default RLZTracker instance returned | |
88 // by GetInstance(). | |
89 void set_tracker(RLZTracker* tracker) { | |
90 tracker_ = tracker; | |
91 } | |
92 | |
56 private: | 93 private: |
57 DISALLOW_IMPLICIT_CONSTRUCTORS(RLZTracker); | 94 friend struct DefaultSingletonTraits<RLZTracker>; |
95 friend class base::RefCountedThreadSafe<RLZTracker>; | |
cpu_(ooo_6.6-7.5)
2011/08/26 21:37:51
are we refcounted?
Roger Tawa OOO till Jul 10th
2011/08/27 02:00:06
In order to use NewRunnableMethod(), the class tha
| |
96 | |
97 // Implementation called from InitRlzDelayed() static method. | |
98 bool Init(bool first_run, int delay, bool google_default_search, | |
99 bool google_default_homepage); | |
100 | |
101 // Implementation called from RecordProductEvent() static method. | |
102 bool GetAccessPointRlzImpl(rlz_lib::AccessPoint point, std::wstring* rlz); | |
103 | |
104 // Schedules the delayed initialization. This method is virtual to allow | |
105 // tests to override how the scheduling is done. | |
106 virtual void ScheduleDelayedInit(int delay); | |
107 | |
108 // Schedules a call to rlz_lib::SendFinancialPing(). This method is virtual | |
109 // to allow tests to override how the scheduling is done. | |
110 virtual void ScheduleFinancialPing(); | |
111 | |
112 // Schedules a call to GetAccessPointRlz() on the I/O thread if the current | |
113 // thread is not already the I/O thread, otherwise does nothing. Returns | |
114 // true if the call was scheduled, and false otherwise. This method is | |
115 // virtual to allow tests to override how the scheduling is done. | |
116 virtual bool ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point); | |
117 | |
118 // Sends the financial ping to the RLZ servers and invalidates the RLZ string | |
119 // cache since the response from the RLZ server may have changed then. | |
120 void PingNowImpl(); | |
121 | |
122 // Sends the financial ping to the RLZ servers. This method is virtual to | |
123 // allow tests to override. | |
124 virtual bool SendFinancialPing(const std::wstring& brand, | |
125 const std::wstring& lang, | |
126 const std::wstring& referral, | |
127 bool exclude_id); | |
128 | |
129 // Tracker used for testing purposes only. If this value is non-NULL, it | |
130 // will be returned from GetInstance() instead of the regular singleton. | |
131 static RLZTracker* tracker_; | |
132 | |
133 // Configuation data for RLZ tracker. Set by call to Init(). | |
134 bool first_run_; | |
135 bool send_ping_immediately_; | |
136 bool google_default_search_; | |
137 bool google_default_homepage_; | |
138 | |
139 // Keeps track if the RLZ tracker has already performed its delayed | |
140 // initialization. | |
141 bool already_ran_; | |
142 | |
143 // Keeps a cache of RLZ access point strings, since they rarely change. | |
144 // The cache must be protected by a lock since it may be accessed from | |
145 // the UI thread for reading and the IO thread for reading and/or writing. | |
146 base::Lock cache_lock_; | |
147 std::map<rlz_lib::AccessPoint, std::wstring> rlz_cache_; | |
148 | |
149 // Keeps track of whether the omnibox or host page have been used. | |
150 bool omnibox_used_; | |
151 bool homepage_used_; | |
152 | |
153 NotificationRegistrar registrar_; | |
154 | |
155 DISALLOW_COPY_AND_ASSIGN(RLZTracker); | |
58 }; | 156 }; |
59 | 157 |
158 // The RLZTracker is a singleton object that outlives any runnable tasks | |
159 // that will be queued up. | |
160 DISABLE_RUNNABLE_METHOD_REFCOUNT(RLZTracker); | |
161 | |
60 #endif // defined(OS_WIN) | 162 #endif // defined(OS_WIN) |
61 | 163 |
62 #endif // CHROME_BROWSER_RLZ_RLZ_H_ | 164 #endif // CHROME_BROWSER_RLZ_RLZ_H_ |
OLD | NEW |