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 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_ | |
| 6 #define CHROME_BROWSER_METRICS_VARIATIONS_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_ | |
| 7 | |
| 8 #include "base/observer_list.h" | |
| 9 #include "net/base/network_change_notifier.h" | |
| 10 | |
| 11 #if defined(OS_CHROMEOS) | |
| 12 #include "content/public/browser/notification_observer.h" | |
| 13 #include "content/public/browser/notification_registrar.h" | |
| 14 #endif | |
| 15 | |
| 16 #if defined(OS_CHROMEOS) | |
| 17 namespace chromeos { | |
| 18 class WizardController; | |
| 19 } | |
| 20 #endif | |
| 21 | |
| 22 // This class informs an interested observer when resource requests over the | |
| 23 // network are permitted. | |
| 24 // | |
| 25 // Currently, the criteria for allowing resource requests include: | |
| 26 // 1. The network is currently available. | |
| 27 // 2. The EULA was accepted by the user (ChromeOS only). | |
| 28 // | |
| 29 // Interested services should add themselves as an observer of | |
| 30 // ResourceRequestAllowedNotifier and check ResourceRequestsAllowed() to see if | |
| 31 // requests are permitted. If it returns true, they can go ahead and make their | |
| 32 // request. If it returns false, ResourceRequestAllowedNotifier will notify the | |
| 33 // service when the criteria is met. | |
| 34 // | |
| 35 // If the ResourceRequestsAllowed returns true the first time, | |
|
Alexei Svitkine (slow)
2012/09/19 20:05:35
Nit: remove the first "the".
SteveT
2012/09/20 19:40:18
Done.
| |
| 36 // ResourceRequestAllowedNotifier will not notify the service in the future. | |
| 37 // | |
| 38 // Note that this class handles the criteria state for a single service, so | |
| 39 // services should keep their own instance of this class rather than sharing a | |
| 40 // global instance. | |
| 41 class ResourceRequestAllowedNotifier : | |
| 42 #if defined(OS_CHROMEOS) | |
| 43 public content::NotificationObserver, | |
| 44 #endif | |
| 45 public net::NetworkChangeNotifier::ConnectionTypeObserver { | |
| 46 public: | |
| 47 // Observes resource request allowed state changes. | |
| 48 class Observer { | |
| 49 public: | |
| 50 virtual void OnResourceRequestsAllowed() = 0; | |
| 51 }; | |
| 52 | |
| 53 // Note that the constructor has some logic to register for notifications from | |
| 54 // the WizardController if the EULA was not accepted at startup (ChromeOS | |
| 55 // only). | |
| 56 ResourceRequestAllowedNotifier(); | |
| 57 virtual ~ResourceRequestAllowedNotifier(); | |
| 58 | |
| 59 // Sets |observer| as the observing service to be notified. | |
|
Alexei Svitkine (slow)
2012/09/19 20:05:35
Mention that this is a weak reference.
SteveT
2012/09/20 19:40:18
Removed this completely since we now take in that
| |
| 60 void SetObserver(Observer* observer); | |
| 61 | |
| 62 // Clears the current observer. | |
| 63 void ClearObserver(); | |
| 64 | |
| 65 // Returns true iff all resource request criteria is met. If not, this call | |
|
Alexei Svitkine (slow)
2012/09/19 20:05:35
Nit: "is met" -> "are met". ("criteria" is plural,
SteveT
2012/09/20 19:40:18
Done.
| |
| 66 // will set some flags so it knows to notify the observer if the criteria | |
| 67 // changes. This is virtual so it can be overriden for tests. | |
| 68 virtual bool ResourceRequestsAllowed(); | |
| 69 | |
| 70 void SetWasWaitingForNetworkForTesting(bool waiting); | |
| 71 #if defined(OS_CHROMEOS) | |
| 72 void SetWasWaitingForEulaForTesting(bool waiting); | |
| 73 #endif | |
| 74 | |
| 75 protected: | |
| 76 // Notifies observers if all criteria needed for resource requests are met. | |
| 77 // This is protected so it can be called from subclasses for testing. | |
| 78 void MaybeNotifyObservers(); | |
| 79 | |
| 80 private: | |
| 81 #if defined(OS_CHROMEOS) | |
| 82 // content::NotificationObserver overrides: | |
| 83 virtual void Observe(int type, | |
| 84 const content::NotificationSource& source, | |
| 85 const content::NotificationDetails& details) OVERRIDE; | |
| 86 | |
| 87 // net::NetworkChangeNotifier::ConnectionTypeObserver implementation. | |
|
Alexei Svitkine (slow)
2012/09/19 20:05:35
Nit: Use a consistent style for the comment.
You
SteveT
2012/09/20 19:40:18
Using "overrides:"
| |
| 88 virtual void OnConnectionTypeChanged( | |
|
Alexei Svitkine (slow)
2012/09/19 20:05:35
I don't think this should be in an ifdef CHROMEOS
SteveT
2012/09/20 19:40:18
Correct. Will have to rerun those other trybots an
| |
| 89 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | |
| 90 | |
| 91 content::NotificationRegistrar registrar_; | |
| 92 | |
| 93 // Tracks EULA acceptance criteria. | |
| 94 bool was_waiting_for_user_to_accept_eula_; | |
| 95 #endif | |
| 96 | |
| 97 // Tracks network connectivity criteria. | |
| 98 bool was_waiting_for_network_; | |
| 99 | |
| 100 // Observing service interested in request permissions. | |
| 101 Observer* observer_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(ResourceRequestAllowedNotifier); | |
| 104 }; | |
| 105 | |
| 106 #endif // CHROME_BROWSER_METRICS_VARIATIONS_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H _ | |
| OLD | NEW |