Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: chrome/browser/component_updater/sw_reporter_installer_win.cc

Issue 495643002: Trigger the SW reporter to run once a week for users with UMA enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 #include "chrome/browser/component_updater/sw_reporter_installer_win.h" 5 #include "chrome/browser/component_updater/sw_reporter_installer_win.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/metrics/sparse_histogram.h" 18 #include "base/metrics/sparse_histogram.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/prefs/pref_registry_simple.h" 20 #include "base/prefs/pref_registry_simple.h"
21 #include "base/prefs/pref_service.h" 21 #include "base/prefs/pref_service.h"
22 #include "base/process/kill.h" 22 #include "base/process/kill.h"
23 #include "base/process/launch.h" 23 #include "base/process/launch.h"
24 #include "base/task_runner_util.h" 24 #include "base/task_runner_util.h"
25 #include "base/threading/worker_pool.h" 25 #include "base/threading/worker_pool.h"
26 #include "base/time/time.h"
26 #include "base/win/registry.h" 27 #include "base/win/registry.h"
27 #include "chrome/browser/browser_process.h" 28 #include "chrome/browser/browser_process.h"
29 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
30 #include "chrome/common/pref_names.h"
28 #include "components/component_updater/component_updater_paths.h" 31 #include "components/component_updater/component_updater_paths.h"
29 #include "components/component_updater/component_updater_service.h" 32 #include "components/component_updater/component_updater_service.h"
30 #include "components/component_updater/component_updater_utils.h" 33 #include "components/component_updater/component_updater_utils.h"
31 #include "components/component_updater/default_component_installer.h" 34 #include "components/component_updater/default_component_installer.h"
32 #include "components/component_updater/pref_names.h" 35 #include "components/component_updater/pref_names.h"
33 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
34 37
35 using content::BrowserThread; 38 using content::BrowserThread;
36 39
37 namespace component_updater { 40 namespace component_updater {
38 41
39 namespace { 42 namespace {
40 43
41 // These values are used to send UMA information and are replicated in the 44 // These values are used to send UMA information and are replicated in the
42 // histograms.xml file, so the order MUST NOT CHANGE. 45 // histograms.xml file, so the order MUST NOT CHANGE.
43 enum SwReporterUmaValue { 46 enum SwReporterUmaValue {
44 SW_REPORTER_EXPLICIT_REQUEST = 0, 47 SW_REPORTER_EXPLICIT_REQUEST = 0,
45 SW_REPORTER_STARTUP_RETRY = 1, 48 SW_REPORTER_STARTUP_RETRY = 1,
46 SW_REPORTER_RETRIED_TOO_MANY_TIMES = 2, 49 SW_REPORTER_RETRIED_TOO_MANY_TIMES = 2,
47 SW_REPORTER_START_EXECUTION = 3, 50 SW_REPORTER_START_EXECUTION = 3,
48 SW_REPORTER_FAILED_TO_START = 4, 51 SW_REPORTER_FAILED_TO_START = 4,
49 SW_REPORTER_REGISTRY_EXIT_CODE = 5, 52 SW_REPORTER_REGISTRY_EXIT_CODE = 5,
50 SW_REPORTER_RESET_RETRIES = 6, 53 SW_REPORTER_RESET_RETRIES = 6,
51 SW_REPORTER_MAX, 54 SW_REPORTER_MAX,
52 }; 55 };
53 56
54 // The maximum number of times to retry a download on startup. 57 // The maximum number of times to retry a download on startup.
55 const int kMaxRetry = 20; 58 const int kMaxRetry = 20;
56 59
60 // The number of days to wait before triggering another sw reporter run.
61 const int kDaysBetweenSwReporterRuns = 7;
62
57 // CRX hash. The extension id is: gkmgaooipdjhmangpemjhigmamcehddo. The hash was 63 // CRX hash. The extension id is: gkmgaooipdjhmangpemjhigmamcehddo. The hash was
58 // generated in Python with something like this: 64 // generated in Python with something like this:
59 // hashlib.sha256().update(open("<file>.crx").read()[16:16+294]).digest(). 65 // hashlib.sha256().update(open("<file>.crx").read()[16:16+294]).digest().
60 const uint8 kSha256Hash[] = {0x6a, 0xc6, 0x0e, 0xe8, 0xf3, 0x97, 0xc0, 0xd6, 66 const uint8 kSha256Hash[] = {0x6a, 0xc6, 0x0e, 0xe8, 0xf3, 0x97, 0xc0, 0xd6,
61 0xf4, 0xc9, 0x78, 0x6c, 0x0c, 0x24, 0x73, 0x3e, 67 0xf4, 0xc9, 0x78, 0x6c, 0x0c, 0x24, 0x73, 0x3e,
62 0x05, 0xa5, 0x62, 0x4b, 0x2e, 0xc7, 0xb7, 0x1c, 68 0x05, 0xa5, 0x62, 0x4b, 0x2e, 0xc7, 0xb7, 0x1c,
63 0x5f, 0xea, 0xf0, 0x88, 0xf6, 0x97, 0x9b, 0xc7}; 69 0x5f, 0xea, 0xf0, 0x88, 0xf6, 0x97, 0x9b, 0xc7};
64 70
65 const base::FilePath::CharType kSwReporterExeName[] = 71 const base::FilePath::CharType kSwReporterExeName[] =
66 FILE_PATH_LITERAL("software_reporter_tool.exe"); 72 FILE_PATH_LITERAL("software_reporter_tool.exe");
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 void ExecuteSwReporter(ComponentUpdateService* cus, PrefService* prefs) { 219 void ExecuteSwReporter(ComponentUpdateService* cus, PrefService* prefs) {
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
215 // If we have a pending execution, send metrics about it so we can account for 221 // If we have a pending execution, send metrics about it so we can account for
216 // missing executions. 222 // missing executions.
217 if (prefs->GetInteger(prefs::kSwReporterExecuteTryCount) > 0) 223 if (prefs->GetInteger(prefs::kSwReporterExecuteTryCount) > 0)
218 ReportUmaStep(SW_REPORTER_RESET_RETRIES); 224 ReportUmaStep(SW_REPORTER_RESET_RETRIES);
219 // This is an explicit call, so let's forget about previous incomplete 225 // This is an explicit call, so let's forget about previous incomplete
220 // execution attempts and start from scratch. 226 // execution attempts and start from scratch.
221 prefs->SetInteger(prefs::kSwReporterExecuteTryCount, kMaxRetry); 227 prefs->SetInteger(prefs::kSwReporterExecuteTryCount, kMaxRetry);
222 ReportUmaStep(SW_REPORTER_EXPLICIT_REQUEST); 228 ReportUmaStep(SW_REPORTER_EXPLICIT_REQUEST);
229 // Record the requested trigger time.
230 prefs->SetInt64(prefs::kSwReporterLastTimeTriggered,
231 base::Time::Now().ToInternalValue());
223 const std::vector<std::string> registered_components(cus->GetComponentIDs()); 232 const std::vector<std::string> registered_components(cus->GetComponentIDs());
224 if (std::find(registered_components.begin(), 233 if (std::find(registered_components.begin(),
225 registered_components.end(), 234 registered_components.end(),
226 SwReporterInstallerTraits::ID()) == 235 SwReporterInstallerTraits::ID()) ==
227 registered_components.end()) { 236 registered_components.end()) {
228 RegisterComponent(cus, prefs); 237 RegisterComponent(cus, prefs);
229 } else if (!SwReporterInstallerTraits::VersionPath().empty()) { 238 } else if (!SwReporterInstallerTraits::VersionPath().empty()) {
230 // Here, we already have a fully registered and installed component 239 // Here, we already have a fully registered and installed component
231 // available for immediate use. This doesn't handle cases where the version 240 // available for immediate use. This doesn't handle cases where the version
232 // folder is there but the executable is not within in. This is a corruption 241 // folder is there but the executable is not within in. This is a corruption
233 // we don't want to handle here. 242 // we don't want to handle here.
234 ExecuteReporter(SwReporterInstallerTraits::VersionPath()); 243 ExecuteReporter(SwReporterInstallerTraits::VersionPath());
235 } 244 }
236 // If the component is registered but the version path is not available, it 245 // If the component is registered but the version path is not available, it
237 // means the component was not fully installed yet, and it should run the 246 // means the component was not fully installed yet, and it should run the
238 // reporter when ComponentReady is called. 247 // reporter when ComponentReady is called.
239 } 248 }
240 249
241 void ExecutePendingSwReporter(ComponentUpdateService* cus, PrefService* prefs) { 250 void ExecuteSwReporterIfRequired(ComponentUpdateService* cus,
251 PrefService* prefs) {
242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
243 253
244 // Register the existing component for updates. 254 // Register the existing component for updates.
245 base::PostTaskAndReplyWithResult( 255 base::PostTaskAndReplyWithResult(
246 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 256 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
247 FROM_HERE, 257 FROM_HERE,
248 base::Bind(&base::PathExists, SwReporterInstallerTraits::install_dir()), 258 base::Bind(&base::PathExists, SwReporterInstallerTraits::install_dir()),
249 base::Bind(&MaybeRegisterComponent, cus, prefs)); 259 base::Bind(&MaybeRegisterComponent, cus, prefs));
250 260
251 // Run the reporter if there is a pending execution request. 261 // Run the reporter if there is a pending execution request.
(...skipping 13 matching lines...) Expand all
265 275
266 // The previous request has not completed. The reporter will run again 276 // The previous request has not completed. The reporter will run again
267 // when ComponentReady is called or the request is abandoned if it has 277 // when ComponentReady is called or the request is abandoned if it has
268 // been tried too many times. 278 // been tried too many times.
269 prefs->SetInteger(prefs::kSwReporterExecuteTryCount, --execute_try_count); 279 prefs->SetInteger(prefs::kSwReporterExecuteTryCount, --execute_try_count);
270 if (execute_try_count > 0) 280 if (execute_try_count > 0)
271 ReportUmaStep(SW_REPORTER_STARTUP_RETRY); 281 ReportUmaStep(SW_REPORTER_STARTUP_RETRY);
272 else 282 else
273 ReportUmaStep(SW_REPORTER_RETRIED_TOO_MANY_TIMES); 283 ReportUmaStep(SW_REPORTER_RETRIED_TOO_MANY_TIMES);
274 } 284 }
285
286 // Run the reporter if it hasn't been triggered in the last
287 // kDaysBetweenSwReporterRuns days and the user is opted-in to UMA.
288 const base::Time last_time_triggered = base::Time::FromInternalValue(
289 prefs->GetInt64(prefs::kSwReporterLastTimeTriggered));
290 if ((base::Time::Now() - last_time_triggered).InDays() >=
291 kDaysBetweenSwReporterRuns &&
292 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled()) {
MAD 2014/08/21 15:12:25 I would move the check for metrics outward so that
csharp 2014/08/21 17:13:59 I moved this check to the top of the function and
293 ExecuteSwReporter(cus, prefs);
294 }
275 } 295 }
276 296
277 void RegisterPrefsForSwReporter(PrefRegistrySimple* registry) { 297 void RegisterPrefsForSwReporter(PrefRegistrySimple* registry) {
278 registry->RegisterIntegerPref(prefs::kSwReporterExecuteTryCount, 0); 298 registry->RegisterIntegerPref(prefs::kSwReporterExecuteTryCount, 0);
299 registry->RegisterInt64Pref(prefs::kSwReporterLastTimeTriggered, 0);
279 } 300 }
280 301
281 } // namespace component_updater 302 } // namespace component_updater
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/sw_reporter_installer_win.h ('k') | chrome/browser/metrics/chrome_metrics_service_accessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698