| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 if (!ash::Shell::HasInstance()) | 65 if (!ash::Shell::HasInstance()) |
| 66 return nullptr; | 66 return nullptr; |
| 67 return aura::client::GetActivationClient(ash::Shell::GetPrimaryRootWindow()); | 67 return aura::client::GetActivationClient(ash::Shell::GetPrimaryRootWindow()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Checks if a window renders ARC apps. | 70 // Checks if a window renders ARC apps. |
| 71 bool IsArcWindow(aura::Window* window) { | 71 bool IsArcWindow(aura::Window* window) { |
| 72 if (!window || window->name() != kExoShellSurfaceWindowName) | 72 if (!window || window->name() != kExoShellSurfaceWindowName) |
| 73 return false; | 73 return false; |
| 74 std::string application_id = exo::ShellSurface::GetApplicationId(window); | 74 std::string application_id = exo::ShellSurface::GetApplicationId(window); |
| 75 return application_id.find(kArcProcessNamePrefix) == 0; | 75 return base::StartsWith(application_id, kArcProcessNamePrefix, |
| 76 base::CompareCase::SENSITIVE); |
| 76 } | 77 } |
| 77 | 78 |
| 78 bool IsArcWindowInForeground() { | 79 bool IsArcWindowInForeground() { |
| 79 auto activation_client = GetActivationClient(); | 80 auto activation_client = GetActivationClient(); |
| 80 return activation_client && IsArcWindow(activation_client->GetActiveWindow()); | 81 return activation_client && IsArcWindow(activation_client->GetActiveWindow()); |
| 81 } | 82 } |
| 82 | 83 |
| 83 int AppStateToPriority( | 84 int AppStateToPriority( |
| 84 const arc::mojom::ProcessState& process_state) { | 85 const arc::mojom::ProcessState& process_state) { |
| 85 // Logic copied from Android: | 86 // Logic copied from Android: |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 int TabManagerDelegate::MemoryStat::EstimatedMemoryFreedKB( | 278 int TabManagerDelegate::MemoryStat::EstimatedMemoryFreedKB( |
| 278 base::ProcessHandle pid) { | 279 base::ProcessHandle pid) { |
| 279 std::unique_ptr<base::ProcessMetrics> process_metrics( | 280 std::unique_ptr<base::ProcessMetrics> process_metrics( |
| 280 base::ProcessMetrics::CreateProcessMetrics(pid)); | 281 base::ProcessMetrics::CreateProcessMetrics(pid)); |
| 281 base::WorkingSetKBytes mem_usage; | 282 base::WorkingSetKBytes mem_usage; |
| 282 process_metrics->GetWorkingSetKBytes(&mem_usage); | 283 process_metrics->GetWorkingSetKBytes(&mem_usage); |
| 283 return mem_usage.priv; | 284 return mem_usage.priv; |
| 284 } | 285 } |
| 285 | 286 |
| 286 class TabManagerDelegate::UmaReporter { | 287 class TabManagerDelegate::UmaReporter { |
| 287 public: | 288 public: |
| 288 UmaReporter() | 289 UmaReporter() : total_kills_(0) {} |
| 289 : last_kill_time_(), total_kills_(0) {} | 290 ~UmaReporter() {} |
| 290 ~UmaReporter() {} | |
| 291 void ReportKill(const int memory_freed); | |
| 292 | 291 |
| 293 private: | 292 void ReportKill(const int memory_freed); |
| 294 base::Time last_kill_time_; | 293 |
| 295 int total_kills_; | 294 private: |
| 295 base::Time last_kill_time_; |
| 296 int total_kills_; |
| 296 }; | 297 }; |
| 297 | 298 |
| 298 void TabManagerDelegate::UmaReporter::ReportKill(const int memory_freed) { | 299 void TabManagerDelegate::UmaReporter::ReportKill(const int memory_freed) { |
| 299 base::Time now = base::Time::Now(); | 300 base::Time now = base::Time::Now(); |
| 300 const TimeDelta time_delta = | 301 const TimeDelta time_delta = |
| 301 last_kill_time_.is_null() ? | 302 last_kill_time_.is_null() ? |
| 302 TimeDelta::FromSeconds(arc::kMaxOomMemoryKillTimeDeltaSecs) : | 303 TimeDelta::FromSeconds(arc::kMaxOomMemoryKillTimeDeltaSecs) : |
| 303 (now - last_kill_time_); | 304 (now - last_kill_time_); |
| 304 UMA_HISTOGRAM_OOM_KILL_TIME_INTERVAL( | 305 UMA_HISTOGRAM_OOM_KILL_TIME_INTERVAL( |
| 305 "Arc.LowMemoryKiller.TimeDelta", time_delta); | 306 "Arc.LowMemoryKiller.TimeDelta", time_delta); |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 } | 817 } |
| 817 } | 818 } |
| 818 priority += priority_increment; | 819 priority += priority_increment; |
| 819 } | 820 } |
| 820 | 821 |
| 821 if (oom_score_for_tabs.size()) | 822 if (oom_score_for_tabs.size()) |
| 822 SetOomScoreAdjForTabs(oom_score_for_tabs); | 823 SetOomScoreAdjForTabs(oom_score_for_tabs); |
| 823 } | 824 } |
| 824 | 825 |
| 825 } // namespace memory | 826 } // namespace memory |
| OLD | NEW |