Home | History | Annotate | Download | only in network
      1 // Copyright 2013 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 CHROMEOS_NETWORK_NETWORK_HANDLER_H_
      6 #define CHROMEOS_NETWORK_NETWORK_HANDLER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/memory/ref_counted.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/message_loop/message_loop_proxy.h"
     12 #include "chromeos/chromeos_export.h"
     13 
     14 namespace chromeos {
     15 
     16 class GeolocationHandler;
     17 class ManagedNetworkConfigurationHandler;
     18 class NetworkCertMigrator;
     19 class NetworkConfigurationHandler;
     20 class NetworkConnectionHandler;
     21 class NetworkDeviceHandler;
     22 class NetworkProfileHandler;
     23 class NetworkStateHandler;
     24 class NetworkSmsHandler;
     25 
     26 // Class for handling initialization and access to chromeos network handlers.
     27 // This class should NOT be used in unit tests. Instead, construct individual
     28 // classes independently.
     29 class CHROMEOS_EXPORT NetworkHandler {
     30  public:
     31   // Sets the global instance. Must be called before any calls to Get().
     32   static void Initialize();
     33 
     34   // Destroys the global instance.
     35   static void Shutdown();
     36 
     37   // Gets the global instance. Initialize() must be called first.
     38   static NetworkHandler* Get();
     39 
     40   // Returns true if the global instance has been initialized.
     41   static bool IsInitialized();
     42 
     43   // Returns the MessageLoopProxy for posting NetworkHandler calls from
     44   // other threads.
     45   base::MessageLoopProxy* message_loop() { return message_loop_.get(); }
     46 
     47   // Do not use these accessors within this module; all dependencies should be
     48   // explicit so that classes can be constructed explicitly in tests without
     49   // NetworkHandler.
     50   NetworkStateHandler* network_state_handler();
     51   NetworkDeviceHandler* network_device_handler();
     52   NetworkProfileHandler* network_profile_handler();
     53   NetworkConfigurationHandler* network_configuration_handler();
     54   ManagedNetworkConfigurationHandler* managed_network_configuration_handler();
     55   NetworkConnectionHandler* network_connection_handler();
     56   NetworkSmsHandler* network_sms_handler();
     57   GeolocationHandler* geolocation_handler();
     58 
     59  private:
     60   NetworkHandler();
     61   virtual ~NetworkHandler();
     62 
     63   void Init();
     64 
     65   // The order of these determines the (inverse) destruction order.
     66   scoped_refptr<base::MessageLoopProxy> message_loop_;
     67   scoped_ptr<NetworkStateHandler> network_state_handler_;
     68   scoped_ptr<NetworkDeviceHandler> network_device_handler_;
     69   scoped_ptr<NetworkProfileHandler> network_profile_handler_;
     70   scoped_ptr<NetworkCertMigrator> network_cert_migrator_;
     71   scoped_ptr<NetworkConfigurationHandler> network_configuration_handler_;
     72   scoped_ptr<ManagedNetworkConfigurationHandler>
     73       managed_network_configuration_handler_;
     74   scoped_ptr<NetworkConnectionHandler> network_connection_handler_;
     75   scoped_ptr<NetworkSmsHandler> network_sms_handler_;
     76   scoped_ptr<GeolocationHandler> geolocation_handler_;
     77 
     78   DISALLOW_COPY_AND_ASSIGN(NetworkHandler);
     79 };
     80 
     81 }  // namespace chromeos
     82 
     83 #endif  // CHROMEOS_NETWORK_NETWORK_HANDLER_H_
     84