Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: chrome/browser/metrics/variations/eula_accepted_notifier_mobile.cc

Issue 16129004: Consolidate EulaAcceptedNotifier implementations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 #include "chrome/browser/metrics/variations/eula_accepted_notifier_mobile.h"
6
7 #include "base/bind.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/common/pref_names.h"
11
12 EulaAcceptedNotifierMobile::EulaAcceptedNotifierMobile(
13 PrefService* local_state)
14 : local_state_(local_state) {
15 }
16
17 EulaAcceptedNotifierMobile::~EulaAcceptedNotifierMobile() {
18 }
19
20 bool EulaAcceptedNotifierMobile::IsEulaAccepted() {
21 if (local_state_->GetBoolean(prefs::kEulaAccepted))
22 return true;
23
24 // Register for the notification, if this is the first time.
25 if (registrar_.IsEmpty()) {
26 registrar_.Init(local_state_);
27 registrar_.Add(prefs::kEulaAccepted,
28 base::Bind(&EulaAcceptedNotifierMobile::OnPrefChanged,
29 base::Unretained(this)));
30 }
31 return false;
32 }
33
34 void EulaAcceptedNotifierMobile::OnPrefChanged() {
35 DCHECK(!registrar_.IsEmpty());
36 registrar_.RemoveAll();
37
38 DCHECK(local_state_->GetBoolean(prefs::kEulaAccepted));
39 NotifyObserver();
40 }
41
42 // static
43 EulaAcceptedNotifier* EulaAcceptedNotifier::Create() {
44 PrefService* local_state = g_browser_process->local_state();
45 // If the |kEulaAccepted| pref is not registered, return NULL which is
46 // equivalent to not needing to check the EULA. This is the case for some
47 // tests for higher-level classes that use the EulaAcceptNotifier.
48 if (local_state->FindPreference(prefs::kEulaAccepted) == NULL)
49 return NULL;
50 return new EulaAcceptedNotifierMobile(local_state);
51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698