| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/resource_request_allowed_notifier.h" | 5 #include "chrome/browser/metrics/variations/resource_request_allowed_notifier.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "chrome/common/chrome_notification_types.h" | 8 #include "chrome/common/chrome_notification_types.h" |
| 9 #include "content/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
| 10 | 10 |
| 11 #if defined(OS_CHROMEOS) | 11 #if defined(OS_CHROMEOS) |
| 12 #include "chrome/browser/chromeos/login/wizard_controller.h" | 12 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 ResourceRequestAllowedNotifier::ResourceRequestAllowedNotifier() | 15 ResourceRequestAllowedNotifier::ResourceRequestAllowedNotifier() |
| 16 : observer_requested_permission_(false), | 16 : observer_requested_permission_(false), |
| 17 was_waiting_for_network_(false), | 17 was_waiting_for_network_(false), |
| 18 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
| 19 was_waiting_for_user_to_accept_eula_(false), | 19 was_waiting_for_user_to_accept_eula_(false), |
| 20 #endif | 20 #endif |
| 21 observer_(NULL) { | 21 observer_(NULL) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 ResourceRequestAllowedNotifier::~ResourceRequestAllowedNotifier() { | 24 ResourceRequestAllowedNotifier::~ResourceRequestAllowedNotifier() { |
| 25 if (observer_) | 25 if (observer_) |
| 26 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 26 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void ResourceRequestAllowedNotifier::Init(Observer* observer) { | 29 void ResourceRequestAllowedNotifier::Init(Observer* observer) { |
| 30 DCHECK(!observer_ && observer); | 30 DCHECK(!observer_ && observer); |
| 31 observer_ = observer; | 31 observer_ = observer; |
| 32 | 32 |
| 33 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 33 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 34 | 34 |
| 35 // Check this state during initialization. It is not expected to change until | 35 // Check this state during initialization. It is not expected to change until |
| 36 // the corresponding notification is received. | 36 // the corresponding notification is received. |
| 37 was_waiting_for_network_ = net::NetworkChangeNotifier::IsOffline(); | 37 was_waiting_for_network_ = net::NetworkChangeNotifier::IsOffline(); |
| 38 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
| 39 was_waiting_for_user_to_accept_eula_ = NeedsEulaAcceptance(); | 39 was_waiting_for_user_to_accept_eula_ = NeedsEulaAcceptance(); |
| 40 if (was_waiting_for_user_to_accept_eula_) { | 40 if (was_waiting_for_user_to_accept_eula_) { |
| 41 // Note that this must listen on AllSources due to the difficulty in knowing | 41 // Note that this must listen on AllSources due to the difficulty in knowing |
| 42 // when the WizardController instance is created, and to avoid over-coupling | 42 // when the WizardController instance is created, and to avoid over-coupling |
| 43 // the Chrome OS code with the VariationsService by directly attaching as an | 43 // the Chrome OS code with the VariationsService by directly attaching as an |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 bool ResourceRequestAllowedNotifier::NeedsEulaAcceptance() { | 87 bool ResourceRequestAllowedNotifier::NeedsEulaAcceptance() { |
| 88 #if defined(GOOGLE_CHROME_BUILD) | 88 #if defined(GOOGLE_CHROME_BUILD) |
| 89 return !chromeos::WizardController::IsEulaAccepted(); | 89 return !chromeos::WizardController::IsEulaAccepted(); |
| 90 #else | 90 #else |
| 91 // On unofficial builds, there is no notion of a EULA. | 91 // On unofficial builds, there is no notion of a EULA. |
| 92 return false; | 92 return false; |
| 93 #endif | 93 #endif |
| 94 } | 94 } |
| 95 #endif | 95 #endif |
| 96 | 96 |
| 97 void ResourceRequestAllowedNotifier::OnConnectionTypeChanged( | 97 void ResourceRequestAllowedNotifier::OnNetworkChanged( |
| 98 net::NetworkChangeNotifier::ConnectionType type) { | 98 net::NetworkChangeNotifier::ConnectionType type) { |
| 99 // Only attempt to notify observers if this was previously waiting for the | 99 // Only attempt to notify observers if this was previously waiting for the |
| 100 // network to reconnect, and new network state is actually available. This | 100 // network to reconnect, and new network state is actually available. This |
| 101 // prevents the notifier from notifying the observer if the notifier was never | 101 // prevents the notifier from notifying the observer if the notifier was never |
| 102 // waiting on the network, or if the network changes from one online state | 102 // waiting on the network, or if the network changes from one online state |
| 103 // to another (for example, Wifi to 3G, or Wifi to Wifi, if the network were | 103 // to another (for example, Wifi to 3G, or Wifi to Wifi, if the network were |
| 104 // flaky). | 104 // flaky). |
| 105 if (was_waiting_for_network_ && | 105 if (was_waiting_for_network_ && |
| 106 type != net::NetworkChangeNotifier::CONNECTION_NONE) { | 106 type != net::NetworkChangeNotifier::CONNECTION_NONE) { |
| 107 was_waiting_for_network_ = false; | 107 was_waiting_for_network_ = false; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 122 content::NotificationService::AllSources()); | 122 content::NotificationService::AllSources()); |
| 123 | 123 |
| 124 // This flag should have been set if this was waiting on the EULA | 124 // This flag should have been set if this was waiting on the EULA |
| 125 // notification. | 125 // notification. |
| 126 DCHECK(was_waiting_for_user_to_accept_eula_); | 126 DCHECK(was_waiting_for_user_to_accept_eula_); |
| 127 DVLOG(1) << "EULA was accepted."; | 127 DVLOG(1) << "EULA was accepted."; |
| 128 was_waiting_for_user_to_accept_eula_ = false; | 128 was_waiting_for_user_to_accept_eula_ = false; |
| 129 MaybeNotifyObserver(); | 129 MaybeNotifyObserver(); |
| 130 } | 130 } |
| 131 #endif | 131 #endif |
| OLD | NEW |