OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/activity_log/uma_policy.h" | 5 #include "chrome/browser/extensions/activity_log/uma_policy.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/extensions/active_script_controller.h" | |
10 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" | 11 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" |
11 #include "chrome/browser/extensions/activity_log/ad_network_database.h" | 12 #include "chrome/browser/extensions/activity_log/ad_network_database.h" |
13 #include "chrome/browser/extensions/location_bar_controller.h" | |
14 #include "chrome/browser/extensions/tab_helper.h" | |
12 #include "chrome/browser/sessions/session_id.h" | 15 #include "chrome/browser/sessions/session_id.h" |
13 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
16 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
17 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
19 #include "extensions/common/dom_action_types.h" | 22 #include "extensions/common/dom_action_types.h" |
20 | 23 |
21 namespace extensions { | 24 namespace extensions { |
(...skipping 12 matching lines...) Expand all Loading... | |
34 const int kCreatedIframe = 1 << UmaPolicy::CREATED_IFRAME; | 37 const int kCreatedIframe = 1 << UmaPolicy::CREATED_IFRAME; |
35 const int kCreatedDiv = 1 << UmaPolicy::CREATED_DIV; | 38 const int kCreatedDiv = 1 << UmaPolicy::CREATED_DIV; |
36 const int kCreatedLink = 1 << UmaPolicy::CREATED_LINK; | 39 const int kCreatedLink = 1 << UmaPolicy::CREATED_LINK; |
37 const int kCreatedInput = 1 << UmaPolicy::CREATED_INPUT; | 40 const int kCreatedInput = 1 << UmaPolicy::CREATED_INPUT; |
38 const int kCreatedEmbed = 1 << UmaPolicy::CREATED_EMBED; | 41 const int kCreatedEmbed = 1 << UmaPolicy::CREATED_EMBED; |
39 const int kCreatedObject = 1 << UmaPolicy::CREATED_OBJECT; | 42 const int kCreatedObject = 1 << UmaPolicy::CREATED_OBJECT; |
40 const int kAdInjected = 1 << UmaPolicy::AD_INJECTED; | 43 const int kAdInjected = 1 << UmaPolicy::AD_INJECTED; |
41 const int kAdRemoved = 1 << UmaPolicy::AD_REMOVED; | 44 const int kAdRemoved = 1 << UmaPolicy::AD_REMOVED; |
42 const int kAdReplaced = 1 << UmaPolicy::AD_REPLACED; | 45 const int kAdReplaced = 1 << UmaPolicy::AD_REPLACED; |
43 | 46 |
47 // A mask of all the ad injection flags. | |
48 const int kAnyAdInjection = kAdInjected | kAdRemoved | kAdReplaced; | |
not at google - send to devlin
2014/05/07 22:49:02
how about kAnyAdActivity?
Devlin
2014/05/08 18:15:46
Sure.
| |
49 | |
44 } // namespace | 50 } // namespace |
45 | 51 |
46 // Class constants, also used in testing. -------------------------------------- | 52 // Class constants, also used in testing. -------------------------------------- |
47 | 53 |
48 const char UmaPolicy::kNumberOfTabs[] = "num_tabs"; | 54 const char UmaPolicy::kNumberOfTabs[] = "num_tabs"; |
49 const size_t UmaPolicy::kMaxTabsTracked = 50; | 55 const size_t UmaPolicy::kMaxTabsTracked = 50; |
50 | 56 |
51 // Setup and shutdown. --------------------------------------------------------- | 57 // Setup and shutdown. --------------------------------------------------------- |
52 | 58 |
53 UmaPolicy::UmaPolicy(Profile* profile) | 59 UmaPolicy::UmaPolicy(Profile* profile) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 break; | 163 break; |
158 case Action::NO_AD_INJECTION: | 164 case Action::NO_AD_INJECTION: |
159 break; | 165 break; |
160 case Action::NUM_INJECTION_TYPES: | 166 case Action::NUM_INJECTION_TYPES: |
161 NOTREACHED(); | 167 NOTREACHED(); |
162 }; | 168 }; |
163 | 169 |
164 return ret_bit; | 170 return ret_bit; |
165 } | 171 } |
166 | 172 |
167 void UmaPolicy::HistogramOnClose(const std::string& url) { | 173 void UmaPolicy::HistogramOnClose(const std::string& url, |
174 content::WebContents* web_contents) { | |
168 // Let's try to avoid histogramming useless URLs. | 175 // Let's try to avoid histogramming useless URLs. |
169 if (url.empty() || url == content::kAboutBlankURL || | 176 if (url.empty() || url == content::kAboutBlankURL || |
170 url == chrome::kChromeUINewTabURL) | 177 url == chrome::kChromeUINewTabURL) |
171 return; | 178 return; |
172 | 179 |
173 int statuses[MAX_STATUS - 1]; | 180 int statuses[MAX_STATUS - 1]; |
174 std::memset(statuses, 0, sizeof(statuses)); | 181 std::memset(statuses, 0, sizeof(statuses)); |
175 | 182 |
183 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); | |
184 ActiveScriptController* active_script_controller = | |
not at google - send to devlin
2014/05/07 22:49:02
maybe ActiveScriptController should be a WebConten
Devlin
2014/05/08 18:15:46
Talked about offline, and decided to keep current
| |
185 tab_helper && tab_helper->location_bar_controller() ? | |
186 tab_helper->location_bar_controller()->active_script_controller() : | |
187 NULL; | |
176 SiteMap::iterator site_lookup = url_status_.find(url); | 188 SiteMap::iterator site_lookup = url_status_.find(url); |
177 ExtensionMap exts = site_lookup->second; | 189 const ExtensionMap& exts = site_lookup->second; |
178 ExtensionMap::iterator ext_iter; | 190 for (ExtensionMap::const_iterator ext_iter = exts.begin(); |
179 for (ext_iter = exts.begin(); ext_iter != exts.end(); ++ext_iter) { | 191 ext_iter != exts.end(); |
192 ++ext_iter) { | |
180 if (ext_iter->first == kNumberOfTabs) | 193 if (ext_iter->first == kNumberOfTabs) |
181 continue; | 194 continue; |
182 for (int i = NONE + 1; i < MAX_STATUS; ++i) { | 195 for (int i = NONE + 1; i < MAX_STATUS; ++i) { |
183 if (ext_iter->second & (1 << i)) | 196 if (ext_iter->second & (1 << i)) |
184 statuses[i-1]++; | 197 statuses[i-1]++; |
185 } | 198 } |
199 | |
200 if ((ext_iter->second & kAnyAdInjection) && | |
201 active_script_controller) { | |
202 bool injection_could_have_been_stopped = | |
203 active_script_controller->HasActionForExtensionId(ext_iter->first); | |
204 UMA_HISTOGRAM_BOOLEAN( | |
205 "ExtensionActivity.AdInjectionCouldHaveBeenStopped", | |
206 injection_could_have_been_stopped); | |
207 } | |
186 } | 208 } |
187 | 209 |
188 std::string prefix = "ExtensionActivity."; | 210 std::string prefix = "ExtensionActivity."; |
189 if (GURL(url).host() != "www.google.com") { | 211 if (GURL(url).host() != "www.google.com") { |
190 UMA_HISTOGRAM_COUNTS_100(prefix + GetHistogramName(CONTENT_SCRIPT), | 212 UMA_HISTOGRAM_COUNTS_100(prefix + GetHistogramName(CONTENT_SCRIPT), |
191 statuses[CONTENT_SCRIPT - 1]); | 213 statuses[CONTENT_SCRIPT - 1]); |
192 UMA_HISTOGRAM_COUNTS_100(prefix + GetHistogramName(READ_DOM), | 214 UMA_HISTOGRAM_COUNTS_100(prefix + GetHistogramName(READ_DOM), |
193 statuses[READ_DOM - 1]); | 215 statuses[READ_DOM - 1]); |
194 UMA_HISTOGRAM_COUNTS_100(prefix + GetHistogramName(MODIFIED_DOM), | 216 UMA_HISTOGRAM_COUNTS_100(prefix + GetHistogramName(MODIFIED_DOM), |
195 statuses[MODIFIED_DOM - 1]); | 217 statuses[MODIFIED_DOM - 1]); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 int32 tab_id = SessionID::IdForTab(contents); | 307 int32 tab_id = SessionID::IdForTab(contents); |
286 | 308 |
287 std::map<int32, std::string>::iterator tab_it = tab_list_.find(tab_id); | 309 std::map<int32, std::string>::iterator tab_it = tab_list_.find(tab_id); |
288 | 310 |
289 // Ignore tabs that haven't changed status. | 311 // Ignore tabs that haven't changed status. |
290 if (tab_it != tab_list_.end() && tab_it->second == url) | 312 if (tab_it != tab_list_.end() && tab_it->second == url) |
291 return; | 313 return; |
292 | 314 |
293 // Is this an existing tab whose URL has changed. | 315 // Is this an existing tab whose URL has changed. |
294 if (tab_it != tab_list_.end()) { | 316 if (tab_it != tab_list_.end()) { |
295 CleanupClosedPage(tab_it->second); | 317 CleanupClosedPage(tab_it->second, contents); |
296 tab_list_.erase(tab_id); | 318 tab_list_.erase(tab_id); |
297 } | 319 } |
298 | 320 |
299 // Check that tab_list_ isn't over the kMaxTabsTracked budget. | 321 // Check that tab_list_ isn't over the kMaxTabsTracked budget. |
300 if (tab_list_.size() >= kMaxTabsTracked) | 322 if (tab_list_.size() >= kMaxTabsTracked) |
301 return; | 323 return; |
302 | 324 |
303 // Set up the new entries. | 325 // Set up the new entries. |
304 tab_list_[tab_id] = url; | 326 tab_list_[tab_id] = url; |
305 SetupOpenedPage(url); | 327 SetupOpenedPage(url); |
306 } | 328 } |
307 | 329 |
308 // Use the value from SessionID::IdForTab, *not* |index|. |index| will be | 330 // Use the value from SessionID::IdForTab, *not* |index|. |index| will be |
309 // duplicated across tabs in a session, whereas IdForTab uniquely identifies | 331 // duplicated across tabs in a session, whereas IdForTab uniquely identifies |
310 // each tab. | 332 // each tab. |
311 void UmaPolicy::TabClosingAt(TabStripModel* tab_strip_model, | 333 void UmaPolicy::TabClosingAt(TabStripModel* tab_strip_model, |
312 content::WebContents* contents, | 334 content::WebContents* contents, |
313 int index) { | 335 int index) { |
314 if (!contents) | 336 if (!contents) |
315 return; | 337 return; |
316 std::string url = CleanURL(contents->GetLastCommittedURL()); | 338 std::string url = CleanURL(contents->GetLastCommittedURL()); |
317 int32 tab_id = SessionID::IdForTab(contents); | 339 int32 tab_id = SessionID::IdForTab(contents); |
318 std::map<int, std::string>::iterator tab_it = tab_list_.find(tab_id); | 340 std::map<int, std::string>::iterator tab_it = tab_list_.find(tab_id); |
319 if (tab_it != tab_list_.end()) | 341 if (tab_it != tab_list_.end()) |
320 tab_list_.erase(tab_id); | 342 tab_list_.erase(tab_id); |
321 | 343 |
322 CleanupClosedPage(url); | 344 CleanupClosedPage(url, contents); |
323 } | 345 } |
324 | 346 |
325 void UmaPolicy::SetupOpenedPage(const std::string& url) { | 347 void UmaPolicy::SetupOpenedPage(const std::string& url) { |
326 url_status_[url][kNumberOfTabs]++; | 348 url_status_[url][kNumberOfTabs]++; |
327 } | 349 } |
328 | 350 |
329 void UmaPolicy::CleanupClosedPage(const std::string& url) { | 351 void UmaPolicy::CleanupClosedPage(const std::string& url, |
352 content::WebContents* web_contents) { | |
330 SiteMap::iterator old_site_lookup = url_status_.find(url); | 353 SiteMap::iterator old_site_lookup = url_status_.find(url); |
331 if (old_site_lookup == url_status_.end()) | 354 if (old_site_lookup == url_status_.end()) |
332 return; | 355 return; |
333 old_site_lookup->second[kNumberOfTabs]--; | 356 old_site_lookup->second[kNumberOfTabs]--; |
334 if (old_site_lookup->second[kNumberOfTabs] == 0) { | 357 if (old_site_lookup->second[kNumberOfTabs] == 0) { |
335 HistogramOnClose(url); | 358 HistogramOnClose(url, web_contents); |
336 url_status_.erase(url); | 359 url_status_.erase(url); |
337 } | 360 } |
338 } | 361 } |
339 | 362 |
340 // Helpers. -------------------------------------------------------------------- | 363 // Helpers. -------------------------------------------------------------------- |
341 | 364 |
342 // We don't want to treat # ref navigations as if they were new pageloads. | 365 // We don't want to treat # ref navigations as if they were new pageloads. |
343 // So we get rid of the ref if it has it. | 366 // So we get rid of the ref if it has it. |
344 // We convert to a string in the hopes that this is faster than Replacements. | 367 // We convert to a string in the hopes that this is faster than Replacements. |
345 std::string UmaPolicy::CleanURL(const GURL& gurl) { | 368 std::string UmaPolicy::CleanURL(const GURL& gurl) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 return "AdReplaced"; | 422 return "AdReplaced"; |
400 case NONE: | 423 case NONE: |
401 case MAX_STATUS: | 424 case MAX_STATUS: |
402 default: | 425 default: |
403 NOTREACHED(); | 426 NOTREACHED(); |
404 return ""; | 427 return ""; |
405 } | 428 } |
406 } | 429 } |
407 | 430 |
408 } // namespace extensions | 431 } // namespace extensions |
OLD | NEW |