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

Side by Side Diff: content/browser/browsing_data/clear_site_data_throttle.cc

Issue 2274853002: Add metrics for the Clear-Site-Data header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl format Created 4 years, 3 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/browsing_data/clear_site_data_throttle.h" 5 #include "content/browser/browsing_data/clear_site_data_throttle.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/metrics/histogram_macros.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "content/browser/frame_host/navigation_handle_impl.h" 15 #include "content/browser/frame_host/navigation_handle_impl.h"
15 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/content_browser_client.h" 17 #include "content/public/browser/content_browser_client.h"
17 #include "content/public/browser/navigation_handle.h" 18 #include "content/public/browser/navigation_handle.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/content_client.h" 20 #include "content/public/common/content_client.h"
20 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
(...skipping 22 matching lines...) Expand all
43 const std::string& text, 44 const std::string& text,
44 ConsoleMessageLevel level) { 45 ConsoleMessageLevel level) {
45 messages->push_back({url, text, level}); 46 messages->push_back({url, text, level});
46 } 47 }
47 48
48 bool AreExperimentalFeaturesEnabled() { 49 bool AreExperimentalFeaturesEnabled() {
49 return base::CommandLine::ForCurrentProcess()->HasSwitch( 50 return base::CommandLine::ForCurrentProcess()->HasSwitch(
50 switches::kEnableExperimentalWebPlatformFeatures); 51 switches::kEnableExperimentalWebPlatformFeatures);
51 } 52 }
52 53
54 // Represents the parameters as a single number to be recorded in a histogram.
55 int ParametersMask(bool clear_cookies, bool clear_storage, bool clear_cache) {
56 return static_cast<int>(clear_cookies) * (1 << 0) +
57 static_cast<int>(clear_storage) * (1 << 1) +
58 static_cast<int>(clear_cache) * (1 << 2);
59 }
60
53 } // namespace 61 } // namespace
54 62
55 // static 63 // static
56 std::unique_ptr<NavigationThrottle> 64 std::unique_ptr<NavigationThrottle>
57 ClearSiteDataThrottle::CreateThrottleForNavigation(NavigationHandle* handle) { 65 ClearSiteDataThrottle::CreateThrottleForNavigation(NavigationHandle* handle) {
58 if (AreExperimentalFeaturesEnabled()) 66 if (AreExperimentalFeaturesEnabled())
59 return base::WrapUnique(new ClearSiteDataThrottle(handle)); 67 return base::WrapUnique(new ClearSiteDataThrottle(handle));
60 68
61 return std::unique_ptr<NavigationThrottle>(); 69 return std::unique_ptr<NavigationThrottle>();
62 } 70 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 139
132 bool clear_cookies; 140 bool clear_cookies;
133 bool clear_storage; 141 bool clear_storage;
134 bool clear_cache; 142 bool clear_cache;
135 143
136 if (!ParseHeader(header_value, &clear_cookies, &clear_storage, &clear_cache, 144 if (!ParseHeader(header_value, &clear_cookies, &clear_storage, &clear_cache,
137 &messages_)) { 145 &messages_)) {
138 return; 146 return;
139 } 147 }
140 148
149 // Record the call parameters.
150 UMA_HISTOGRAM_ENUMERATION(
151 "Navigation.ClearSiteData.Parameters",
152 ParametersMask(clear_cookies, clear_storage, clear_cache), (1 << 3));
153
141 // If the header is valid, clear the data for this browser context and origin. 154 // If the header is valid, clear the data for this browser context and origin.
142 BrowserContext* browser_context = 155 BrowserContext* browser_context =
143 navigation_handle()->GetWebContents()->GetBrowserContext(); 156 navigation_handle()->GetWebContents()->GetBrowserContext();
144 url::Origin origin(current_url_); 157 url::Origin origin(current_url_);
145 158
146 if (origin.unique()) { 159 if (origin.unique()) {
147 ConsoleLog(&messages_, current_url_, "Not supported for unique origins.", 160 ConsoleLog(&messages_, current_url_, "Not supported for unique origins.",
148 CONSOLE_MESSAGE_LEVEL_ERROR); 161 CONSOLE_MESSAGE_LEVEL_ERROR);
149 return; 162 return;
150 } 163 }
151 164
152 clearing_in_progress_ = true; 165 clearing_in_progress_ = true;
166 clearing_started_ = base::TimeTicks::Now();
153 GetContentClient()->browser()->ClearSiteData( 167 GetContentClient()->browser()->ClearSiteData(
154 browser_context, origin, clear_cookies, clear_storage, clear_cache, 168 browser_context, origin, clear_cookies, clear_storage, clear_cache,
155 base::Bind(&ClearSiteDataThrottle::TaskFinished, 169 base::Bind(&ClearSiteDataThrottle::TaskFinished,
156 weak_ptr_factory_.GetWeakPtr())); 170 weak_ptr_factory_.GetWeakPtr()));
157 } 171 }
158 172
159 bool ClearSiteDataThrottle::ParseHeader(const std::string& header, 173 bool ClearSiteDataThrottle::ParseHeader(const std::string& header,
160 bool* clear_cookies, 174 bool* clear_cookies,
161 bool* clear_storage, 175 bool* clear_storage,
162 bool* clear_cache, 176 bool* clear_cache,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 NOTREACHED(); 263 NOTREACHED();
250 } 264 }
251 ConsoleLog(messages, current_url_, output, CONSOLE_MESSAGE_LEVEL_LOG); 265 ConsoleLog(messages, current_url_, output, CONSOLE_MESSAGE_LEVEL_LOG);
252 266
253 return true; 267 return true;
254 } 268 }
255 269
256 void ClearSiteDataThrottle::TaskFinished() { 270 void ClearSiteDataThrottle::TaskFinished() {
257 DCHECK(clearing_in_progress_); 271 DCHECK(clearing_in_progress_);
258 clearing_in_progress_ = false; 272 clearing_in_progress_ = false;
273
274 UMA_HISTOGRAM_CUSTOM_TIMES("Navigation.ClearSiteData.Duration",
275 base::TimeTicks::Now() - clearing_started_,
276 base::TimeDelta::FromMilliseconds(1),
277 base::TimeDelta::FromSeconds(1), 50);
278
259 navigation_handle()->Resume(); 279 navigation_handle()->Resume();
260 } 280 }
261 281
262 } // namespace content 282 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browsing_data/clear_site_data_throttle.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698