Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/arc/boot_phase_monitor/arc_instance_throttle.h " | |
| 6 | |
| 7 #include "ash/common/wm_shell.h" | |
| 8 #include "ash/common/wm_window.h" | |
| 9 #include "ash/shared/app_types.h" | |
| 10 #include "base/bind.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 13 #include "chromeos/dbus/session_manager_client.h" | |
| 14 | |
| 15 namespace arc { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 void OnDBusReply(bool is_prioritize, bool success) { | |
| 20 if (success) | |
| 21 return; | |
| 22 const char* message = is_prioritize ? "unprioritize" : "prioritize"; | |
| 23 LOG(WARNING) << "Failed to " << message << " the instance"; | |
| 24 } | |
| 25 | |
| 26 bool IsArcAppWindow(ash::WmWindow* active) { | |
| 27 return active->GetAppType() == static_cast<int>(ash::AppType::ARC_APP); | |
| 28 } | |
| 29 | |
| 30 void ThrottleInstanceIfNeeded(ash::WmWindow* active) { | |
| 31 chromeos::SessionManagerClient* session_manager_client = | |
| 32 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | |
| 33 if (!session_manager_client) { | |
| 34 LOG(WARNING) << "SessionManagerClient is not available"; | |
| 35 return; | |
| 36 } | |
| 37 if (!active || !IsArcAppWindow(active)) { | |
| 38 // TODO(yusukes): Call session_manager_client->UnprioritizeArcInstance() | |
|
Yusuke Sato
2017/01/10 22:19:27
It's under review at https://chromium-review.googl
| |
| 39 // once it's ready. | |
| 40 } else { | |
| 41 session_manager_client->PrioritizeArcInstance( | |
| 42 base::Bind(OnDBusReply, true)); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 48 ArcInstanceThrottle::ArcInstanceThrottle() { | |
| 49 ash::WmShell* shell = ash::WmShell::Get(); | |
| 50 DCHECK(shell); | |
| 51 shell->AddActivationObserver(this); | |
| 52 ThrottleInstanceIfNeeded(shell->GetActiveWindow()); | |
| 53 } | |
| 54 | |
| 55 ArcInstanceThrottle::~ArcInstanceThrottle() { | |
| 56 ash::WmShell* shell = ash::WmShell::Get(); | |
| 57 if (shell) | |
| 58 shell->RemoveActivationObserver(this); | |
| 59 } | |
| 60 | |
| 61 void ArcInstanceThrottle::OnWindowActivated(ash::WmWindow* gained_active, | |
| 62 ash::WmWindow* lost_active) { | |
| 63 ThrottleInstanceIfNeeded(gained_active); | |
| 64 } | |
| 65 | |
| 66 } // namespace arc | |
| OLD | NEW |