Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/metrics/histogram.h" | |
| 6 #include "chrome/browser/resource_request_allowed_notifier.h" | |
| 7 #include "chrome/common/chrome_notification_types.h" | |
| 8 #include "content/public/browser/notification_service.h" | |
| 9 | |
| 10 #if defined(OS_CHROMEOS) | |
| 11 #include "chrome/browser/chromeos/login/wizard_controller.h" | |
| 12 #endif | |
| 13 | |
| 14 ResourceRequestAllowedNotifier::ResourceRequestAllowedNotifier() : | |
| 15 #if defined(OS_CHROMEOS) | |
| 16 was_offline_during_last_request_attempt_(false), | |
| 17 #endif | |
| 18 was_waiting_for_user_to_accept_eula_(false) { | |
|
Alexei Svitkine (slow)
2012/09/12 15:15:46
I think you want the OS_CHROMEOS ifdef over this l
SteveT
2012/09/14 20:25:09
D'oh. You can tell I haven't ran my Non-CrOS tests
| |
| 19 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | |
| 20 | |
| 21 #if defined(OS_CHROMEOS) | |
| 22 registrar_.Add(this, chrome::NOTIFICATION_WIZARD_EULA_ACCEPTED, | |
| 23 content::NotificationService::AllSources()); | |
|
Ilya Sherman
2012/09/11 22:51:27
nit: Listening to notifications from AllSources()
SteveT
2012/09/14 20:25:09
Did the work to resolve all this.
| |
| 24 #endif | |
| 25 } | |
| 26 | |
| 27 ResourceRequestAllowedNotifier::~ResourceRequestAllowedNotifier() { | |
| 28 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | |
| 29 | |
| 30 #if defined(OS_CHROMEOS) | |
| 31 registrar_.Remove(this, chrome::NOTIFICATION_WIZARD_EULA_ACCEPTED, | |
| 32 content::NotificationService::AllSources()); | |
|
Ilya Sherman
2012/09/11 22:51:27
nit: Listening to notifications from AllSources()
SteveT
2012/09/14 20:25:09
Done.
| |
| 33 #endif | |
| 34 } | |
| 35 | |
| 36 void ResourceRequestAllowedNotifier::AddObserver(Observer* observer) { | |
| 37 DCHECK(observer_list_.size() == 0) << "One service per notifier."; | |
|
Ilya Sherman
2012/09/11 22:51:27
nit: Please drop the """<< "One service per notifi
Alexei Svitkine (slow)
2012/09/12 15:15:46
If you're enforcing this, why not just make it enf
SteveT
2012/09/14 20:25:09
Didn't realize that was the case. I'll drop the lo
SteveT
2012/09/14 20:25:09
No, you're totally right. I've changed this class
| |
| 38 observer_list_.AddObserver(observer); | |
| 39 } | |
| 40 | |
| 41 void ResourceRequestAllowedNotifier::RemoveObserver(Observer* observer) { | |
| 42 observer_list_.RemoveObserver(observer); | |
| 43 DCHECK(observer_list_.size() == 0) << "One service per notifier."; | |
|
Ilya Sherman
2012/09/11 22:51:27
nit: Please drop the logged line.
SteveT
2012/09/14 20:25:09
Done.
| |
| 44 } | |
| 45 | |
| 46 bool ResourceRequestAllowedNotifier::ResourceRequestsAllowed() { | |
| 47 #if defined(OS_CHROMEOS) | |
| 48 was_waiting_for_user_to_accept_eula_ = | |
| 49 !chromeos::WizardController::IsEulaAccepted(); | |
|
Alexei Svitkine (slow)
2012/09/12 15:15:46
Do we need to query this each time or can we just
SteveT
2012/09/14 20:25:09
I think your suggestion is reasonable, because onc
| |
| 50 #endif | |
| 51 was_offline_during_last_request_attempt_ = | |
| 52 net::NetworkChangeNotifier::IsOffline(); | |
| 53 | |
| 54 // TODO(stevet): Remove this or rename. | |
| 55 UMA_HISTOGRAM_BOOLEAN("Variations.NetworkAvailability", | |
|
Alexei Svitkine (slow)
2012/09/12 15:15:46
Maybe keep this histogram in variations service an
SteveT
2012/09/14 20:25:09
I am considering just sunsetting, since we already
| |
| 56 !was_offline_during_last_request_attempt_); | |
| 57 | |
| 58 return | |
| 59 #if defined(OS_CHROMEOS) | |
| 60 !was_waiting_for_user_to_accept_eula_ && | |
| 61 #endif | |
| 62 !was_offline_during_last_request_attempt_; | |
| 63 } | |
| 64 | |
| 65 #if defined(OS_CHROMEOS) | |
| 66 void ResourceRequestAllowedNotifier::Observe( | |
| 67 int type, | |
| 68 const content::NotificationSource& source, | |
| 69 const content::NotificationDetails& details) { | |
| 70 DCHECK(type == chrome::NOTIFICATION_WIZARD_EULA_ACCEPTED); | |
|
Alexei Svitkine (slow)
2012/09/12 15:15:46
Can you use DCHECK_EQ() here?
SteveT
2012/09/14 20:25:09
Done.
| |
| 71 // If the observing service did not fail earlier due to an unaccepted EULA, | |
| 72 // do not notify it. | |
|
Alexei Svitkine (slow)
2012/09/12 15:15:46
Wouldn't the condition you describe in this commen
Nikita (slow)
2012/09/12 15:20:23
No, it is not possible.
| |
| 73 if (was_waiting_for_user_to_accept_eula_) { | |
| 74 DVLOG(1) << "EULA was accepted."; | |
|
Ilya Sherman
2012/09/11 22:51:27
Is this DVLOG just to help you while developing, o
SteveT
2012/09/14 20:25:09
Well I expect it to be useful in the future as dev
| |
| 75 MaybeNotifyObservers(); | |
| 76 } | |
| 77 } | |
| 78 #endif | |
| 79 | |
| 80 // net::NetworkChangeNotifier::ConnectionTypeObserver implementation. | |
| 81 void ResourceRequestAllowedNotifier::OnConnectionTypeChanged( | |
| 82 net::NetworkChangeNotifier::ConnectionType type) { | |
| 83 if (was_offline_during_last_request_attempt_ && | |
| 84 type != net::NetworkChangeNotifier::CONNECTION_NONE) { | |
|
Alexei Svitkine (slow)
2012/09/12 15:15:46
Can you add a comment explaining the if statement
SteveT
2012/09/14 20:25:09
Done.
| |
| 85 DVLOG(1) << "Network came back online."; | |
| 86 MaybeNotifyObservers(); | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 void ResourceRequestAllowedNotifier:: | |
| 91 SetWasOfflineDuringLastRequestAttemptForTesting(bool offline) { | |
| 92 was_offline_during_last_request_attempt_ = offline; | |
| 93 } | |
| 94 | |
| 95 void ResourceRequestAllowedNotifier::MaybeNotifyObservers() { | |
| 96 // Need to ensure that all criteria is met before notifying observers. | |
|
Alexei Svitkine (slow)
2012/09/12 15:15:46
Nit: "is" -> "are".
SteveT
2012/09/14 20:25:09
Done.
| |
| 97 if (ResourceRequestsAllowed()) { | |
|
Alexei Svitkine (slow)
2012/09/12 15:15:46
I think this is problematic per what mmenke said i
SteveT
2012/09/14 20:25:09
X being one of Eula-accepted or network-online? So
| |
| 98 DVLOG(1) << "Notifying observer of state change."; | |
| 99 FOR_EACH_OBSERVER(Observer, observer_list_, OnResourceRequestsAllowed()); | |
| 100 } | |
| 101 } | |
| OLD | NEW |