| OLD | NEW |
| 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_delegate_chromeos.h" | 5 #include "chrome/browser/memory/tab_manager_delegate_chromeos.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // Instantiate the mock instance. | 238 // Instantiate the mock instance. |
| 239 MockTabManagerDelegate tab_manager_delegate(memory_stat); | 239 MockTabManagerDelegate tab_manager_delegate(memory_stat); |
| 240 | 240 |
| 241 std::vector<arc::ArcProcess> arc_processes; | 241 std::vector<arc::ArcProcess> arc_processes; |
| 242 arc_processes.emplace_back(1, 10, "focused", arc::mojom::ProcessState::TOP, | 242 arc_processes.emplace_back(1, 10, "focused", arc::mojom::ProcessState::TOP, |
| 243 kIsFocused, 100); | 243 kIsFocused, 100); |
| 244 arc_processes.emplace_back(2, 20, "visible1", arc::mojom::ProcessState::TOP, | 244 arc_processes.emplace_back(2, 20, "visible1", arc::mojom::ProcessState::TOP, |
| 245 kNotFocused, 200); | 245 kNotFocused, 200); |
| 246 arc_processes.emplace_back( | 246 arc_processes.emplace_back( |
| 247 3, 30, "service", arc::mojom::ProcessState::SERVICE, kNotFocused, 500); | 247 3, 30, "service", arc::mojom::ProcessState::SERVICE, kNotFocused, 500); |
| 248 arc_processes.emplace_back(4, 40, "visible2", arc::mojom::ProcessState::TOP, | 248 arc_processes.emplace_back(4, 40, "visible2", |
| 249 arc::mojom::ProcessState::IMPORTANT_FOREGROUND, |
| 249 kNotFocused, 150); | 250 kNotFocused, 150); |
| 251 arc_processes.emplace_back(5, 50, "not-visible", |
| 252 arc::mojom::ProcessState::IMPORTANT_BACKGROUND, |
| 253 kNotFocused, 300); |
| 250 | 254 |
| 251 TabStats tab1, tab2, tab3, tab4, tab5; | 255 TabStats tab1, tab2, tab3, tab4, tab5; |
| 252 tab1.is_pinned = true; | 256 tab1.is_pinned = true; |
| 253 tab1.renderer_handle = 11; | 257 tab1.renderer_handle = 11; |
| 254 tab1.tab_contents_id = 1; | 258 tab1.tab_contents_id = 1; |
| 255 | 259 |
| 256 tab2.is_internal_page = true; | 260 tab2.is_internal_page = true; |
| 257 tab2.renderer_handle = 11; | 261 tab2.renderer_handle = 11; |
| 258 tab2.tab_contents_id = 2; | 262 tab2.tab_contents_id = 2; |
| 259 | 263 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 273 | 277 |
| 274 // Sorted order: | 278 // Sorted order: |
| 275 // app "focused" pid: 10 nspid 1 | 279 // app "focused" pid: 10 nspid 1 |
| 276 // app "visible1" pid: 20 nspid 2 | 280 // app "visible1" pid: 20 nspid 2 |
| 277 // app "visible2" pid: 40 nspid 4 | 281 // app "visible2" pid: 40 nspid 4 |
| 278 // tab3 pid: 12 tab_contents_id 3 | 282 // tab3 pid: 12 tab_contents_id 3 |
| 279 // tab4 pid: 12 tab_contents_id 4 | 283 // tab4 pid: 12 tab_contents_id 4 |
| 280 // tab1 pid: 11 tab_contents_id 1 | 284 // tab1 pid: 11 tab_contents_id 1 |
| 281 // tab5 pid: 12 tab_contents_id 5 | 285 // tab5 pid: 12 tab_contents_id 5 |
| 282 // tab2 pid: 11 tab_contents_id 2 | 286 // tab2 pid: 11 tab_contents_id 2 |
| 287 // app "not-visible" pid: 50 nspid 5 |
| 283 // app "service" pid: 30 nspid 3 | 288 // app "service" pid: 30 nspid 3 |
| 284 memory_stat->SetTargetMemoryToFreeKB(250000); | 289 memory_stat->SetTargetMemoryToFreeKB(250000); |
| 285 // Entities to be killed. | 290 // Entities to be killed. |
| 286 memory_stat->SetProcessPss(30, 10000); | 291 memory_stat->SetProcessPss(30, 10000); |
| 292 memory_stat->SetProcessPss(50, 5000); |
| 287 memory_stat->SetProcessPss(11, 200000); | 293 memory_stat->SetProcessPss(11, 200000); |
| 288 memory_stat->SetProcessPss(12, 30000); | 294 memory_stat->SetProcessPss(12, 30000); |
| 289 // Should not be used. | 295 // Should not be used. |
| 290 memory_stat->SetProcessPss(40, 50000); | 296 memory_stat->SetProcessPss(40, 50000); |
| 291 memory_stat->SetProcessPss(20, 30000); | 297 memory_stat->SetProcessPss(20, 30000); |
| 292 memory_stat->SetProcessPss(10, 100000); | 298 memory_stat->SetProcessPss(10, 100000); |
| 293 | 299 |
| 294 tab_manager_delegate.LowMemoryKillImpl(tab_list, arc_processes); | 300 tab_manager_delegate.LowMemoryKillImpl(tab_list, arc_processes); |
| 295 | 301 |
| 296 auto killed_arc_processes = tab_manager_delegate.GetKilledArcProcesses(); | 302 auto killed_arc_processes = tab_manager_delegate.GetKilledArcProcesses(); |
| 297 auto killed_tabs = tab_manager_delegate.GetKilledTabs(); | 303 auto killed_tabs = tab_manager_delegate.GetKilledTabs(); |
| 298 | 304 |
| 299 // Killed apps and their nspid. | 305 // Killed apps and their nspid. |
| 300 EXPECT_EQ(1U, killed_arc_processes.size()); | 306 ASSERT_EQ(2U, killed_arc_processes.size()); |
| 301 EXPECT_EQ(3, killed_arc_processes[0]); | 307 EXPECT_EQ(3, killed_arc_processes[0]); |
| 308 EXPECT_EQ(5, killed_arc_processes[1]); |
| 302 // Killed tabs and their content id. | 309 // Killed tabs and their content id. |
| 303 // Note that process with pid 11 is counted twice. But so far I don't have a | 310 // Note that process with pid 11 is counted twice. But so far I don't have a |
| 304 // good way to estimate the memory freed if multiple tabs share one process. | 311 // good way to estimate the memory freed if multiple tabs share one process. |
| 305 EXPECT_EQ(3U, killed_tabs.size()); | 312 ASSERT_EQ(3U, killed_tabs.size()); |
| 306 EXPECT_EQ(2, killed_tabs[0]); | 313 EXPECT_EQ(2, killed_tabs[0]); |
| 307 EXPECT_EQ(5, killed_tabs[1]); | 314 EXPECT_EQ(5, killed_tabs[1]); |
| 308 EXPECT_EQ(1, killed_tabs[2]); | 315 EXPECT_EQ(1, killed_tabs[2]); |
| 309 } | 316 } |
| 310 | 317 |
| 311 } // namespace memory | 318 } // namespace memory |
| OLD | NEW |