| 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_mobile.h" | 5 #include "chrome/browser/metrics/variations/eula_accepted_notifier_mobile.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 | 10 #include "chrome/common/pref_names.h" |
| 11 namespace { | |
| 12 | |
| 13 const char kEulaAccepted[] = "EulaAccepted"; | |
| 14 | |
| 15 } // namespace | |
| 16 | 11 |
| 17 EulaAcceptedNotifierMobile::EulaAcceptedNotifierMobile( | 12 EulaAcceptedNotifierMobile::EulaAcceptedNotifierMobile( |
| 18 PrefService* local_state) | 13 PrefService* local_state) |
| 19 : local_state_(local_state) { | 14 : local_state_(local_state) { |
| 20 } | 15 } |
| 21 | 16 |
| 22 EulaAcceptedNotifierMobile::~EulaAcceptedNotifierMobile() { | 17 EulaAcceptedNotifierMobile::~EulaAcceptedNotifierMobile() { |
| 23 } | 18 } |
| 24 | 19 |
| 25 bool EulaAcceptedNotifierMobile::IsEulaAccepted() { | 20 bool EulaAcceptedNotifierMobile::IsEulaAccepted() { |
| 26 if (local_state_->GetBoolean(kEulaAccepted)) | 21 if (local_state_->GetBoolean(prefs::kEulaAccepted)) |
| 27 return true; | 22 return true; |
| 28 | 23 |
| 29 // Register for the notification, if this is the first time. | 24 // Register for the notification, if this is the first time. |
| 30 if (registrar_.IsEmpty()) { | 25 if (registrar_.IsEmpty()) { |
| 31 registrar_.Init(local_state_); | 26 registrar_.Init(local_state_); |
| 32 registrar_.Add(kEulaAccepted, | 27 registrar_.Add(prefs::kEulaAccepted, |
| 33 base::Bind(&EulaAcceptedNotifierMobile::OnPrefChanged, | 28 base::Bind(&EulaAcceptedNotifierMobile::OnPrefChanged, |
| 34 base::Unretained(this))); | 29 base::Unretained(this))); |
| 35 } | 30 } |
| 36 return false; | 31 return false; |
| 37 } | 32 } |
| 38 | 33 |
| 39 void EulaAcceptedNotifierMobile::OnPrefChanged() { | 34 void EulaAcceptedNotifierMobile::OnPrefChanged() { |
| 40 DCHECK(!registrar_.IsEmpty()); | 35 DCHECK(!registrar_.IsEmpty()); |
| 41 registrar_.RemoveAll(); | 36 registrar_.RemoveAll(); |
| 42 | 37 |
| 43 DCHECK(local_state_->GetBoolean(kEulaAccepted)); | 38 DCHECK(local_state_->GetBoolean(prefs::kEulaAccepted)); |
| 44 NotifyObserver(); | 39 NotifyObserver(); |
| 45 } | 40 } |
| 46 | 41 |
| 47 // static | 42 // static |
| 48 EulaAcceptedNotifier* EulaAcceptedNotifier::Create() { | 43 EulaAcceptedNotifier* EulaAcceptedNotifier::Create() { |
| 49 PrefService* local_state = g_browser_process->local_state(); | 44 PrefService* local_state = g_browser_process->local_state(); |
| 50 // If the |kEulaAccepted| pref is not registered, return NULL which is | 45 // If the |kEulaAccepted| pref is not registered, return NULL which is |
| 51 // equivalent to not needing to check the EULA. This is the case for some | 46 // equivalent to not needing to check the EULA. This is the case for some |
| 52 // tests for higher-level classes that use the EulaAcceptNotifier. | 47 // tests for higher-level classes that use the EulaAcceptNotifier. |
| 53 if (local_state->FindPreference(kEulaAccepted) == NULL) | 48 if (local_state->FindPreference(prefs::kEulaAccepted) == NULL) |
| 54 return NULL; | 49 return NULL; |
| 55 return new EulaAcceptedNotifierMobile(local_state); | 50 return new EulaAcceptedNotifierMobile(local_state); |
| 56 } | 51 } |
| OLD | NEW |