summaryrefslogtreecommitdiffstats
path: root/components/web_resource/eula_accepted_notifier.h
blob: 552b53ca048f0407296acdd5a5f6cffee9524c31 (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
// Copyright 2013 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 COMPONENTS_WEB_RESOURCE_EULA_ACCEPTED_NOTIFIER_H_
#define COMPONENTS_WEB_RESOURCE_EULA_ACCEPTED_NOTIFIER_H_

#include "base/basictypes.h"
#include "base/prefs/pref_change_registrar.h"

class PrefService;

namespace web_resource {

// Helper class for querying the EULA accepted state and receiving a
// notification when the EULA is accepted.
class EulaAcceptedNotifier {
 public:
  // Observes EULA accepted state changes.
  class Observer {
   public:
    virtual void OnEulaAccepted() = 0;
  };

  explicit EulaAcceptedNotifier(PrefService* local_state);
  virtual ~EulaAcceptedNotifier();

  // Initializes this class with the given |observer|. Must be called before
  // the class is used.
  void Init(Observer* observer);

  // Returns true if the EULA has been accepted. If the EULA has not yet been
  // accepted, begins monitoring the EULA state and will notify the observer
  // once the EULA has been accepted.
  virtual bool IsEulaAccepted();

  // Factory method for this class.
  static EulaAcceptedNotifier* Create(PrefService* local_state);

 protected:
  // Notifies the observer that the EULA has been updated, made protected for
  // testing.
  void NotifyObserver();

 private:
  // Callback for EULA accepted pref change notification.
  void OnPrefChanged();

  // Local state pref service for querying the EULA accepted pref.
  PrefService* local_state_;

  // Used to listen for the EULA accepted pref change notification.
  PrefChangeRegistrar registrar_;

  // Observer of the EULA accepted notification.
  Observer* observer_;

  DISALLOW_COPY_AND_ASSIGN(EulaAcceptedNotifier);
};

}  // namespace web_resource

#endif  // COMPONENTS_WEB_RESOURCE_EULA_ACCEPTED_NOTIFIER_H_