Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / web_resource / eula_accepted_notifier.cc
blob58bd7d783a510e74361df5f224ccf1d7e9aac1e0
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 "chrome/browser/web_resource/eula_accepted_notifier.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/common/pref_names.h"
13 EulaAcceptedNotifier::EulaAcceptedNotifier(PrefService* local_state)
14 : local_state_(local_state), observer_(NULL) {
17 EulaAcceptedNotifier::~EulaAcceptedNotifier() {
20 void EulaAcceptedNotifier::Init(Observer* observer) {
21 DCHECK(!observer_ && observer);
22 observer_ = observer;
25 bool EulaAcceptedNotifier::IsEulaAccepted() {
26 if (local_state_->GetBoolean(prefs::kEulaAccepted))
27 return true;
29 // Register for the notification, if this is the first time.
30 if (registrar_.IsEmpty()) {
31 registrar_.Init(local_state_);
32 registrar_.Add(prefs::kEulaAccepted,
33 base::Bind(&EulaAcceptedNotifier::OnPrefChanged,
34 base::Unretained(this)));
36 return false;
39 // static
40 EulaAcceptedNotifier* EulaAcceptedNotifier::Create() {
41 // First run EULA only exists on ChromeOS, Android and iOS. On ChromeOS, it is
42 // only shown in official builds.
43 #if (defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)) || \
44 defined(OS_ANDROID) || defined(OS_IOS)
45 PrefService* local_state = g_browser_process->local_state();
46 // Tests that use higher-level classes that use EulaAcceptNotifier may not
47 // register this pref. In this case, return NULL which is equivalent to not
48 // needing to check the EULA.
49 if (local_state->FindPreference(prefs::kEulaAccepted) == NULL)
50 return NULL;
51 return new EulaAcceptedNotifier(local_state);
52 #else
53 return NULL;
54 #endif
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();