File: first_app_run_toast_manager.h

package info (click to toggle)
chromium 90.0.4430.212-1~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,450,632 kB
  • sloc: cpp: 19,832,434; javascript: 2,948,838; ansic: 2,312,399; python: 1,464,622; xml: 584,121; java: 514,189; asm: 470,557; objc: 83,463; perl: 77,861; sh: 77,030; cs: 70,789; fortran: 24,137; tcl: 18,916; php: 18,872; makefile: 16,848; ruby: 16,721; pascal: 13,150; sql: 10,199; yacc: 7,507; lex: 1,313; lisp: 840; awk: 329; jsp: 39; sed: 19
file content (92 lines) | stat: -rw-r--r-- 3,446 bytes parent folder | download | duplicates (2)
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 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_FIRST_APP_RUN_TOAST_MANAGER_H_
#define CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_FIRST_APP_RUN_TOAST_MANAGER_H_

#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"

class Profile;

namespace extensions {
class AppWindow;
}

namespace lock_screen_apps {

// Manager that can be used on a lock screen note app to show a first run
// dialog informing the user about the app that's been launched from the lock
// screen.
class FirstAppRunToastManager : public extensions::AppWindowRegistry::Observer,
                                public views::WidgetObserver {
 public:
  explicit FirstAppRunToastManager(Profile* profile);
  ~FirstAppRunToastManager() override;

  // Runs the manager for an app window launch. It determines whether the first
  // lock screen run dialog for the app associated with the app window has been
  // previously shown to the user (this information is kept in the user prefs).
  // If the dialog has not yet been shown (and confirmed by the user), the
  // manager will show the dialog once the app window becomes visible.
  void RunForAppWindow(extensions::AppWindow* app_window);

  // Resets current manager state - if a first run dialog is being shown, this
  // method will close the dialog.
  void Reset();

  // views::WidgetObserver:
  void OnWidgetDestroyed(views::Widget* widget) override;

  // extensions::AppWindowRegistry::Observer:
  void OnAppWindowActivated(extensions::AppWindow* app_window) override;

  views::Widget* widget() { return toast_widget_; }

 private:
  // Creates and shows the first lock screen app dialog for the app associated
  // with |app_window_|.
  void CreateAndShowToastDialog();

  // Called when the user closes the first app run dialog, and thus unblocks
  // lock screen app UI.
  // The manager will mark the first run dialog as handled for the app.
  void ToastDialogDismissed();

  // Adjust toast dialog's bounds relative to the bounds of the app window for
  // which the toast dialog is shown - the dialog position is
  //  * horizontally - centered
  //  * vertically - at the bottom, with additional vertical offset (so a
  //        portion of the dialog is rendered outside the app window bounds).
  void AdjustToastWidgetBounds();

  Profile* const profile_;

  // If set, the app window for which the manager is being run.
  extensions::AppWindow* app_window_ = nullptr;

  // The widget associated with the first run dialog, if the dialog is shown.
  views::Widget* toast_widget_ = nullptr;

  ScopedObserver<views::Widget, views::WidgetObserver> toast_widget_observer_{
      this};
  ScopedObserver<extensions::AppWindowRegistry,
                 extensions::AppWindowRegistry::Observer>
      app_window_observer_{this};

  class AppWidgetObserver;
  std::unique_ptr<AppWidgetObserver> app_widget_observer_;

  base::WeakPtrFactory<FirstAppRunToastManager> weak_ptr_factory_{this};

  DISALLOW_COPY_AND_ASSIGN(FirstAppRunToastManager);
};

}  // namespace lock_screen_apps

#endif  // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_FIRST_APP_RUN_TOAST_MANAGER_H_