Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: chrome/browser/chromeos/arc/boot_phase_monitor/arc_instance_throttle.cc

Issue 2624513004: Prioritize ARC instance only when it is needed (Closed)
Patch Set: address comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 DCHECK(active);
28 return active->GetAppType() == static_cast<int>(ash::AppType::ARC_APP);
29 }
30
31 void ThrottleInstanceIfNeeded(ash::WmWindow* active) {
32 chromeos::SessionManagerClient* session_manager_client =
33 chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
34 if (!session_manager_client) {
35 LOG(WARNING) << "SessionManagerClient is not available";
36 return;
37 }
38 if (!active || !IsArcAppWindow(active)) {
39 // TODO(yusukes): Call session_manager_client->UnprioritizeArcInstance()
40 // once it's ready.
41 } else {
42 session_manager_client->PrioritizeArcInstance(
43 base::Bind(OnDBusReply, true));
44 }
45 }
46
47 } // namespace
48
49 ArcInstanceThrottle::ArcInstanceThrottle() {
50 ash::WmShell* shell = ash::WmShell::Get();
51 DCHECK(shell);
52 shell->AddActivationObserver(this);
53 ThrottleInstanceIfNeeded(shell->GetActiveWindow());
54 }
55
56 ArcInstanceThrottle::~ArcInstanceThrottle() {
57 ash::WmShell* shell = ash::WmShell::Get();
58 if (shell)
59 shell->RemoveActivationObserver(this);
60 }
61
62 void ArcInstanceThrottle::OnWindowActivated(ash::WmWindow* gained_active,
63 ash::WmWindow* lost_active) {
64 ThrottleInstanceIfNeeded(gained_active);
65 }
66
67 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/boot_phase_monitor/arc_instance_throttle.h ('k') | components/arc/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698