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

Side by Side Diff: chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_win.cc

Issue 2973873002: Primary histograms for InBrowserCleanerUI experiment (Closed)
Patch Set: Histograms and enums Created 3 years, 5 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/safe_browsing/chrome_cleaner/chrome_cleaner_controller_ win.h" 5 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_ win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
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/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/metrics/histogram_macros.h"
18 #include "base/task_scheduler/post_task.h" 19 #include "base/task_scheduler/post_task.h"
19 #include "base/task_scheduler/task_traits.h" 20 #include "base/task_scheduler/task_traits.h"
20 #include "base/threading/thread_restrictions.h" 21 #include "base/threading/thread_restrictions.h"
21 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
22 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 24 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_fetcher_win .h" 27 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_fetcher_win .h"
27 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_runner_win. h" 28 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_runner_win. h"
28 #include "chrome/browser/safe_browsing/chrome_cleaner/settings_resetter_win.h" 29 #include "chrome/browser/safe_browsing/chrome_cleaner/settings_resetter_win.h"
29 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_client_info_win.h" 30 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_client_info_win.h"
31 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h"
30 #include "chrome/installer/util/scoped_token_privilege.h" 32 #include "chrome/installer/util/scoped_token_privilege.h"
31 #include "components/chrome_cleaner/public/constants/constants.h" 33 #include "components/chrome_cleaner/public/constants/constants.h"
32 #include "components/safe_browsing/common/safe_browsing_prefs.h" 34 #include "components/safe_browsing/common/safe_browsing_prefs.h"
33 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
34 #include "net/http/http_status_code.h" 36 #include "net/http/http_status_code.h"
35 37
36 namespace safe_browsing { 38 namespace safe_browsing {
37 39
38 namespace { 40 namespace {
39 41
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 ChromeCleanerController::IdleReason IdleReasonWhenConnectionClosedTooSoon( 95 ChromeCleanerController::IdleReason IdleReasonWhenConnectionClosedTooSoon(
94 ChromeCleanerController::State current_state) { 96 ChromeCleanerController::State current_state) {
95 DCHECK(current_state == ChromeCleanerController::State::kScanning || 97 DCHECK(current_state == ChromeCleanerController::State::kScanning ||
96 current_state == ChromeCleanerController::State::kInfected); 98 current_state == ChromeCleanerController::State::kInfected);
97 99
98 return current_state == ChromeCleanerController::State::kScanning 100 return current_state == ChromeCleanerController::State::kScanning
99 ? ChromeCleanerController::IdleReason::kScanningFailed 101 ? ChromeCleanerController::IdleReason::kScanningFailed
100 : ChromeCleanerController::IdleReason::kConnectionLost; 102 : ChromeCleanerController::IdleReason::kConnectionLost;
101 } 103 }
102 104
105 void RecordCleanerLogsAcceptanceHistogram(bool value) {
csharp 2017/07/07 17:32:51 what about logs_uploaded instead of value?
ftirelo 2017/07/07 20:27:52 Used logs_accepted instead.
106 UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.CleanerLogsAcceptance", value);
107 }
108
103 } // namespace 109 } // namespace
104 110
111 void RecordCleanupStartedHistogram(CleanupStartedHistogramValue value) {
112 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.CleanupStarted", value,
113 CLEANUP_STARTED_MAX);
114 }
115
105 ChromeCleanerControllerDelegate::ChromeCleanerControllerDelegate() = default; 116 ChromeCleanerControllerDelegate::ChromeCleanerControllerDelegate() = default;
106 117
107 ChromeCleanerControllerDelegate::~ChromeCleanerControllerDelegate() = default; 118 ChromeCleanerControllerDelegate::~ChromeCleanerControllerDelegate() = default;
108 119
109 void ChromeCleanerControllerDelegate::FetchAndVerifyChromeCleaner( 120 void ChromeCleanerControllerDelegate::FetchAndVerifyChromeCleaner(
110 FetchedCallback fetched_callback) { 121 FetchedCallback fetched_callback) {
111 FetchChromeCleaner( 122 FetchChromeCleaner(
112 base::BindOnce(&OnChromeCleanerFetched, base::Passed(&fetched_callback))); 123 base::BindOnce(&OnChromeCleanerFetched, base::Passed(&fetched_callback)));
113 } 124 }
114 125
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 return; 235 return;
225 236
226 DCHECK(prompt_user_callback_); 237 DCHECK(prompt_user_callback_);
227 238
228 PromptAcceptance acceptance = PromptAcceptance::DENIED; 239 PromptAcceptance acceptance = PromptAcceptance::DENIED;
229 State new_state = State::kIdle; 240 State new_state = State::kIdle;
230 switch (user_response) { 241 switch (user_response) {
231 case UserResponse::kAcceptedWithLogs: 242 case UserResponse::kAcceptedWithLogs:
232 acceptance = PromptAcceptance::ACCEPTED_WITH_LOGS; 243 acceptance = PromptAcceptance::ACCEPTED_WITH_LOGS;
233 SetLogsEnabled(true); 244 SetLogsEnabled(true);
245 RecordCleanerLogsAcceptanceHistogram(true);
234 new_state = State::kCleaning; 246 new_state = State::kCleaning;
235 delegate_->TagForResetting(profile); 247 delegate_->TagForResetting(profile);
236 break; 248 break;
237 case UserResponse::kAcceptedWithoutLogs: 249 case UserResponse::kAcceptedWithoutLogs:
238 acceptance = PromptAcceptance::ACCEPTED_WITHOUT_LOGS; 250 acceptance = PromptAcceptance::ACCEPTED_WITHOUT_LOGS;
239 SetLogsEnabled(false); 251 SetLogsEnabled(false);
252 RecordCleanerLogsAcceptanceHistogram(false);
240 new_state = State::kCleaning; 253 new_state = State::kCleaning;
241 delegate_->TagForResetting(profile); 254 delegate_->TagForResetting(profile);
242 break; 255 break;
243 case UserResponse::kDenied: // Fallthrough 256 case UserResponse::kDenied: // Fallthrough
244 case UserResponse::kDismissed: 257 case UserResponse::kDismissed:
245 acceptance = PromptAcceptance::DENIED; 258 acceptance = PromptAcceptance::DENIED;
246 idle_reason_ = IdleReason::kUserDeclinedCleanup; 259 idle_reason_ = IdleReason::kUserDeclinedCleanup;
247 new_state = State::kIdle; 260 new_state = State::kIdle;
248 break; 261 break;
249 } 262 }
250 263
251 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) 264 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)
252 ->PostTask(FROM_HERE, 265 ->PostTask(FROM_HERE,
253 base::BindOnce(std::move(prompt_user_callback_), acceptance)); 266 base::BindOnce(std::move(prompt_user_callback_), acceptance));
254 267
255 // The transition to a new state should happen only after the response has 268 // The transition to a new state should happen only after the response has
256 // been posted on the UI thread so that if we transition to the kIdle state, 269 // been posted on the UI thread so that if we transition to the kIdle state,
257 // the response callback is not cleared before it has been posted. 270 // the response callback is not cleared before it has been posted.
258 SetStateAndNotifyObservers(new_state); 271 SetStateAndNotifyObservers(new_state);
259 } 272 }
260 273
261 void ChromeCleanerController::Reboot() { 274 void ChromeCleanerController::Reboot() {
262 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 275 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
263 276
264 if (state() != State::kRebootRequired) 277 if (state() != State::kRebootRequired)
265 return; 278 return;
266 279
280 UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.RebootInitiated", true);
267 InitiateReboot(); 281 InitiateReboot();
268 } 282 }
269 283
270 ChromeCleanerController::ChromeCleanerController() 284 ChromeCleanerController::ChromeCleanerController()
271 : real_delegate_(base::MakeUnique<ChromeCleanerControllerDelegate>()), 285 : real_delegate_(base::MakeUnique<ChromeCleanerControllerDelegate>()),
272 delegate_(real_delegate_.get()), 286 delegate_(real_delegate_.get()),
273 weak_factory_(this) { 287 weak_factory_(this) {
274 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 288 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
275 } 289 }
276 290
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 336
323 void ChromeCleanerController::OnChromeCleanerFetchedAndVerified( 337 void ChromeCleanerController::OnChromeCleanerFetchedAndVerified(
324 base::FilePath executable_path) { 338 base::FilePath executable_path) {
325 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 339 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
326 DCHECK_EQ(State::kScanning, state()); 340 DCHECK_EQ(State::kScanning, state());
327 DCHECK(reporter_invocation_); 341 DCHECK(reporter_invocation_);
328 342
329 if (executable_path.empty()) { 343 if (executable_path.empty()) {
330 idle_reason_ = IdleReason::kScanningFailed; 344 idle_reason_ = IdleReason::kScanningFailed;
331 SetStateAndNotifyObservers(State::kIdle); 345 SetStateAndNotifyObservers(State::kIdle);
346 RecordPromptNotShownWithReasonHistogram(
347 NO_PROMPT_REASON_CLEANER_DOWNLOAD_FAILED);
332 return; 348 return;
333 } 349 }
334 350
335 DCHECK(executable_path.MatchesExtension(FILE_PATH_LITERAL(".exe"))); 351 DCHECK(executable_path.MatchesExtension(FILE_PATH_LITERAL(".exe")));
336 352
337 ChromeCleanerRunner::ChromeMetricsStatus metrics_status = 353 ChromeCleanerRunner::ChromeMetricsStatus metrics_status =
338 delegate_->IsMetricsAndCrashReportingEnabled() 354 delegate_->IsMetricsAndCrashReportingEnabled()
339 ? ChromeCleanerRunner::ChromeMetricsStatus::kEnabled 355 ? ChromeCleanerRunner::ChromeMetricsStatus::kEnabled
340 : ChromeCleanerRunner::ChromeMetricsStatus::kDisabled; 356 : ChromeCleanerRunner::ChromeMetricsStatus::kDisabled;
341 357
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 DCHECK_EQ(State::kScanning, state()); 400 DCHECK_EQ(State::kScanning, state());
385 DCHECK(!files_to_delete_); 401 DCHECK(!files_to_delete_);
386 DCHECK(!prompt_user_callback_); 402 DCHECK(!prompt_user_callback_);
387 403
388 if (files_to_delete->empty()) { 404 if (files_to_delete->empty()) {
389 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) 405 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)
390 ->PostTask(FROM_HERE, base::BindOnce(std::move(prompt_user_callback), 406 ->PostTask(FROM_HERE, base::BindOnce(std::move(prompt_user_callback),
391 PromptAcceptance::DENIED)); 407 PromptAcceptance::DENIED));
392 idle_reason_ = IdleReason::kScanningFoundNothing; 408 idle_reason_ = IdleReason::kScanningFoundNothing;
393 SetStateAndNotifyObservers(State::kIdle); 409 SetStateAndNotifyObservers(State::kIdle);
410 RecordPromptNotShownWithReasonHistogram(NO_PROMPT_REASON_NOTHING_FOUND);
394 return; 411 return;
395 } 412 }
396 413
414 UMA_HISTOGRAM_COUNTS_1000("SoftwareReporter.NumberOfFilesToDelete",
415 files_to_delete->size());
csharp 2017/07/07 17:32:51 Is there any problem if files_to_delete->size() >
ftirelo 2017/07/07 20:27:52 There is an overflow buffer for counts > 1000. Sin
397 files_to_delete_ = std::move(files_to_delete); 416 files_to_delete_ = std::move(files_to_delete);
398 prompt_user_callback_ = std::move(prompt_user_callback); 417 prompt_user_callback_ = std::move(prompt_user_callback);
399 SetStateAndNotifyObservers(State::kInfected); 418 SetStateAndNotifyObservers(State::kInfected);
400 } 419 }
401 420
402 void ChromeCleanerController::OnConnectionClosed() { 421 void ChromeCleanerController::OnConnectionClosed() {
403 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 422 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
404 DCHECK_NE(State::kIdle, state()); 423 DCHECK_NE(State::kIdle, state());
405 DCHECK_NE(State::kRebootRequired, state()); 424 DCHECK_NE(State::kRebootRequired, state());
406 425
407 if (state() == State::kScanning || state() == State::kInfected) { 426 if (state() == State::kScanning || state() == State::kInfected) {
408 idle_reason_ = IdleReasonWhenConnectionClosedTooSoon(state()); 427 idle_reason_ = IdleReasonWhenConnectionClosedTooSoon(state());
409 SetStateAndNotifyObservers(State::kIdle); 428 SetStateAndNotifyObservers(State::kIdle);
429 RecordPromptNotShownWithReasonHistogram(
430 NO_PROMPT_REASON_IPC_CONNECTION_BROKEN);
csharp 2017/07/07 17:32:51 Is it possible for the connect to be closed after
ftirelo 2017/07/07 20:27:52 Yes, if the cleaner binary crashes.
csharp 2017/07/07 20:53:33 Should this be counted then, since in that case wo
ftirelo 2017/07/07 21:22:07 Added a new histogram for moment when IPC connecti
410 return; 431 return;
411 } 432 }
412 // Nothing to do if OnConnectionClosed() is called in other states: 433 // Nothing to do if OnConnectionClosed() is called in other states:
413 // - This function will not be called in the kIdle and kRebootRequired 434 // - This function will not be called in the kIdle and kRebootRequired
414 // states since we invalidate all weak pointers when we enter those states. 435 // states since we invalidate all weak pointers when we enter those states.
415 // - In the kCleaning state, we don't care about the connection to the Chrome 436 // - In the kCleaning state, we don't care about the connection to the Chrome
416 // Cleaner process since communication via Mojo is complete and only the 437 // Cleaner process since communication via Mojo is complete and only the
417 // exit code of the process is of any use to us (for deciding whether we 438 // exit code of the process is of any use to us (for deciding whether we
418 // need to reboot). 439 // need to reboot).
419 } 440 }
(...skipping 13 matching lines...) Expand all
433 process_status.launch_status); 454 process_status.launch_status);
434 455
435 if (process_status.launch_status != 456 if (process_status.launch_status !=
436 ChromeCleanerRunner::LaunchStatus::kSuccess) { 457 ChromeCleanerRunner::LaunchStatus::kSuccess) {
437 idle_reason_ = IdleReason::kCleaningFailed; 458 idle_reason_ = IdleReason::kCleaningFailed;
438 SetStateAndNotifyObservers(State::kIdle); 459 SetStateAndNotifyObservers(State::kIdle);
439 return; 460 return;
440 } 461 }
441 462
442 if (process_status.exit_code == kRebootRequiredExitCode) { 463 if (process_status.exit_code == kRebootRequiredExitCode) {
464 UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.RebootRequired", true);
443 SetStateAndNotifyObservers(State::kRebootRequired); 465 SetStateAndNotifyObservers(State::kRebootRequired);
444 return; 466 return;
445 } 467 }
446 468
447 if (process_status.exit_code == kRebootNotRequiredExitCode) { 469 if (process_status.exit_code == kRebootNotRequiredExitCode) {
448 delegate_->ResetTaggedProfiles( 470 delegate_->ResetTaggedProfiles(
449 g_browser_process->profile_manager()->GetLoadedProfiles(), 471 g_browser_process->profile_manager()->GetLoadedProfiles(),
450 base::BindOnce(&ChromeCleanerController::OnSettingsResetCompleted, 472 base::BindOnce(&ChromeCleanerController::OnSettingsResetCompleted,
451 base::Unretained(this))); 473 base::Unretained(this)));
452 ResetCleanerDataAndInvalidateWeakPtrs(); 474 ResetCleanerDataAndInvalidateWeakPtrs();
(...skipping 17 matching lines...) Expand all
470 observer.OnRebootFailed(); 492 observer.OnRebootFailed();
471 } 493 }
472 } 494 }
473 495
474 void ChromeCleanerController::OnSettingsResetCompleted() { 496 void ChromeCleanerController::OnSettingsResetCompleted() {
475 idle_reason_ = IdleReason::kCleaningSucceeded; 497 idle_reason_ = IdleReason::kCleaningSucceeded;
476 SetStateAndNotifyObservers(State::kIdle); 498 SetStateAndNotifyObservers(State::kIdle);
477 } 499 }
478 500
479 } // namespace safe_browsing 501 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698