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

Side by Side Diff: chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_fetcher_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_fetcher_win .h" 5 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_fetcher_win .h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/guid.h" 15 #include "base/guid.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
21 #include "base/metrics/histogram_macros.h"
21 #include "base/sequenced_task_runner.h" 22 #include "base/sequenced_task_runner.h"
22 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
23 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
24 #include "base/task_runner_util.h" 25 #include "base/task_runner_util.h"
25 #include "base/task_scheduler/post_task.h" 26 #include "base/task_scheduler/post_task.h"
26 #include "chrome/browser/browser_process.h" 27 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h" 28 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h"
28 #include "chrome/install_static/install_details.h" 29 #include "chrome/install_static/install_details.h"
29 #include "chrome/install_static/install_modes.h" 30 #include "chrome/install_static/install_modes.h"
30 #include "components/data_use_measurement/core/data_use_user_data.h" 31 #include "components/data_use_measurement/core/data_use_user_data.h"
(...skipping 14 matching lines...) Expand all
45 // Create a temporary directory name prefix like "ChromeCleaner_4_", where 46 // Create a temporary directory name prefix like "ChromeCleaner_4_", where
46 // "Chrome" is the product name and the 4 refers to the install mode of the 47 // "Chrome" is the product name and the 4 refers to the install mode of the
47 // browser. 48 // browser.
48 int install_mode = install_static::InstallDetails::Get().install_mode_index(); 49 int install_mode = install_static::InstallDetails::Get().install_mode_index();
49 return base::StringPrintf( 50 return base::StringPrintf(
50 FILE_PATH_LITERAL("%" PRFilePath "%" PRFilePath "_%d_"), 51 FILE_PATH_LITERAL("%" PRFilePath "%" PRFilePath "_%d_"),
51 install_static::kProductPathName, FILE_PATH_LITERAL("Cleaner"), 52 install_static::kProductPathName, FILE_PATH_LITERAL("Cleaner"),
52 install_mode); 53 install_mode);
53 } 54 }
54 55
56 enum CleanerDownloadStatusHistogramValue {
csharp 2017/07/07 17:32:51 Please add a comment saying this must say in sync
ftirelo 2017/07/07 20:27:53 Done.
57 CLEANER_DOWNLOAD_STATUS_SUCCEEDED = 0,
58 CLEANER_DOWNLOAD_STATUS_OTHER_FAILURE = 1,
59 CLEANER_DOWNLOAD_STATUS_NOT_FOUND_ON_SERVER = 2,
60 CLEANER_DOWNLOAD_STATUS_FAILED_TO_CREATE_TEMP_DIR = 3,
61
62 CLEANER_DOWNLOAD_STATUS_MAX,
63 };
64
65 void RecordCleanerDownloadStatusHistogram(
66 CleanerDownloadStatusHistogramValue value) {
67 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.CleanerDownloadStatus", value,
68 CLEANER_DOWNLOAD_STATUS_MAX);
69 }
70
55 // Class that will attempt to download the Chrome Cleaner executable and call a 71 // Class that will attempt to download the Chrome Cleaner executable and call a
56 // given callback when done. Instances of ChromeCleanerFetcher own themselves 72 // given callback when done. Instances of ChromeCleanerFetcher own themselves
57 // and will self-delete if they encounter an error or when the network request 73 // and will self-delete if they encounter an error or when the network request
58 // has completed. 74 // has completed.
59 class ChromeCleanerFetcher : public net::URLFetcherDelegate { 75 class ChromeCleanerFetcher : public net::URLFetcherDelegate {
60 public: 76 public:
61 explicit ChromeCleanerFetcher(ChromeCleanerFetchedCallback fetched_callback); 77 explicit ChromeCleanerFetcher(ChromeCleanerFetchedCallback fetched_callback);
62 78
63 protected: 79 protected:
64 ~ChromeCleanerFetcher() override; 80 ~ChromeCleanerFetcher() override;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return base::CreateNewTempDirectory(CleanerTempDirectoryPrefix(), 135 return base::CreateNewTempDirectory(CleanerTempDirectoryPrefix(),
120 &temp_dir) && 136 &temp_dir) &&
121 scoped_temp_dir_->Set(temp_dir); 137 scoped_temp_dir_->Set(temp_dir);
122 } 138 }
123 139
124 void ChromeCleanerFetcher::OnTemporaryDirectoryCreated(bool success) { 140 void ChromeCleanerFetcher::OnTemporaryDirectoryCreated(bool success) {
125 if (!success) { 141 if (!success) {
126 PostCallbackAndDeleteSelf( 142 PostCallbackAndDeleteSelf(
127 base::FilePath(), 143 base::FilePath(),
128 ChromeCleanerFetchStatus::kFailedToCreateTemporaryDirectory); 144 ChromeCleanerFetchStatus::kFailedToCreateTemporaryDirectory);
145 RecordCleanerDownloadStatusHistogram(
csharp 2017/07/07 17:32:51 This should probably be move up a line so it is do
ftirelo 2017/07/07 20:27:53 Done. Also did for the other calls.
146 CLEANER_DOWNLOAD_STATUS_FAILED_TO_CREATE_TEMP_DIR);
129 return; 147 return;
130 } 148 }
131 149
132 DCHECK(!scoped_temp_dir_->GetPath().empty()); 150 DCHECK(!scoped_temp_dir_->GetPath().empty());
133 151
134 temp_file_ = scoped_temp_dir_->GetPath().Append( 152 temp_file_ = scoped_temp_dir_->GetPath().Append(
135 base::ASCIIToUTF16(base::GenerateGUID()) + L".tmp"); 153 base::ASCIIToUTF16(base::GenerateGUID()) + L".tmp");
136 154
137 data_use_measurement::DataUseUserData::AttachToFetcher( 155 data_use_measurement::DataUseUserData::AttachToFetcher(
138 url_fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); 156 url_fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING);
(...skipping 22 matching lines...) Expand all
161 179
162 void ChromeCleanerFetcher::OnURLFetchComplete(const net::URLFetcher* source) { 180 void ChromeCleanerFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
163 // Take ownership of the fetcher in this scope (source == url_fetcher_). 181 // Take ownership of the fetcher in this scope (source == url_fetcher_).
164 DCHECK_EQ(url_fetcher_.get(), source); 182 DCHECK_EQ(url_fetcher_.get(), source);
165 DCHECK(!source->GetStatus().is_io_pending()); 183 DCHECK(!source->GetStatus().is_io_pending());
166 DCHECK(fetched_callback_); 184 DCHECK(fetched_callback_);
167 185
168 if (source->GetResponseCode() == net::HTTP_NOT_FOUND) { 186 if (source->GetResponseCode() == net::HTTP_NOT_FOUND) {
169 PostCallbackAndDeleteSelf(base::FilePath(), 187 PostCallbackAndDeleteSelf(base::FilePath(),
170 ChromeCleanerFetchStatus::kNotFoundOnServer); 188 ChromeCleanerFetchStatus::kNotFoundOnServer);
189 RecordCleanerDownloadStatusHistogram(
190 CLEANER_DOWNLOAD_STATUS_NOT_FOUND_ON_SERVER);
171 return; 191 return;
172 } 192 }
173 193
174 base::FilePath download_path; 194 base::FilePath download_path;
175 if (!source->GetStatus().is_success() || 195 if (!source->GetStatus().is_success() ||
176 source->GetResponseCode() != net::HTTP_OK || 196 source->GetResponseCode() != net::HTTP_OK ||
177 !source->GetResponseAsFilePath(/*take_ownership=*/true, &download_path)) { 197 !source->GetResponseAsFilePath(/*take_ownership=*/true, &download_path)) {
178 PostCallbackAndDeleteSelf(base::FilePath(), 198 PostCallbackAndDeleteSelf(base::FilePath(),
179 ChromeCleanerFetchStatus::kOtherFailure); 199 ChromeCleanerFetchStatus::kOtherFailure);
200 RecordCleanerDownloadStatusHistogram(CLEANER_DOWNLOAD_STATUS_OTHER_FAILURE);
180 return; 201 return;
181 } 202 }
182 203
183 DCHECK(!download_path.empty()); 204 DCHECK(!download_path.empty());
184 DCHECK_EQ(temp_file_.value(), download_path.value()); 205 DCHECK_EQ(temp_file_.value(), download_path.value());
185 206
186 // Take ownership of the scoped temp directory so it is not deleted. 207 // Take ownership of the scoped temp directory so it is not deleted.
187 scoped_temp_dir_->Take(); 208 scoped_temp_dir_->Take();
188 209
189 PostCallbackAndDeleteSelf(std::move(download_path), 210 PostCallbackAndDeleteSelf(std::move(download_path),
190 ChromeCleanerFetchStatus::kSuccess); 211 ChromeCleanerFetchStatus::kSuccess);
212 RecordCleanerDownloadStatusHistogram(CLEANER_DOWNLOAD_STATUS_SUCCEEDED);
191 } 213 }
192 214
193 } // namespace 215 } // namespace
194 216
195 void FetchChromeCleaner(ChromeCleanerFetchedCallback fetched_callback) { 217 void FetchChromeCleaner(ChromeCleanerFetchedCallback fetched_callback) {
196 new ChromeCleanerFetcher(std::move(fetched_callback)); 218 new ChromeCleanerFetcher(std::move(fetched_callback));
197 } 219 }
198 220
199 } // namespace safe_browsing 221 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698