OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/metrics/variations/eula_accepted_notifier.h" | 5 #include "chrome/browser/metrics/variations/eula_accepted_notifier.h" |
6 | 6 |
7 #include "base/bind.h" | |
7 #include "base/logging.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" | |
8 | 12 |
9 EulaAcceptedNotifier::EulaAcceptedNotifier() : observer_(NULL) { | 13 // static |
14 EulaAcceptedNotifier* EulaAcceptedNotifier::Create() { | |
15 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS) | |
16 // First run EULA only exists on ChromeOS, Android and iOS. | |
17 return NULL; | |
18 #elif defined(OS_CHROMEOS) && !defined(GOOGLE_CHROME_BUILD) | |
19 // On ChromeOS, unofficial builds do not show the EULA, whereas on Android | |
20 // and iOS they do. | |
21 return NULL; | |
22 #else | |
SteveT
2013/05/31 12:20:08
Do you think it'd be cleaner if we did
#if (defin
Alexei Svitkine (slow)
2013/05/31 15:25:17
Done.
| |
23 PrefService* local_state = g_browser_process->local_state(); | |
24 // If the |kEulaAccepted| pref is not registered, return NULL which is | |
25 // equivalent to not needing to check the EULA. This is the case for some | |
26 // tests for higher-level classes that use the EulaAcceptNotifier. | |
SteveT
2013/05/31 12:20:08
To be a bit more clear in this comment, is the kEu
Alexei Svitkine (slow)
2013/05/31 15:25:17
Done.
| |
27 if (local_state->FindPreference(prefs::kEulaAccepted) == NULL) | |
28 return NULL; | |
29 return new EulaAcceptedNotifier(local_state); | |
30 #endif | |
31 } | |
32 | |
33 EulaAcceptedNotifier::EulaAcceptedNotifier(PrefService* local_state) | |
34 : local_state_(local_state), observer_(NULL) { | |
10 } | 35 } |
11 | 36 |
12 EulaAcceptedNotifier::~EulaAcceptedNotifier() { | 37 EulaAcceptedNotifier::~EulaAcceptedNotifier() { |
13 } | 38 } |
14 | 39 |
15 void EulaAcceptedNotifier::Init(Observer* observer) { | 40 void EulaAcceptedNotifier::Init(Observer* observer) { |
16 DCHECK(!observer_ && observer); | 41 DCHECK(!observer_ && observer); |
17 observer_ = observer; | 42 observer_ = observer; |
18 } | 43 } |
19 | 44 |
45 bool EulaAcceptedNotifier::IsEulaAccepted() { | |
46 if (local_state_->GetBoolean(prefs::kEulaAccepted)) | |
47 return true; | |
48 | |
49 // Register for the notification, if this is the first time. | |
50 if (registrar_.IsEmpty()) { | |
51 registrar_.Init(local_state_); | |
52 registrar_.Add(prefs::kEulaAccepted, | |
53 base::Bind(&EulaAcceptedNotifier::OnPrefChanged, | |
54 base::Unretained(this))); | |
55 } | |
56 return false; | |
57 } | |
58 | |
20 void EulaAcceptedNotifier::NotifyObserver() { | 59 void EulaAcceptedNotifier::NotifyObserver() { |
21 observer_->OnEulaAccepted(); | 60 observer_->OnEulaAccepted(); |
22 } | 61 } |
23 | 62 |
24 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS) | 63 void EulaAcceptedNotifier::OnPrefChanged() { |
25 // static | 64 DCHECK(!registrar_.IsEmpty()); |
26 EulaAcceptedNotifier* EulaAcceptedNotifier::Create() { | 65 registrar_.RemoveAll(); |
27 return NULL; | 66 |
67 DCHECK(local_state_->GetBoolean(prefs::kEulaAccepted)); | |
68 observer_->OnEulaAccepted(); | |
28 } | 69 } |
29 #endif | 70 |
OLD | NEW |