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_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_ | |
| 6 #define CHROME_BROWSER_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_ | |
|
Ilya Sherman
2012/09/11 22:51:27
nit: Is the variations service currently the only
Alexei Svitkine (slow)
2012/09/12 15:15:46
I agree with Ilya here. Let's add it under chrome/
SteveT
2012/09/14 20:25:09
Done.
SteveT
2012/09/14 20:25:09
Done.
| |
| 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 // Services that need to request resources over the network should use this | |
|
Alexei Svitkine (slow)
2012/09/12 15:15:46
Can you rephrase the first sentence and/or paragra
SteveT
2012/09/14 20:25:09
Done.
| |
| 17 // helper class to check if they can perform their requests. This class wraps | |
| 18 // such criteria and notifies interested services if state ever changes in such | |
| 19 // a way that resource access is allowed. | |
| 20 // | |
| 21 // Such services should add themselves as an observer of | |
| 22 // ResourceRequestAllowedNotifier and check ResourceRequestsAllowed() to see if | |
| 23 // requests are permitted. If it returns true, they can go ahead and make their | |
| 24 // request. If it returns false, ResourceRequestAllowedNotifier will notify the | |
| 25 // service when the criteria is met. | |
| 26 // | |
| 27 // If the ResourceRequestsAllowed returns true the first time, | |
| 28 // ResourceRequestAllowedNotifier will not notify the service in the future. | |
| 29 // | |
| 30 // Note that this class handles the criteria state for a single service, so | |
| 31 // services should keep their own instance of this class rather than sharing a | |
| 32 // global instance. | |
| 33 // | |
| 34 // Currently, the criteria for allowing resource requests include: | |
| 35 // 1. The network is currently available. | |
| 36 // 2. The EULA was accepted by the user (ChromeOS only). | |
| 37 class ResourceRequestAllowedNotifier : | |
| 38 #if defined(OS_CHROMEOS) | |
| 39 public content::NotificationObserver, | |
| 40 #endif | |
| 41 public net::NetworkChangeNotifier::ConnectionTypeObserver { | |
| 42 public: | |
| 43 // Observes resource request allowed state changes. | |
| 44 class Observer { | |
| 45 public: | |
| 46 virtual void OnResourceRequestsAllowed() = 0; | |
| 47 }; | |
| 48 | |
| 49 ResourceRequestAllowedNotifier(); | |
| 50 virtual ~ResourceRequestAllowedNotifier(); | |
| 51 | |
| 52 void AddObserver(Observer* observer); | |
| 53 void RemoveObserver(Observer* observer); | |
| 54 | |
| 55 // Returns true iff all resource request criteria is met. If not, this call | |
| 56 // will set some flags so it knows to notify the observer if the criteria | |
| 57 // changes. | |
| 58 bool ResourceRequestsAllowed(); | |
| 59 | |
| 60 #if defined(OS_CHROMEOS) | |
| 61 // content::NotificationObserver overrides: | |
| 62 virtual void Observe(int type, | |
| 63 const content::NotificationSource& source, | |
| 64 const content::NotificationDetails& details) OVERRIDE; | |
|
Ilya Sherman
2012/09/11 22:51:27
nit: Can this have private visibility?
SteveT
2012/09/14 20:25:09
Yes! Done.
| |
| 65 #endif | |
| 66 | |
| 67 // net::NetworkChangeNotifier::ConnectionTypeObserver implementation. | |
| 68 virtual void OnConnectionTypeChanged( | |
| 69 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | |
|
Ilya Sherman
2012/09/11 22:51:27
nit: Can this have private visibility?
SteveT
2012/09/14 20:25:09
Yeah, done.
| |
| 70 | |
| 71 void SetWasOfflineDuringLastRequestAttemptForTesting(bool offline); | |
| 72 | |
| 73 private: | |
| 74 // Notifies observers if all criteria needed for resource requests are met. | |
| 75 void MaybeNotifyObservers(); | |
| 76 | |
| 77 #if defined(OS_CHROMEOS) | |
|
Alexei Svitkine (slow)
2012/09/12 15:15:46
I think this ifdef was meant to go around the next
SteveT
2012/09/14 20:25:09
Yes, done.
| |
| 78 // Tracks network connectivity criteria. | |
| 79 bool was_offline_during_last_request_attempt_; | |
|
Alexei Svitkine (slow)
2012/09/12 15:15:46
Can you name this consistently with |was_waiting_f
SteveT
2012/09/14 20:25:09
Sure.
was_waiting_for_network_
and
was_waiting_fo
| |
| 80 #endif | |
| 81 | |
| 82 // Tracks EULA acceptance criteria. | |
| 83 bool was_waiting_for_user_to_accept_eula_; | |
|
Ilya Sherman
2012/09/11 22:51:27
nit: Should this also be in the #if defined(OS_CHR
SteveT
2012/09/14 20:25:09
Yes - thanks.
| |
| 84 | |
| 85 // List of observers interested in request permissions. | |
| 86 ObserverList<Observer> observer_list_; | |
| 87 | |
| 88 content::NotificationRegistrar registrar_; | |
|
Ilya Sherman
2012/09/11 22:51:27
nit: Ditto
SteveT
2012/09/14 20:25:09
Done.
| |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(ResourceRequestAllowedNotifier); | |
| 91 }; | |
| 92 | |
| 93 #endif // CHROME_BROWSER_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_ | |
| OLD | NEW |