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

Side by Side Diff: chrome/browser/memory/tab_manager.cc

Issue 2171123002: chrome/browser/memory: Change auto to not deduce raw pointers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/memory/tab_manager_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/tab_manager.h" 5 #include "chrome/browser/memory/tab_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 109 }
110 } 110 }
111 111
112 return -1; 112 return -1;
113 } 113 }
114 114
115 // A wrapper around base::MemoryPressureMonitor::GetCurrentPressureLevel. 115 // A wrapper around base::MemoryPressureMonitor::GetCurrentPressureLevel.
116 // TODO(chrisha): Move this do the default implementation of a delegate. 116 // TODO(chrisha): Move this do the default implementation of a delegate.
117 base::MemoryPressureListener::MemoryPressureLevel 117 base::MemoryPressureListener::MemoryPressureLevel
118 GetCurrentPressureLevel() { 118 GetCurrentPressureLevel() {
119 auto monitor = base::MemoryPressureMonitor::Get(); 119 auto* monitor = base::MemoryPressureMonitor::Get();
120 if (monitor) 120 if (monitor)
121 return monitor->GetCurrentPressureLevel(); 121 return monitor->GetCurrentPressureLevel();
122 return base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE; 122 return base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE;
123 } 123 }
124 124
125 // A wrapper to content::SendPressureNotification that doesn't have overloaded 125 // A wrapper to content::SendPressureNotification that doesn't have overloaded
126 // type ambiguity. Makes use of Bind easier. 126 // type ambiguity. Makes use of Bind easier.
127 // TODO(chrisha): Move this do the default implementation of a delegate. 127 // TODO(chrisha): Move this do the default implementation of a delegate.
128 void NotifyRendererProcess( 128 void NotifyRendererProcess(
129 const content::RenderProcessHost* render_process_host, 129 const content::RenderProcessHost* render_process_host,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 auto tab_stats = GetTabStats(); 236 auto tab_stats = GetTabStats();
237 237
238 std::vector<content::RenderProcessHost*> sorted_renderers; 238 std::vector<content::RenderProcessHost*> sorted_renderers;
239 std::set<content::RenderProcessHost*> seen_renderers; 239 std::set<content::RenderProcessHost*> seen_renderers;
240 std::set<content::RenderProcessHost*> visible_renderers; 240 std::set<content::RenderProcessHost*> visible_renderers;
241 sorted_renderers.reserve(tab_stats.size()); 241 sorted_renderers.reserve(tab_stats.size());
242 242
243 // Convert the tab sort order to a process sort order. The process inherits 243 // Convert the tab sort order to a process sort order. The process inherits
244 // the priority of its highest priority tab. 244 // the priority of its highest priority tab.
245 for (auto& tab : tab_stats) { 245 for (auto& tab : tab_stats) {
246 auto renderer = tab.render_process_host; 246 auto* renderer = tab.render_process_host;
247 247
248 // Skip renderers associated with visible tabs as handling memory pressure 248 // Skip renderers associated with visible tabs as handling memory pressure
249 // notifications in these processes can cause jank. This code works because 249 // notifications in these processes can cause jank. This code works because
250 // visible tabs always come first in |tab_stats|. 250 // visible tabs always come first in |tab_stats|.
251 if (tab.is_selected) { 251 if (tab.is_selected) {
252 visible_renderers.insert(renderer); 252 visible_renderers.insert(renderer);
253 continue; 253 continue;
254 } 254 }
255 if (visible_renderers.count(renderer) > 0) 255 if (visible_renderers.count(renderer) > 0)
256 continue; 256 continue;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 307
308 void TabManager::set_test_tick_clock(base::TickClock* test_tick_clock) { 308 void TabManager::set_test_tick_clock(base::TickClock* test_tick_clock) {
309 test_tick_clock_ = test_tick_clock; 309 test_tick_clock_ = test_tick_clock;
310 } 310 }
311 311
312 void TabManager::TabChangedAt(content::WebContents* contents, 312 void TabManager::TabChangedAt(content::WebContents* contents,
313 int index, 313 int index,
314 TabChangeType change_type) { 314 TabChangeType change_type) {
315 if (change_type != TabChangeType::ALL) 315 if (change_type != TabChangeType::ALL)
316 return; 316 return;
317 auto data = GetWebContentsData(contents); 317 auto* data = GetWebContentsData(contents);
318 bool old_state = data->IsRecentlyAudible(); 318 bool old_state = data->IsRecentlyAudible();
319 bool current_state = contents->WasRecentlyAudible(); 319 bool current_state = contents->WasRecentlyAudible();
320 if (old_state != current_state) { 320 if (old_state != current_state) {
321 data->SetRecentlyAudible(current_state); 321 data->SetRecentlyAudible(current_state);
322 data->SetLastAudioChangeTime(NowTicks()); 322 data->SetLastAudioChangeTime(NowTicks());
323 } 323 }
324 } 324 }
325 325
326 void TabManager::ActiveTabChanged(content::WebContents* old_contents, 326 void TabManager::ActiveTabChanged(content::WebContents* old_contents,
327 content::WebContents* new_contents, 327 content::WebContents* new_contents,
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 return true; 714 return true;
715 } 715 }
716 716
717 auto delta = NowTicks() - GetWebContentsData(contents)->LastAudioChangeTime(); 717 auto delta = NowTicks() - GetWebContentsData(contents)->LastAudioChangeTime();
718 return delta < TimeDelta::FromSeconds(kAudioProtectionTimeSeconds); 718 return delta < TimeDelta::FromSeconds(kAudioProtectionTimeSeconds);
719 } 719 }
720 720
721 TabManager::WebContentsData* TabManager::GetWebContentsData( 721 TabManager::WebContentsData* TabManager::GetWebContentsData(
722 content::WebContents* contents) const { 722 content::WebContents* contents) const {
723 WebContentsData::CreateForWebContents(contents); 723 WebContentsData::CreateForWebContents(contents);
724 auto web_contents_data = WebContentsData::FromWebContents(contents); 724 auto* web_contents_data = WebContentsData::FromWebContents(contents);
725 web_contents_data->set_test_tick_clock(test_tick_clock_); 725 web_contents_data->set_test_tick_clock(test_tick_clock_);
726 return web_contents_data; 726 return web_contents_data;
727 } 727 }
728 728
729 // static 729 // static
730 bool TabManager::CompareTabStats(const TabStats& first, 730 bool TabManager::CompareTabStats(const TabStats& first,
731 const TabStats& second) { 731 const TabStats& second) {
732 // Being currently selected is most important to protect. 732 // Being currently selected is most important to protect.
733 if (first.is_selected != second.is_selected) 733 if (first.is_selected != second.is_selected)
734 return first.is_selected; 734 return first.is_selected;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 bool TabManager::IsTabAutoDiscardable(content::WebContents* contents) const { 925 bool TabManager::IsTabAutoDiscardable(content::WebContents* contents) const {
926 return GetWebContentsData(contents)->IsAutoDiscardable(); 926 return GetWebContentsData(contents)->IsAutoDiscardable();
927 } 927 }
928 928
929 void TabManager::SetTabAutoDiscardableState(content::WebContents* contents, 929 void TabManager::SetTabAutoDiscardableState(content::WebContents* contents,
930 bool state) { 930 bool state) {
931 GetWebContentsData(contents)->SetAutoDiscardableState(state); 931 GetWebContentsData(contents)->SetAutoDiscardableState(state);
932 } 932 }
933 933
934 } // namespace memory 934 } // namespace memory
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/memory/tab_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698