| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/reporter_runner_win.h" | 5 #include "chrome/browser/safe_browsing/chrome_cleaner/reporter_runner_win.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 const std::wstring registry_key_; | 476 const std::wstring registry_key_; |
| 477 }; | 477 }; |
| 478 | 478 |
| 479 // Records the reporter step without a suffix. (For steps that are never run by | 479 // Records the reporter step without a suffix. (For steps that are never run by |
| 480 // the experimental reporter.) | 480 // the experimental reporter.) |
| 481 void RecordReporterStepHistogram(SwReporterUmaValue value) { | 481 void RecordReporterStepHistogram(SwReporterUmaValue value) { |
| 482 UMAHistogramReporter uma; | 482 UMAHistogramReporter uma; |
| 483 uma.RecordReporterStep(value); | 483 uma.RecordReporterStep(value); |
| 484 } | 484 } |
| 485 | 485 |
| 486 void DisplaySRTPrompt(base::FilePath download_path, int http_response_code) { | 486 void DisplaySRTPrompt(base::FilePath download_path, |
| 487 ChromeCleanerFetchStatus fetch_status) { |
| 487 // As long as the fetch didn't fail due to HTTP_NOT_FOUND, show a prompt | 488 // As long as the fetch didn't fail due to HTTP_NOT_FOUND, show a prompt |
| 488 // (either offering the tool directly or pointing to the download page). | 489 // (either offering the tool directly or pointing to the download page). |
| 489 // If the fetch failed to find the file, don't prompt the user since the | 490 // If the fetch failed to find the file, don't prompt the user since the |
| 490 // tool is not currently available. | 491 // tool is not currently available. |
| 491 // TODO(csharp): In the event the browser is closed before the prompt | 492 // TODO(csharp): In the event the browser is closed before the prompt |
| 492 // displays, we will wait until the next scanner run to | 493 // displays, we will wait until the next scanner run to |
| 493 // re-display it. Improve this. http://crbug.com/460295 | 494 // re-display it. Improve this. http://crbug.com/460295 |
| 494 if (http_response_code == net::HTTP_NOT_FOUND) { | 495 if (fetch_status == ChromeCleanerFetchStatus::kNotFoundOnServer) { |
| 495 RecordSRTPromptHistogram(SRT_PROMPT_DOWNLOAD_UNAVAILABLE); | 496 RecordSRTPromptHistogram(SRT_PROMPT_DOWNLOAD_UNAVAILABLE); |
| 496 return; | 497 return; |
| 497 } | 498 } |
| 498 | 499 |
| 499 // Find the last active browser, which may be NULL, in which case we won't | 500 // Find the last active browser, which may be NULL, in which case we won't |
| 500 // show the prompt this time and will wait until the next run of the | 501 // show the prompt this time and will wait until the next run of the |
| 501 // reporter. We can't use other ways of finding a browser because we don't | 502 // reporter. We can't use other ways of finding a browser because we don't |
| 502 // have a profile. | 503 // have a profile. |
| 503 Browser* browser = chrome::FindLastActive(); | 504 Browser* browser = chrome::FindLastActive(); |
| 504 if (!browser) | 505 if (!browser) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 DCHECK(success); | 565 DCHECK(success); |
| 565 } else { | 566 } else { |
| 566 uma.RecordReporterStep(SW_REPORTER_FAILED_TO_START); | 567 uma.RecordReporterStep(SW_REPORTER_FAILED_TO_START); |
| 567 } | 568 } |
| 568 return exit_code; | 569 return exit_code; |
| 569 } | 570 } |
| 570 | 571 |
| 571 } // namespace | 572 } // namespace |
| 572 | 573 |
| 573 void DisplaySRTPromptForTesting(const base::FilePath& download_path) { | 574 void DisplaySRTPromptForTesting(const base::FilePath& download_path) { |
| 574 DisplaySRTPrompt(download_path, net::HTTP_OK); | 575 DisplaySRTPrompt(download_path, ChromeCleanerFetchStatus::kSuccess); |
| 575 } | 576 } |
| 576 | 577 |
| 577 namespace { | 578 namespace { |
| 578 | 579 |
| 579 // Try to fetch the SRT, and on success, show the prompt to run it. | 580 // Try to fetch the SRT, and on success, show the prompt to run it. |
| 580 void MaybeFetchSRT(Browser* browser, const base::Version& reporter_version) { | 581 void MaybeFetchSRT(Browser* browser, const base::Version& reporter_version) { |
| 581 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 582 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 582 | 583 |
| 583 if (g_testing_delegate_) { | 584 if (g_testing_delegate_) { |
| 584 g_testing_delegate_->TriggerPrompt(browser, reporter_version.GetString()); | 585 g_testing_delegate_->TriggerPrompt(browser, reporter_version.GetString()); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), | 988 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), |
| 988 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 989 KEY_QUERY_VALUE) == ERROR_SUCCESS && |
| 989 srt_cleaner_key.GetValueCount() > 0; | 990 srt_cleaner_key.GetValueCount() > 0; |
| 990 } | 991 } |
| 991 | 992 |
| 992 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { | 993 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { |
| 993 g_testing_delegate_ = delegate; | 994 g_testing_delegate_ = delegate; |
| 994 } | 995 } |
| 995 | 996 |
| 996 } // namespace safe_browsing | 997 } // namespace safe_browsing |
| OLD | NEW |