| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/web_resource/eula_accepted_notifier.h" | 5 #include "chrome/browser/web_resource/eula_accepted_notifier.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/browser_process.h" | |
| 11 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 12 | 11 |
| 13 EulaAcceptedNotifier::EulaAcceptedNotifier(PrefService* local_state) | 12 EulaAcceptedNotifier::EulaAcceptedNotifier(PrefService* local_state) |
| 14 : local_state_(local_state), observer_(NULL) { | 13 : local_state_(local_state), observer_(NULL) { |
| 15 } | 14 } |
| 16 | 15 |
| 17 EulaAcceptedNotifier::~EulaAcceptedNotifier() { | 16 EulaAcceptedNotifier::~EulaAcceptedNotifier() { |
| 18 } | 17 } |
| 19 | 18 |
| 20 void EulaAcceptedNotifier::Init(Observer* observer) { | 19 void EulaAcceptedNotifier::Init(Observer* observer) { |
| 21 DCHECK(!observer_ && observer); | 20 DCHECK(!observer_ && observer); |
| 22 observer_ = observer; | 21 observer_ = observer; |
| 23 } | 22 } |
| 24 | 23 |
| 25 bool EulaAcceptedNotifier::IsEulaAccepted() { | 24 bool EulaAcceptedNotifier::IsEulaAccepted() { |
| 26 if (local_state_->GetBoolean(prefs::kEulaAccepted)) | 25 if (local_state_->GetBoolean(prefs::kEulaAccepted)) |
| 27 return true; | 26 return true; |
| 28 | 27 |
| 29 // Register for the notification, if this is the first time. | 28 // Register for the notification, if this is the first time. |
| 30 if (registrar_.IsEmpty()) { | 29 if (registrar_.IsEmpty()) { |
| 31 registrar_.Init(local_state_); | 30 registrar_.Init(local_state_); |
| 32 registrar_.Add(prefs::kEulaAccepted, | 31 registrar_.Add(prefs::kEulaAccepted, |
| 33 base::Bind(&EulaAcceptedNotifier::OnPrefChanged, | 32 base::Bind(&EulaAcceptedNotifier::OnPrefChanged, |
| 34 base::Unretained(this))); | 33 base::Unretained(this))); |
| 35 } | 34 } |
| 36 return false; | 35 return false; |
| 37 } | 36 } |
| 38 | 37 |
| 39 // static | 38 // static |
| 40 EulaAcceptedNotifier* EulaAcceptedNotifier::Create() { | 39 EulaAcceptedNotifier* EulaAcceptedNotifier::Create(PrefService* local_state) { |
| 41 // First run EULA only exists on ChromeOS, Android and iOS. On ChromeOS, it is | 40 // First run EULA only exists on ChromeOS, Android and iOS. On ChromeOS, it is |
| 42 // only shown in official builds. | 41 // only shown in official builds. |
| 43 #if (defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)) || \ | 42 #if (defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)) || \ |
| 44 defined(OS_ANDROID) || defined(OS_IOS) | 43 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 | 44 // Tests that use higher-level classes that use EulaAcceptNotifier may not |
| 47 // have local state or may not register this pref. Return NULL to indicate not | 45 // have local state or may not register this pref. Return NULL to indicate not |
| 48 // needing to check the EULA. | 46 // needing to check the EULA. |
| 49 if (!local_state || !local_state->FindPreference(prefs::kEulaAccepted)) | 47 if (!local_state || !local_state->FindPreference(prefs::kEulaAccepted)) |
| 50 return NULL; | 48 return NULL; |
| 51 return new EulaAcceptedNotifier(local_state); | 49 return new EulaAcceptedNotifier(local_state); |
| 52 #else | 50 #else |
| 53 return NULL; | 51 return NULL; |
| 54 #endif | 52 #endif |
| 55 } | 53 } |
| 56 | 54 |
| 57 void EulaAcceptedNotifier::NotifyObserver() { | 55 void EulaAcceptedNotifier::NotifyObserver() { |
| 58 observer_->OnEulaAccepted(); | 56 observer_->OnEulaAccepted(); |
| 59 } | 57 } |
| 60 | 58 |
| 61 void EulaAcceptedNotifier::OnPrefChanged() { | 59 void EulaAcceptedNotifier::OnPrefChanged() { |
| 62 DCHECK(!registrar_.IsEmpty()); | 60 DCHECK(!registrar_.IsEmpty()); |
| 63 registrar_.RemoveAll(); | 61 registrar_.RemoveAll(); |
| 64 | 62 |
| 65 DCHECK(local_state_->GetBoolean(prefs::kEulaAccepted)); | 63 DCHECK(local_state_->GetBoolean(prefs::kEulaAccepted)); |
| 66 observer_->OnEulaAccepted(); | 64 observer_->OnEulaAccepted(); |
| 67 } | 65 } |
| 68 | 66 |
| OLD | NEW |