| 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 "ios/chrome/browser/metrics/tab_usage_recorder.h" | 5 #include "ios/chrome/browser/metrics/tab_usage_recorder.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "ios/chrome/browser/chrome_url_constants.h" | 8 #include "ios/chrome/browser/chrome_url_constants.h" |
| 9 #import "ios/chrome/browser/metrics/previous_session_info.h" | 9 #import "ios/chrome/browser/metrics/previous_session_info.h" |
| 10 #import "ios/chrome/browser/tabs/tab.h" | 10 #import "ios/chrome/browser/tabs/tab.h" |
| 11 #import "ios/web/public/navigation_item.h" |
| 12 #import "ios/web/public/navigation_manager.h" |
| 13 #import "ios/web/public/web_state/web_state.h" |
| 11 #import "ios/web/web_state/ui/crw_web_controller.h" | 14 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 12 | 15 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
| 15 #endif | 18 #endif |
| 16 | 19 |
| 17 const char kTabUsageHistogramPrefix[] = "Tab"; | 20 const char kTabUsageHistogramPrefix[] = "Tab"; |
| 18 | 21 |
| 19 // The histogram recording the state of the tab the user switches to. | 22 // The histogram recording the state of the tab the user switches to. |
| 20 const char kSelectedTabHistogramName[] = | 23 const char kSelectedTabHistogramName[] = |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 294 |
| 292 void TabUsageRecorder::ResetEvictedTab() { | 295 void TabUsageRecorder::ResetEvictedTab() { |
| 293 evicted_tab_ = NULL; | 296 evicted_tab_ = NULL; |
| 294 evicted_tab_state_ = IN_MEMORY; | 297 evicted_tab_state_ = IN_MEMORY; |
| 295 evicted_tab_reload_start_time_ = base::TimeTicks(); | 298 evicted_tab_reload_start_time_ = base::TimeTicks(); |
| 296 } | 299 } |
| 297 | 300 |
| 298 bool TabUsageRecorder::ShouldIgnoreTab(Tab* tab) { | 301 bool TabUsageRecorder::ShouldIgnoreTab(Tab* tab) { |
| 299 // Do not count chrome:// urls to avoid data noise. For example, if they were | 302 // Do not count chrome:// urls to avoid data noise. For example, if they were |
| 300 // counted, every new tab created would add noise to the page load count. | 303 // counted, every new tab created would add noise to the page load count. |
| 301 return [tab url].SchemeIs(kChromeUIScheme); | 304 web::NavigationItem* pending_item = |
| 305 tab.webState->GetNavigationManager()->GetPendingItem(); |
| 306 if (pending_item) |
| 307 return pending_item->GetURL().SchemeIs(kChromeUIScheme); |
| 308 return tab.lastCommittedURL.SchemeIs(kChromeUIScheme); |
| 302 } | 309 } |
| 303 | 310 |
| 304 bool TabUsageRecorder::TabAlreadyEvicted(Tab* tab) { | 311 bool TabUsageRecorder::TabAlreadyEvicted(Tab* tab) { |
| 305 base::WeakNSObject<Tab> weak_tab(tab); | 312 base::WeakNSObject<Tab> weak_tab(tab); |
| 306 auto tab_item = evicted_tabs_.find(weak_tab); | 313 auto tab_item = evicted_tabs_.find(weak_tab); |
| 307 return tab_item != evicted_tabs_.end(); | 314 return tab_item != evicted_tabs_.end(); |
| 308 } | 315 } |
| 309 | 316 |
| 310 TabUsageRecorder::TabStateWhenSelected TabUsageRecorder::ExtractTabState( | 317 TabUsageRecorder::TabStateWhenSelected TabUsageRecorder::ExtractTabState( |
| 311 Tab* tab) { | 318 Tab* tab) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 331 } | 338 } |
| 332 | 339 |
| 333 void TabUsageRecorder::ClearDeletedTabs() { | 340 void TabUsageRecorder::ClearDeletedTabs() { |
| 334 base::WeakNSObject<Tab> empty_tab(nil); | 341 base::WeakNSObject<Tab> empty_tab(nil); |
| 335 auto tab_item = evicted_tabs_.find(empty_tab); | 342 auto tab_item = evicted_tabs_.find(empty_tab); |
| 336 while (tab_item != evicted_tabs_.end()) { | 343 while (tab_item != evicted_tabs_.end()) { |
| 337 evicted_tabs_.erase(empty_tab); | 344 evicted_tabs_.erase(empty_tab); |
| 338 tab_item = evicted_tabs_.find(empty_tab); | 345 tab_item = evicted_tabs_.find(empty_tab); |
| 339 } | 346 } |
| 340 } | 347 } |
| OLD | NEW |