network_profile_handler.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
1// Copyright (c) 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_PROFILE_HANDLER_H_ 6#define CHROMEOS_NETWORK_NETWORK_PROFILE_HANDLER_H_ 7 8#include <string> 9#include <vector> 10 11#include "base/basictypes.h" 12#include "base/compiler_specific.h" 13#include "base/memory/weak_ptr.h" 14#include "base/observer_list.h" 15#include "chromeos/chromeos_export.h" 16#include "chromeos/dbus/dbus_method_call_status.h" 17#include "chromeos/dbus/shill_property_changed_observer.h" 18#include "chromeos/network/network_handler.h" 19#include "chromeos/network/network_profile.h" 20 21namespace base { 22class DictionaryValue; 23} 24 25namespace chromeos { 26 27class NetworkProfileObserver; 28class NetworkStateHandler; 29 30class CHROMEOS_EXPORT NetworkProfileHandler 31 : public ShillPropertyChangedObserver { 32 public: 33 typedef std::vector<NetworkProfile> ProfileList; 34 35 virtual ~NetworkProfileHandler(); 36 37 void AddObserver(NetworkProfileObserver* observer); 38 void RemoveObserver(NetworkProfileObserver* observer); 39 40 void GetManagerPropertiesCallback(DBusMethodCallStatus call_status, 41 const base::DictionaryValue& properties); 42 43 // ShillPropertyChangedObserver overrides 44 virtual void OnPropertyChanged(const std::string& name, 45 const base::Value& value) OVERRIDE; 46 47 void GetProfilePropertiesCallback(const std::string& profile_path, 48 const base::DictionaryValue& properties); 49 50 const NetworkProfile* GetProfileForPath( 51 const std::string& profile_path) const; 52 const NetworkProfile* GetProfileForUserhash( 53 const std::string& userhash) const; 54 55 // Returns the first profile entry with a non-empty userhash. 56 // TODO(stevenjb): Replace with GetProfileForUserhash() with the correct 57 // userhash. 58 const NetworkProfile* GetDefaultUserProfile() const; 59 60 static std::string GetSharedProfilePath(); 61 62 protected: 63 friend class ClientCertResolverTest; 64 friend class NetworkConnectionHandlerTest; 65 friend class NetworkHandler; 66 NetworkProfileHandler(); 67 68 // Add ShillManagerClient property observer and request initial list. 69 // Sets |network_state_handler_| for triggering Manager updates (can be NULL). 70 void Init(NetworkStateHandler* network_state_handler); 71 72 void AddProfile(const NetworkProfile& profile); 73 void RemoveProfile(const std::string& profile_path); 74 75 private: 76 NetworkStateHandler* network_state_handler_; 77 ProfileList profiles_; 78 ObserverList<NetworkProfileObserver> observers_; 79 80 // For Shill client callbacks 81 base::WeakPtrFactory<NetworkProfileHandler> weak_ptr_factory_; 82 83 private: 84 DISALLOW_COPY_AND_ASSIGN(NetworkProfileHandler); 85}; 86 87} // namespace chromeos 88 89#endif // CHROMEOS_NETWORK_NETWORK_PROFILE_HANDLER_H_ 90