summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/policy/consumer_management_notifier.h
blob: e107b7f0cfcd5d0b38d47e2ee5ae1cc20605002b (plain)
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
// Copyright 2014 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_POLICY_CONSUMER_MANAGEMENT_NOTIFIER_H_
#define CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_NOTIFIER_H_

#include <string>

#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/chromeos/policy/consumer_management_service.h"
#include "components/keyed_service/core/keyed_service.h"

class Profile;

namespace policy {

class ConsumerManagementStage;

// ConsumerManagementNotifier observes ConsumerManagementService and shows
// a desktop notification to the device owner if consumer enrollment or
// unenrollment suceeds or fails.
class ConsumerManagementNotifier
    : public KeyedService,
      public ConsumerManagementService::Observer {
 public:
  ConsumerManagementNotifier(
      Profile* profile,
      ConsumerManagementService* consumer_management_service);
  ~ConsumerManagementNotifier() override;

  void Shutdown() override;

  // ConsumerManagementService::Observer:
  void OnConsumerManagementStatusChanged() override;

 private:
  // Shows a notification based on |stage|.
  void ShowNotification(const ConsumerManagementStage& stage);

  // Shows a desktop notification.
  void ShowDesktopNotification(
      const std::string& notification_id,
      const std::string& notification_url,
      int title_message_id,
      int body_message_id,
      int button_label_message_id,
      const base::Closure& button_click_callback);

  // Opens the settings page.
  void OpenSettingsPage() const;

  // Opens the enrollment/unenrollment confirmation dialog in the settings page.
  void TryAgain() const;

  Profile* profile_;
  ConsumerManagementService* consumer_management_service_;

  base::WeakPtrFactory<ConsumerManagementNotifier> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(ConsumerManagementNotifier);
};

}  // namespace policy

#endif  // CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_NOTIFIER_H_