File: lock_screen_profile_creator.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 (86 lines) | stat: -rw-r--r-- 3,181 bytes parent folder | download | duplicates (4)
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
// 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_LOCK_SCREEN_PROFILE_CREATOR_H_
#define CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_LOCK_SCREEN_PROFILE_CREATOR_H_

#include <list>

#include "base/callback_forward.h"
#include "base/macros.h"

class Profile;

namespace lock_screen_apps {

// Abstract class to be used to create the lock screen apps profile - the
// profile used for launching/running lock screen enabled apps.
class LockScreenProfileCreator {
 public:
  LockScreenProfileCreator();
  virtual ~LockScreenProfileCreator();

  // Initializes the creator - it marks the object as initialized and calls
  // |InitializeImpl|, a function that should be override to provide actual
  // initialization logic. After this, the |LockScreenProfileCreator|
  // implementation should be allowed to create lock screen profile.
  void Initialize();

  // Adds a closure that should be called when the lock screen profile provided
  // by the class is created. If the profile is alredy created at the time this
  // is called, |callback| will be run immediately.
  void AddCreateProfileCallback(base::OnceClosure callback);

  // Whether the |LockScreenProfileCreator| has been initialized.
  bool Initialized() const;

  // Whether the |LockScreenProfileCreator| finished profile creation, and the
  // created, if any, profile can be retrieved using |lock_screen_profile()|.
  // Note that |lock_screen_profile| might be null even if |ProfileCreated|
  // returns true - in case the profile creation failed.
  bool ProfileCreated() const;

  Profile* lock_screen_profile() const { return lock_screen_profile_; }

 protected:
  // Should be overriden to provide initialization logic - the
  // |LockScreenProfileCreator| instance should be put in state where it can
  // determine whether the lock screen profile should be created and start
  // profile creation when appropriate.
  // For example, the class instance might start observing lock screen note
  // taking availability, and start profile creation when a lock screen note
  // taking app is available.
  virtual void InitializeImpl() = 0;

  // Should be called by the implementation to indicate profile creation has
  // started.
  void OnLockScreenProfileCreateStarted();

  // Should be called by the implementation to finish profile creation - to
  // set |lock_screen_profile_| and run profile creation callbacks.
  void OnLockScreenProfileCreated(Profile* lock_screen_profile);

 private:
  enum class State {
    kNotInitialized,
    kInitialized,
    kCreatingProfile,
    kProfileCreated
  };

  // The current profile  creator state.
  State state_ = State::kNotInitialized;

  // The lock screen profile created by this, set when the profile creation
  // finishes.
  Profile* lock_screen_profile_ = nullptr;

  std::list<base::OnceClosure> create_profile_callbacks_;

  DISALLOW_COPY_AND_ASSIGN(LockScreenProfileCreator);
};

}  // namespace lock_screen_apps

#endif  // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_LOCK_SCREEN_PROFILE_CREATOR_H_