| 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_ |
| 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 |
| 17 // helper class to check if they can perform their requests. They should check |
| 18 // both IsNetworkAccessAllowed and IsEulaAccepted before requesting their data. |
| 19 // If either is false, the service can add themselves as an observer of this |
| 20 // class and be notified when the network is up, or the EULA is accepted. |
| 21 class ResourceRequestAllowedNotifier : |
| 22 #if defined(OS_CHROMEOS) |
| 23 public content::NotificationObserver, |
| 24 #endif |
| 25 public net::NetworkChangeNotifier::ConnectionTypeObserver { |
| 26 public: |
| 27 // Observes network and EULA state changes. |
| 28 class Observer { |
| 29 public: |
| 30 // Called after the network changes to an active connection. |
| 31 virtual void OnNetworkChangedToActiveConnection() = 0; |
| 32 |
| 33 #if defined(OS_CHROMEOS) |
| 34 // Called after the EULA has been accepted. |
| 35 virtual void OnEulaAccepted() = 0; |
| 36 #endif |
| 37 }; |
| 38 |
| 39 ResourceRequestAllowedNotifier(); |
| 40 virtual ~ResourceRequestAllowedNotifier(); |
| 41 |
| 42 void AddObserver(Observer* observer); |
| 43 void RemoveObserver(Observer* observer); |
| 44 |
| 45 // Returns true iff the network is currently inaccessible. |
| 46 static bool IsNetworkOffline(); |
| 47 |
| 48 #if defined(OS_CHROMEOS) |
| 49 // Returns true iff the EULA was accepted by the user. |
| 50 static bool IsEulaAccepted(); |
| 51 |
| 52 // content::NotificationObserver overrides: |
| 53 virtual void Observe(int type, |
| 54 const content::NotificationSource& source, |
| 55 const content::NotificationDetails& details) OVERRIDE; |
| 56 #endif |
| 57 |
| 58 // net::NetworkChangeNotifier::ConnectionTypeObserver implementation. |
| 59 virtual void OnConnectionTypeChanged( |
| 60 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 61 |
| 62 private: |
| 63 // List of observers interested in request permissions. |
| 64 ObserverList<Observer> observer_list_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(ResourceRequestAllowedNotifier); |
| 67 }; |
| 68 |
| 69 #endif // CHROME_BROWSER_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_ |
| OLD | NEW |