Chromium Code Reviews| 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 EulaAcceptedNotifier::EulaAcceptedNotifier(PrefService* local_state) |
| 14 : local_state_(local_state), observer_(NULL) { | |
| 10 } | 15 } |
| 11 | 16 |
| 12 EulaAcceptedNotifier::~EulaAcceptedNotifier() { | 17 EulaAcceptedNotifier::~EulaAcceptedNotifier() { |
| 13 } | 18 } |
| 14 | 19 |
| 15 void EulaAcceptedNotifier::Init(Observer* observer) { | 20 void EulaAcceptedNotifier::Init(Observer* observer) { |
| 16 DCHECK(!observer_ && observer); | 21 DCHECK(!observer_ && observer); |
| 17 observer_ = observer; | 22 observer_ = observer; |
| 18 } | 23 } |
| 19 | 24 |
| 25 bool EulaAcceptedNotifier::IsEulaAccepted() { | |
| 26 if (local_state_->GetBoolean(prefs::kEulaAccepted)) | |
| 27 return true; | |
| 28 | |
| 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))); | |
| 35 } | |
| 36 return false; | |
| 37 } | |
| 38 | |
| 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) | |
|
SteveT
2013/06/03 18:58:18
optional nit: I think it would be slightly easier
Alexei Svitkine (slow)
2013/06/03 20:36:38
That would be misleading, since the defined keywor
SteveT
2013/06/03 20:47:48
Ah, you're right. SGTM.
| |
| 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 | |
| 55 } | |
| 56 | |
| 20 void EulaAcceptedNotifier::NotifyObserver() { | 57 void EulaAcceptedNotifier::NotifyObserver() { |
| 21 observer_->OnEulaAccepted(); | 58 observer_->OnEulaAccepted(); |
| 22 } | 59 } |
| 23 | 60 |
| 24 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS) | 61 void EulaAcceptedNotifier::OnPrefChanged() { |
| 25 // static | 62 DCHECK(!registrar_.IsEmpty()); |
| 26 EulaAcceptedNotifier* EulaAcceptedNotifier::Create() { | 63 registrar_.RemoveAll(); |
| 27 return NULL; | 64 |
| 65 DCHECK(local_state_->GetBoolean(prefs::kEulaAccepted)); | |
| 66 observer_->OnEulaAccepted(); | |
| 28 } | 67 } |
| 29 #endif | 68 |
| OLD | NEW |