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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 226 |
227 std::vector<arc::ArcProcess> arc_processes; | 227 std::vector<arc::ArcProcess> arc_processes; |
228 arc_processes.emplace_back(1, 10, "focused", arc::mojom::ProcessState::TOP, | 228 arc_processes.emplace_back(1, 10, "focused", arc::mojom::ProcessState::TOP, |
229 kIsFocused, 100); | 229 kIsFocused, 100); |
230 arc_processes.emplace_back(2, 20, "visible1", arc::mojom::ProcessState::TOP, | 230 arc_processes.emplace_back(2, 20, "visible1", arc::mojom::ProcessState::TOP, |
231 kNotFocused, 200); | 231 kNotFocused, 200); |
232 arc_processes.emplace_back( | 232 arc_processes.emplace_back( |
233 3, 30, "service", arc::mojom::ProcessState::SERVICE, kNotFocused, 500); | 233 3, 30, "service", arc::mojom::ProcessState::SERVICE, kNotFocused, 500); |
234 arc_processes.emplace_back(4, 40, "visible2", arc::mojom::ProcessState::TOP, | 234 arc_processes.emplace_back(4, 40, "visible2", arc::mojom::ProcessState::TOP, |
235 kNotFocused, 150); | 235 kNotFocused, 150); |
| 236 arc_processes.emplace_back(5, 50, "persistent", |
| 237 arc::mojom::ProcessState::PERSISTENT, kNotFocused, |
| 238 600); |
| 239 arc_processes.emplace_back(6, 60, "persistent_ui", |
| 240 arc::mojom::ProcessState::PERSISTENT_UI, |
| 241 kNotFocused, 700); |
236 | 242 |
237 TabStats tab1, tab2, tab3, tab4, tab5; | 243 TabStats tab1, tab2, tab3, tab4, tab5; |
238 tab1.is_pinned = true; | 244 tab1.is_pinned = true; |
239 tab1.renderer_handle = 11; | 245 tab1.renderer_handle = 11; |
240 | 246 |
241 tab2.is_internal_page = true; | 247 tab2.is_internal_page = true; |
242 tab2.renderer_handle = 11; | 248 tab2.renderer_handle = 11; |
243 | 249 |
244 tab3.is_pinned = true; | 250 tab3.is_pinned = true; |
245 tab3.is_media = true; | 251 tab3.is_media = true; |
246 tab3.renderer_handle = 12; | 252 tab3.renderer_handle = 12; |
247 | 253 |
248 tab4.is_media = true; | 254 tab4.is_media = true; |
249 tab4.renderer_handle = 12; | 255 tab4.renderer_handle = 12; |
250 | 256 |
251 tab5.is_app = true; | 257 tab5.is_app = true; |
252 tab5.renderer_handle = 12; | 258 tab5.renderer_handle = 12; |
253 TabStatsList tab_list = {tab1, tab2, tab3, tab4, tab5}; | 259 TabStatsList tab_list = {tab1, tab2, tab3, tab4, tab5}; |
254 | 260 |
255 // Sorted order: | 261 // Sorted order (by GetSortedCandidates): |
256 // app "focused" pid: 10 | 262 // app "focused" pid: 10 |
257 // app "visible1" pid: 20 | 263 // app "persistent" pid: 50 |
258 // app "visible2" pid: 40 | 264 // app "persistent_ui" pid: 60 |
259 // tab3 pid: 12 | 265 // app "visible1" pid: 20 |
260 // tab4 pid: 12 | 266 // app "visible2" pid: 40 |
261 // tab1 pid: 11 | 267 // tab3 pid: 12 |
262 // tab5 pid: 12 | 268 // tab4 pid: 12 |
263 // tab2 pid: 11 | 269 // tab1 pid: 11 |
264 // app "service" pid: 30 | 270 // tab5 pid: 12 |
| 271 // tab2 pid: 11 |
| 272 // app "service" pid: 30 |
265 tab_manager_delegate.AdjustOomPrioritiesImpl(tab_list, arc_processes); | 273 tab_manager_delegate.AdjustOomPrioritiesImpl(tab_list, arc_processes); |
266 auto& oom_score_map = tab_manager_delegate.oom_score_map_; | 274 auto& oom_score_map = tab_manager_delegate.oom_score_map_; |
267 | 275 |
268 EXPECT_EQ(6U, oom_score_map.size()); | 276 // 6 PIDs for apps + 2 PIDs for tabs. |
| 277 EXPECT_EQ(6U + 2U, oom_score_map.size()); |
| 278 |
| 279 // Non-killable part. AdjustOomPrioritiesImpl() does make a focused app/tab |
| 280 // kernel-killable, but does not do that for PERSISTENT and PERSISTENT_UI |
| 281 // apps. |
| 282 EXPECT_EQ(TabManagerDelegate::kLowestOomScore, oom_score_map[50]); |
| 283 EXPECT_EQ(TabManagerDelegate::kLowestOomScore, oom_score_map[60]); |
269 | 284 |
270 // Higher priority part. | 285 // Higher priority part. |
271 EXPECT_EQ(300, oom_score_map[10]); | 286 EXPECT_EQ(300, oom_score_map[10]); |
272 EXPECT_EQ(344, oom_score_map[20]); | 287 EXPECT_EQ(344, oom_score_map[20]); |
273 EXPECT_EQ(388, oom_score_map[40]); | 288 EXPECT_EQ(388, oom_score_map[40]); |
274 EXPECT_EQ(431, oom_score_map[12]); | 289 EXPECT_EQ(431, oom_score_map[12]); |
275 EXPECT_EQ(475, oom_score_map[11]); | 290 EXPECT_EQ(475, oom_score_map[11]); |
276 | 291 |
277 // Lower priority part. | 292 // Lower priority part. |
278 EXPECT_EQ(650, oom_score_map[30]); | 293 EXPECT_EQ(650, oom_score_map[30]); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 arc_processes.emplace_back(2, 20, "visible1", arc::mojom::ProcessState::TOP, | 376 arc_processes.emplace_back(2, 20, "visible1", arc::mojom::ProcessState::TOP, |
362 kNotFocused, 200); | 377 kNotFocused, 200); |
363 arc_processes.emplace_back( | 378 arc_processes.emplace_back( |
364 3, 30, "service", arc::mojom::ProcessState::SERVICE, kNotFocused, 500); | 379 3, 30, "service", arc::mojom::ProcessState::SERVICE, kNotFocused, 500); |
365 arc_processes.emplace_back(4, 40, "visible2", | 380 arc_processes.emplace_back(4, 40, "visible2", |
366 arc::mojom::ProcessState::IMPORTANT_FOREGROUND, | 381 arc::mojom::ProcessState::IMPORTANT_FOREGROUND, |
367 kNotFocused, 150); | 382 kNotFocused, 150); |
368 arc_processes.emplace_back(5, 50, "not-visible", | 383 arc_processes.emplace_back(5, 50, "not-visible", |
369 arc::mojom::ProcessState::IMPORTANT_BACKGROUND, | 384 arc::mojom::ProcessState::IMPORTANT_BACKGROUND, |
370 kNotFocused, 300); | 385 kNotFocused, 300); |
| 386 arc_processes.emplace_back(6, 60, "persistent", |
| 387 arc::mojom::ProcessState::PERSISTENT, kNotFocused, |
| 388 400); |
371 | 389 |
372 TabStats tab1, tab2, tab3, tab4, tab5; | 390 TabStats tab1, tab2, tab3, tab4, tab5; |
373 tab1.is_pinned = true; | 391 tab1.is_pinned = true; |
374 tab1.renderer_handle = 11; | 392 tab1.renderer_handle = 11; |
375 tab1.tab_contents_id = 1; | 393 tab1.tab_contents_id = 1; |
376 | 394 |
377 tab2.is_internal_page = true; | 395 tab2.is_internal_page = true; |
378 tab2.renderer_handle = 11; | 396 tab2.renderer_handle = 11; |
379 tab2.tab_contents_id = 2; | 397 tab2.tab_contents_id = 2; |
380 | 398 |
381 tab3.is_pinned = true; | 399 tab3.is_pinned = true; |
382 tab3.is_media = true; | 400 tab3.is_media = true; |
383 tab3.renderer_handle = 12; | 401 tab3.renderer_handle = 12; |
384 tab3.tab_contents_id = 3; | 402 tab3.tab_contents_id = 3; |
385 | 403 |
386 tab4.is_media = true; | 404 tab4.is_media = true; |
387 tab4.renderer_handle = 12; | 405 tab4.renderer_handle = 12; |
388 tab4.tab_contents_id = 4; | 406 tab4.tab_contents_id = 4; |
389 | 407 |
390 tab5.is_app = true; | 408 tab5.is_app = true; |
391 tab5.renderer_handle = 12; | 409 tab5.renderer_handle = 12; |
392 tab5.tab_contents_id = 5; | 410 tab5.tab_contents_id = 5; |
393 TabStatsList tab_list = {tab1, tab2, tab3, tab4, tab5}; | 411 TabStatsList tab_list = {tab1, tab2, tab3, tab4, tab5}; |
394 | 412 |
395 // Sorted order: | 413 // Sorted order (by GetSortedCandidates): |
396 // app "focused" pid: 10 nspid 1 | 414 // app "focused" pid: 10 nspid 1 |
| 415 // app "persistent" pid: 60 nspid 6 |
397 // app "visible1" pid: 20 nspid 2 | 416 // app "visible1" pid: 20 nspid 2 |
398 // app "visible2" pid: 40 nspid 4 | 417 // app "visible2" pid: 40 nspid 4 |
399 // tab3 pid: 12 tab_contents_id 3 | 418 // tab3 pid: 12 tab_contents_id 3 |
400 // tab4 pid: 12 tab_contents_id 4 | 419 // tab4 pid: 12 tab_contents_id 4 |
401 // tab1 pid: 11 tab_contents_id 1 | 420 // tab1 pid: 11 tab_contents_id 1 |
402 // tab5 pid: 12 tab_contents_id 5 | 421 // tab5 pid: 12 tab_contents_id 5 |
403 // tab2 pid: 11 tab_contents_id 2 | 422 // tab2 pid: 11 tab_contents_id 2 |
404 // app "not-visible" pid: 50 nspid 5 | 423 // app "not-visible" pid: 50 nspid 5 |
405 // app "service" pid: 30 nspid 3 | 424 // app "service" pid: 30 nspid 3 |
406 memory_stat->SetTargetMemoryToFreeKB(250000); | 425 memory_stat->SetTargetMemoryToFreeKB(250000); |
407 // Entities to be killed. | 426 // Entities to be killed. |
408 memory_stat->SetProcessPss(30, 10000); | 427 memory_stat->SetProcessPss(30, 10000); |
409 memory_stat->SetProcessPss(50, 5000); | 428 memory_stat->SetProcessPss(50, 5000); |
410 memory_stat->SetProcessPss(11, 200000); | 429 memory_stat->SetProcessPss(11, 200000); |
411 memory_stat->SetProcessPss(12, 30000); | 430 memory_stat->SetProcessPss(12, 30000); |
412 // Should not be used. | 431 // Should not be used. |
| 432 memory_stat->SetProcessPss(60, 500000); |
413 memory_stat->SetProcessPss(40, 50000); | 433 memory_stat->SetProcessPss(40, 50000); |
414 memory_stat->SetProcessPss(20, 30000); | 434 memory_stat->SetProcessPss(20, 30000); |
415 memory_stat->SetProcessPss(10, 100000); | 435 memory_stat->SetProcessPss(10, 100000); |
416 | 436 |
417 tab_manager_delegate.LowMemoryKillImpl(tab_list, arc_processes); | 437 tab_manager_delegate.LowMemoryKillImpl(tab_list, arc_processes); |
418 | 438 |
419 auto killed_arc_processes = tab_manager_delegate.GetKilledArcProcesses(); | 439 auto killed_arc_processes = tab_manager_delegate.GetKilledArcProcesses(); |
420 auto killed_tabs = tab_manager_delegate.GetKilledTabs(); | 440 auto killed_tabs = tab_manager_delegate.GetKilledTabs(); |
421 | 441 |
422 // Killed apps and their nspid. | 442 // Killed apps and their nspid. |
(...skipping 10 matching lines...) Expand all Loading... |
433 | 453 |
434 // Check that killed apps are in the map. | 454 // Check that killed apps are in the map. |
435 const TabManagerDelegate::KilledArcProcessesMap& processes_map = | 455 const TabManagerDelegate::KilledArcProcessesMap& processes_map = |
436 tab_manager_delegate.recently_killed_arc_processes_; | 456 tab_manager_delegate.recently_killed_arc_processes_; |
437 EXPECT_EQ(2U, processes_map.size()); | 457 EXPECT_EQ(2U, processes_map.size()); |
438 EXPECT_EQ(1U, processes_map.count("service")); | 458 EXPECT_EQ(1U, processes_map.count("service")); |
439 EXPECT_EQ(1U, processes_map.count("not-visible")); | 459 EXPECT_EQ(1U, processes_map.count("not-visible")); |
440 } | 460 } |
441 | 461 |
442 } // namespace memory | 462 } // namespace memory |
OLD | NEW |