OLD | NEW |
---|---|
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.h" | |
Ilya Sherman
2016/08/24 22:27:56
nit: Please #include histogram_macros instead.
msramek
2016/08/25 08:56:09
Done.
| |
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 Loading... | |
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( | |
56 bool clear_cookies, bool clear_storage, bool clear_cache) { | |
57 return static_cast<int>(clear_cookies) * (1 << 0) + | |
58 static_cast<int>(clear_storage) * (1 << 1) + | |
59 static_cast<int>(clear_cache) * (1 << 2); | |
60 } | |
61 | |
53 } // namespace | 62 } // namespace |
54 | 63 |
55 // static | 64 // static |
56 std::unique_ptr<NavigationThrottle> | 65 std::unique_ptr<NavigationThrottle> |
57 ClearSiteDataThrottle::CreateThrottleForNavigation(NavigationHandle* handle) { | 66 ClearSiteDataThrottle::CreateThrottleForNavigation(NavigationHandle* handle) { |
58 if (AreExperimentalFeaturesEnabled()) | 67 if (AreExperimentalFeaturesEnabled()) |
59 return base::WrapUnique(new ClearSiteDataThrottle(handle)); | 68 return base::WrapUnique(new ClearSiteDataThrottle(handle)); |
60 | 69 |
61 return std::unique_ptr<NavigationThrottle>(); | 70 return std::unique_ptr<NavigationThrottle>(); |
62 } | 71 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 | 140 |
132 bool clear_cookies; | 141 bool clear_cookies; |
133 bool clear_storage; | 142 bool clear_storage; |
134 bool clear_cache; | 143 bool clear_cache; |
135 | 144 |
136 if (!ParseHeader(header_value, &clear_cookies, &clear_storage, &clear_cache, | 145 if (!ParseHeader(header_value, &clear_cookies, &clear_storage, &clear_cache, |
137 &messages_)) { | 146 &messages_)) { |
138 return; | 147 return; |
139 } | 148 } |
140 | 149 |
150 // Record the call parameters. | |
151 UMA_HISTOGRAM_ENUMERATION( | |
152 "Navigation.ClearSiteData.Parameters", | |
153 ParametersMask(clear_cookies, clear_storage, clear_cache), (1 << 3)); | |
154 | |
141 // If the header is valid, clear the data for this browser context and origin. | 155 // If the header is valid, clear the data for this browser context and origin. |
142 BrowserContext* browser_context = | 156 BrowserContext* browser_context = |
143 navigation_handle()->GetWebContents()->GetBrowserContext(); | 157 navigation_handle()->GetWebContents()->GetBrowserContext(); |
144 url::Origin origin(current_url_); | 158 url::Origin origin(current_url_); |
145 | 159 |
146 if (origin.unique()) { | 160 if (origin.unique()) { |
147 ConsoleLog(&messages_, current_url_, "Not supported for unique origins.", | 161 ConsoleLog(&messages_, current_url_, "Not supported for unique origins.", |
148 CONSOLE_MESSAGE_LEVEL_ERROR); | 162 CONSOLE_MESSAGE_LEVEL_ERROR); |
149 return; | 163 return; |
150 } | 164 } |
151 | 165 |
152 clearing_in_progress_ = true; | 166 clearing_in_progress_ = true; |
167 clearing_started_ = base::TimeTicks::Now(); | |
153 GetContentClient()->browser()->ClearSiteData( | 168 GetContentClient()->browser()->ClearSiteData( |
154 browser_context, origin, clear_cookies, clear_storage, clear_cache, | 169 browser_context, origin, clear_cookies, clear_storage, clear_cache, |
155 base::Bind(&ClearSiteDataThrottle::TaskFinished, | 170 base::Bind(&ClearSiteDataThrottle::TaskFinished, |
156 weak_ptr_factory_.GetWeakPtr())); | 171 weak_ptr_factory_.GetWeakPtr())); |
157 } | 172 } |
158 | 173 |
159 bool ClearSiteDataThrottle::ParseHeader(const std::string& header, | 174 bool ClearSiteDataThrottle::ParseHeader(const std::string& header, |
160 bool* clear_cookies, | 175 bool* clear_cookies, |
161 bool* clear_storage, | 176 bool* clear_storage, |
162 bool* clear_cache, | 177 bool* clear_cache, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 NOTREACHED(); | 264 NOTREACHED(); |
250 } | 265 } |
251 ConsoleLog(messages, current_url_, output, CONSOLE_MESSAGE_LEVEL_LOG); | 266 ConsoleLog(messages, current_url_, output, CONSOLE_MESSAGE_LEVEL_LOG); |
252 | 267 |
253 return true; | 268 return true; |
254 } | 269 } |
255 | 270 |
256 void ClearSiteDataThrottle::TaskFinished() { | 271 void ClearSiteDataThrottle::TaskFinished() { |
257 DCHECK(clearing_in_progress_); | 272 DCHECK(clearing_in_progress_); |
258 clearing_in_progress_ = false; | 273 clearing_in_progress_ = false; |
274 | |
275 UMA_HISTOGRAM_TIMES("Navigation.ClearSiteData.Duration", | |
276 base::TimeTicks::Now() - clearing_started_); | |
Ilya Sherman
2016/08/24 22:27:56
Do you have a guess for roughly how long a "typica
clamy
2016/08/24 23:15:01
IIUC, you're blocking the navigation during the ti
msramek
2016/08/25 08:56:09
Clearing browsing data *can* potentially take a lo
clamy
2016/08/25 17:53:47
The median Page Load Time on Android is 2.5s right
msramek
2016/08/25 18:39:44
I lowered it to 50 buckets per 1 second. That's 20
| |
277 | |
259 navigation_handle()->Resume(); | 278 navigation_handle()->Resume(); |
260 } | 279 } |
261 | 280 |
262 } // namespace content | 281 } // namespace content |
OLD | NEW |