File: mobile_data_notifications.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (92 lines) | stat: -rw-r--r-- 3,747 bytes parent folder | download | duplicates (7)
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
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_ASH_NETWORK_MOBILE_DATA_NOTIFICATIONS_H_
#define CHROME_BROWSER_UI_ASH_NETWORK_MOBILE_DATA_NOTIFICATIONS_H_

#include <memory>
#include <vector>

#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "base/timer/timer.h"
#include "chromeos/ash/components/network/network_connection_observer.h"
#include "chromeos/ash/components/network/network_state_handler.h"
#include "chromeos/ash/components/network/network_state_handler_observer.h"
#include "components/session_manager/core/session_manager_observer.h"
#include "components/user_manager/user_manager.h"

namespace user_manager {
class User;
}

// This class is responsible for triggering a one-time (per user) mobile data
// usage warning notification.
// Shows notification to authenticated users with unlocked screen
// while cellular is the default network and there are no other network
// connection requests.
// Connection status could change before the default network is updated. We
// could run into situations where notifications are shown even though default
// network is about to change to  a non-cellular network. We introduce a delay
// in operations that we think might run into this issue.
class MobileDataNotifications
    : public ash::NetworkStateHandlerObserver,
      public ash::NetworkConnectionObserver,
      public user_manager::UserManager::UserSessionStateObserver,
      public session_manager::SessionManagerObserver {
 public:
  MobileDataNotifications();

  MobileDataNotifications(const MobileDataNotifications&) = delete;
  MobileDataNotifications& operator=(const MobileDataNotifications&) = delete;

  ~MobileDataNotifications() override;

  // NetworkStateHandlerObserver:
  void ActiveNetworksChanged(
      const std::vector<const ash::NetworkState*>& active_networks) override;
  void OnShuttingDown() override;

  // NetworkConnectionObserver:
  void ConnectSucceeded(const std::string& service_path) override;
  void ConnectFailed(const std::string& service_path,
                     const std::string& error_name) override;

  // UserSessionStateObserver:
  void ActiveUserChanged(user_manager::User* active_user) override;

  // SessionManagerObserver:
  void OnSessionStateChanged() override;

 private:
  // Requests the active networks and calls
  // ShowOptionalMobileDataNotificationImpl.
  void ShowOptionalMobileDataNotification();

  // Displays a mobile data warning notification if all conditions are met:
  // * Cellular is the default network.
  // * User is authenticated with unlocked screen.
  // * There are no pending connection requests (Prevent flaky network switches
  //   from triggering the notification).
  // * First time notification is shown according to user prefs.
  void ShowOptionalMobileDataNotificationImpl(
      const std::vector<const ash::NetworkState*>& active_networks);

  // Adds a delay before calling |ShowOptionalMobileDataNotification|. Delay is
  // introduced because in some cases we might be notified through an observer
  // of an update that is not fully propagated to other parts of the
  // system. Checks performed in |ShowOptionalMobileDataNotification| might
  // accidentally pass.
  void DelayedShowOptionalMobileDataNotification();

  base::OneShotTimer one_shot_notification_check_delay_;

  base::ScopedObservation<ash::NetworkStateHandler,
                          ash::NetworkStateHandlerObserver>
      network_state_handler_observer_{this};

  base::WeakPtrFactory<MobileDataNotifications> weak_factory_{this};
};

#endif  // CHROME_BROWSER_UI_ASH_NETWORK_MOBILE_DATA_NOTIFICATIONS_H_