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

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: Revert changes to histogram.cc 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 // These values are used to send UMA information and are replicated in the
57 // histograms.xml file, so the order MUST NOT CHANGE.
58 enum CleanerDownloadStatusHistogramValue {
59 CLEANER_DOWNLOAD_STATUS_SUCCEEDED = 0,
60 CLEANER_DOWNLOAD_STATUS_OTHER_FAILURE = 1,
61 CLEANER_DOWNLOAD_STATUS_NOT_FOUND_ON_SERVER = 2,
62 CLEANER_DOWNLOAD_STATUS_FAILED_TO_CREATE_TEMP_DIR = 3,
63
64 CLEANER_DOWNLOAD_STATUS_MAX,
65 };
66
67 void RecordCleanerDownloadStatusHistogram(
68 CleanerDownloadStatusHistogramValue value) {
69 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Cleaner.DownloadStatus", value,
70 CLEANER_DOWNLOAD_STATUS_MAX);
71 }
72
55 // Class that will attempt to download the Chrome Cleaner executable and call a 73 // Class that will attempt to download the Chrome Cleaner executable and call a
56 // given callback when done. Instances of ChromeCleanerFetcher own themselves 74 // given callback when done. Instances of ChromeCleanerFetcher own themselves
57 // and will self-delete if they encounter an error or when the network request 75 // and will self-delete if they encounter an error or when the network request
58 // has completed. 76 // has completed.
59 class ChromeCleanerFetcher : public net::URLFetcherDelegate { 77 class ChromeCleanerFetcher : public net::URLFetcherDelegate {
60 public: 78 public:
61 explicit ChromeCleanerFetcher(ChromeCleanerFetchedCallback fetched_callback); 79 explicit ChromeCleanerFetcher(ChromeCleanerFetchedCallback fetched_callback);
62 80
63 protected: 81 protected:
64 ~ChromeCleanerFetcher() override; 82 ~ChromeCleanerFetcher() override;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 134
117 bool ChromeCleanerFetcher::CreateTemporaryDirectory() { 135 bool ChromeCleanerFetcher::CreateTemporaryDirectory() {
118 base::FilePath temp_dir; 136 base::FilePath temp_dir;
119 return base::CreateNewTempDirectory(CleanerTempDirectoryPrefix(), 137 return base::CreateNewTempDirectory(CleanerTempDirectoryPrefix(),
120 &temp_dir) && 138 &temp_dir) &&
121 scoped_temp_dir_->Set(temp_dir); 139 scoped_temp_dir_->Set(temp_dir);
122 } 140 }
123 141
124 void ChromeCleanerFetcher::OnTemporaryDirectoryCreated(bool success) { 142 void ChromeCleanerFetcher::OnTemporaryDirectoryCreated(bool success) {
125 if (!success) { 143 if (!success) {
144 RecordCleanerDownloadStatusHistogram(
145 CLEANER_DOWNLOAD_STATUS_FAILED_TO_CREATE_TEMP_DIR);
126 PostCallbackAndDeleteSelf( 146 PostCallbackAndDeleteSelf(
127 base::FilePath(), 147 base::FilePath(),
128 ChromeCleanerFetchStatus::kFailedToCreateTemporaryDirectory); 148 ChromeCleanerFetchStatus::kFailedToCreateTemporaryDirectory);
129 return; 149 return;
130 } 150 }
131 151
132 DCHECK(!scoped_temp_dir_->GetPath().empty()); 152 DCHECK(!scoped_temp_dir_->GetPath().empty());
133 153
134 temp_file_ = scoped_temp_dir_->GetPath().Append( 154 temp_file_ = scoped_temp_dir_->GetPath().Append(
135 base::ASCIIToUTF16(base::GenerateGUID()) + L".tmp"); 155 base::ASCIIToUTF16(base::GenerateGUID()) + L".tmp");
(...skipping 23 matching lines...) Expand all
159 delete this; 179 delete this;
160 } 180 }
161 181
162 void ChromeCleanerFetcher::OnURLFetchComplete(const net::URLFetcher* source) { 182 void ChromeCleanerFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
163 // Take ownership of the fetcher in this scope (source == url_fetcher_). 183 // Take ownership of the fetcher in this scope (source == url_fetcher_).
164 DCHECK_EQ(url_fetcher_.get(), source); 184 DCHECK_EQ(url_fetcher_.get(), source);
165 DCHECK(!source->GetStatus().is_io_pending()); 185 DCHECK(!source->GetStatus().is_io_pending());
166 DCHECK(fetched_callback_); 186 DCHECK(fetched_callback_);
167 187
168 if (source->GetResponseCode() == net::HTTP_NOT_FOUND) { 188 if (source->GetResponseCode() == net::HTTP_NOT_FOUND) {
189 RecordCleanerDownloadStatusHistogram(
190 CLEANER_DOWNLOAD_STATUS_NOT_FOUND_ON_SERVER);
169 PostCallbackAndDeleteSelf(base::FilePath(), 191 PostCallbackAndDeleteSelf(base::FilePath(),
170 ChromeCleanerFetchStatus::kNotFoundOnServer); 192 ChromeCleanerFetchStatus::kNotFoundOnServer);
171 return; 193 return;
172 } 194 }
173 195
174 base::FilePath download_path; 196 base::FilePath download_path;
175 if (!source->GetStatus().is_success() || 197 if (!source->GetStatus().is_success() ||
176 source->GetResponseCode() != net::HTTP_OK || 198 source->GetResponseCode() != net::HTTP_OK ||
177 !source->GetResponseAsFilePath(/*take_ownership=*/true, &download_path)) { 199 !source->GetResponseAsFilePath(/*take_ownership=*/true, &download_path)) {
200 RecordCleanerDownloadStatusHistogram(CLEANER_DOWNLOAD_STATUS_OTHER_FAILURE);
178 PostCallbackAndDeleteSelf(base::FilePath(), 201 PostCallbackAndDeleteSelf(base::FilePath(),
179 ChromeCleanerFetchStatus::kOtherFailure); 202 ChromeCleanerFetchStatus::kOtherFailure);
180 return; 203 return;
181 } 204 }
182 205
183 DCHECK(!download_path.empty()); 206 DCHECK(!download_path.empty());
184 DCHECK_EQ(temp_file_.value(), download_path.value()); 207 DCHECK_EQ(temp_file_.value(), download_path.value());
185 208
186 // Take ownership of the scoped temp directory so it is not deleted. 209 // Take ownership of the scoped temp directory so it is not deleted.
187 scoped_temp_dir_->Take(); 210 scoped_temp_dir_->Take();
188 211
212 RecordCleanerDownloadStatusHistogram(CLEANER_DOWNLOAD_STATUS_SUCCEEDED);
189 PostCallbackAndDeleteSelf(std::move(download_path), 213 PostCallbackAndDeleteSelf(std::move(download_path),
190 ChromeCleanerFetchStatus::kSuccess); 214 ChromeCleanerFetchStatus::kSuccess);
191 } 215 }
192 216
193 } // namespace 217 } // namespace
194 218
195 void FetchChromeCleaner(ChromeCleanerFetchedCallback fetched_callback) { 219 void FetchChromeCleaner(ChromeCleanerFetchedCallback fetched_callback) {
196 new ChromeCleanerFetcher(std::move(fetched_callback)); 220 new ChromeCleanerFetcher(std::move(fetched_callback));
197 } 221 }
198 222
199 } // namespace safe_browsing 223 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698