File: remote_activity_notification_controller.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (103 lines) | stat: -rw-r--r-- 3,458 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/policy/remote_commands/crd/remote_activity_notification_controller.h"

#include <memory>

#include "ash/shell.h"
#include "base/check_deref.h"
#include "base/functional/bind.h"
#include "chrome/browser/ui/ash/login/login_display_host.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_member.h"
#include "components/prefs/pref_service.h"

namespace policy {

RemoteActivityNotificationController::RemoteActivityNotificationController(
    PrefService& local_state,
    base::RepeatingCallback<bool()> is_current_session_curtained)
    : is_current_session_curtained_(is_current_session_curtained) {
  observation_.Observe(session_manager::SessionManager::Get());

  remote_admin_was_present_.Init(
      prefs::kRemoteAdminWasPresent, &local_state,
      base::BindRepeating(&RemoteActivityNotificationController::
                              OnRemoteAdminWasPresentPrefChanged,
                          weak_ptr_factory_.GetWeakPtr()));
}

RemoteActivityNotificationController::~RemoteActivityNotificationController() =
    default;

// Buttons (like the one on the notification) do not correctly respond to
// on-click events if they are created before the login screen is properly
// initialized, so only create the notification once that's the case.
void RemoteActivityNotificationController::OnLoginOrLockScreenVisible() {
  if (remote_admin_was_present_.GetValue()) {
    notification_.Show();
  }
}

void RemoteActivityNotificationController::OnClientConnecting() {
  // The notification is meant for a local user not for the remote admin, so
  // hide it during a CRD connection so we don't annoy them. This also prevents
  // the notification from showing when the remote admin auto-reconnects after
  // a Chrome crash/restart.
  notification_.Hide();
}

void RemoteActivityNotificationController::OnClientConnected() {
  if (is_current_session_curtained_.Run()) {
    remote_admin_was_present_.SetValue(true);
  }
}

void RemoteActivityNotificationController::OnClientDisconnected() {
  // Show the notification once the remote admin disconnects.
  if (remote_admin_was_present_.GetValue()) {
    notification_.Show();
  }
}

void RemoteActivityNotificationController::
    OnRemoteAdminWasPresentPrefChanged() {
  if (!remote_admin_was_present_.GetValue()) {
    // Remember the notification was dismissed by the user.
    notification_.SetAsHidden();
  }

  if (is_current_session_curtained_.Run()) {
    // When the notification is dismissed from inside a curtained session
    // we must ensure the notification is shown again the next time.
    remote_admin_was_present_.SetValue(true);
  }
}

void RemoteActivityNotificationController::Notification::Show() {
  if (!is_showing_) {
    auto* default_host = ash::LoginDisplayHost::default_host();
    if (default_host) {
      default_host->ShowRemoteActivityNotificationScreen();
      is_showing_ = true;
    }
  }
}

void RemoteActivityNotificationController::Notification::Hide() {
  if (is_showing_) {
    auto* default_host = ash::LoginDisplayHost::default_host();
    if (default_host) {
      default_host->HideOobeDialog();
      is_showing_ = false;
    }
  }
}

void RemoteActivityNotificationController::Notification::SetAsHidden() {
  is_showing_ = false;
}

}  // namespace policy