1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/web_resource/eula_accepted_notifier.h"
8 #include "base/logging.h"
9 #include "base/prefs/pref_service.h"
10 #include "components/web_resource/web_resource_pref_names.h"
12 namespace web_resource
{
14 EulaAcceptedNotifier::EulaAcceptedNotifier(PrefService
* local_state
)
15 : local_state_(local_state
), observer_(nullptr) {
18 EulaAcceptedNotifier::~EulaAcceptedNotifier() {
21 void EulaAcceptedNotifier::Init(Observer
* observer
) {
22 DCHECK(!observer_
&& observer
);
26 bool EulaAcceptedNotifier::IsEulaAccepted() {
27 if (local_state_
->GetBoolean(prefs::kEulaAccepted
))
30 // Register for the notification, if this is the first time.
31 if (registrar_
.IsEmpty()) {
32 registrar_
.Init(local_state_
);
33 registrar_
.Add(prefs::kEulaAccepted
,
34 base::Bind(&EulaAcceptedNotifier::OnPrefChanged
,
35 base::Unretained(this)));
41 EulaAcceptedNotifier
* EulaAcceptedNotifier::Create(PrefService
* local_state
) {
42 // First run EULA only exists on ChromeOS, Android and iOS. On ChromeOS, it is
43 // only shown in official builds.
44 #if (defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)) || \
45 defined(OS_ANDROID) || defined(OS_IOS)
46 // Tests that use higher-level classes that use EulaAcceptNotifier may not
47 // have local state or may not register this pref. Return null to indicate not
48 // needing to check the EULA.
49 if (!local_state
|| !local_state
->FindPreference(prefs::kEulaAccepted
))
51 return new EulaAcceptedNotifier(local_state
);
57 void EulaAcceptedNotifier::NotifyObserver() {
58 observer_
->OnEulaAccepted();
61 void EulaAcceptedNotifier::OnPrefChanged() {
62 DCHECK(!registrar_
.IsEmpty());
63 registrar_
.RemoveAll();
65 DCHECK(local_state_
->GetBoolean(prefs::kEulaAccepted
));
66 observer_
->OnEulaAccepted();
69 } // namespace web_resource