OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/chromeos/arc/boot_phase_monitor/arc_instance_throttle.h
" | 5 #include "chrome/browser/chromeos/arc/boot_phase_monitor/arc_instance_throttle.h
" |
6 | 6 |
7 #include "ash/shared/app_types.h" | |
8 #include "ash/shell.h" | 7 #include "ash/shell.h" |
9 #include "ash/wm/window_util.h" | 8 #include "ash/wm/window_util.h" |
10 #include "ash/wm_window.h" | |
11 #include "base/bind.h" | 9 #include "base/bind.h" |
12 #include "base/logging.h" | 10 #include "base/logging.h" |
13 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
14 #include "chromeos/dbus/session_manager_client.h" | 12 #include "chromeos/dbus/session_manager_client.h" |
| 13 #include "components/arc/arc_util.h" |
15 #include "ui/wm/public/activation_client.h" | 14 #include "ui/wm/public/activation_client.h" |
16 | 15 |
17 namespace arc { | 16 namespace arc { |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 void OnDBusReply(login_manager::ContainerCpuRestrictionState state, | 20 void OnDBusReply(login_manager::ContainerCpuRestrictionState state, |
22 bool success) { | 21 bool success) { |
23 if (success) | 22 if (success) |
24 return; | 23 return; |
25 const char* message = | 24 const char* message = |
26 (state == login_manager::CONTAINER_CPU_RESTRICTION_BACKGROUND) | 25 (state == login_manager::CONTAINER_CPU_RESTRICTION_BACKGROUND) |
27 ? "unprioritize" | 26 ? "unprioritize" |
28 : "prioritize"; | 27 : "prioritize"; |
29 LOG(WARNING) << "Failed to " << message << " the instance"; | 28 LOG(WARNING) << "Failed to " << message << " the instance"; |
30 } | 29 } |
31 | 30 |
32 bool IsArcAppWindow(ash::WmWindow* active) { | 31 void ThrottleInstanceIfNeeded(aura::Window* active) { |
33 DCHECK(active); | |
34 return active->GetAppType() == static_cast<int>(ash::AppType::ARC_APP); | |
35 } | |
36 | |
37 void ThrottleInstanceIfNeeded(ash::WmWindow* active) { | |
38 chromeos::SessionManagerClient* session_manager_client = | 32 chromeos::SessionManagerClient* session_manager_client = |
39 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 33 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
40 if (!session_manager_client) { | 34 if (!session_manager_client) { |
41 LOG(WARNING) << "SessionManagerClient is not available"; | 35 LOG(WARNING) << "SessionManagerClient is not available"; |
42 return; | 36 return; |
43 } | 37 } |
44 const login_manager::ContainerCpuRestrictionState state = | 38 const login_manager::ContainerCpuRestrictionState state = |
45 (!active || !IsArcAppWindow(active)) | 39 !IsArcAppWindow(active) |
46 ? login_manager::CONTAINER_CPU_RESTRICTION_BACKGROUND | 40 ? login_manager::CONTAINER_CPU_RESTRICTION_BACKGROUND |
47 : login_manager::CONTAINER_CPU_RESTRICTION_FOREGROUND; | 41 : login_manager::CONTAINER_CPU_RESTRICTION_FOREGROUND; |
48 session_manager_client->SetArcCpuRestriction(state, | 42 session_manager_client->SetArcCpuRestriction(state, |
49 base::Bind(OnDBusReply, state)); | 43 base::Bind(OnDBusReply, state)); |
50 } | 44 } |
51 | 45 |
52 } // namespace | 46 } // namespace |
53 | 47 |
54 ArcInstanceThrottle::ArcInstanceThrottle() { | 48 ArcInstanceThrottle::ArcInstanceThrottle() { |
55 ash::Shell::Get()->activation_client()->AddObserver(this); | 49 ash::Shell::Get()->activation_client()->AddObserver(this); |
56 ThrottleInstanceIfNeeded(ash::WmWindow::Get(ash::wm::GetActiveWindow())); | 50 ThrottleInstanceIfNeeded(ash::wm::GetActiveWindow()); |
57 } | 51 } |
58 | 52 |
59 ArcInstanceThrottle::~ArcInstanceThrottle() { | 53 ArcInstanceThrottle::~ArcInstanceThrottle() { |
60 if (ash::Shell::HasInstance()) | 54 if (ash::Shell::HasInstance()) |
61 ash::Shell::Get()->activation_client()->RemoveObserver(this); | 55 ash::Shell::Get()->activation_client()->RemoveObserver(this); |
62 } | 56 } |
63 | 57 |
64 void ArcInstanceThrottle::OnWindowActivated(ActivationReason reason, | 58 void ArcInstanceThrottle::OnWindowActivated(ActivationReason reason, |
65 aura::Window* gained_active, | 59 aura::Window* gained_active, |
66 aura::Window* lost_active) { | 60 aura::Window* lost_active) { |
67 ThrottleInstanceIfNeeded(ash::WmWindow::Get(gained_active)); | 61 ThrottleInstanceIfNeeded(gained_active); |
68 } | 62 } |
69 | 63 |
70 } // namespace arc | 64 } // namespace arc |
OLD | NEW |