Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chromeos / network / network_profile_handler.h
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 <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h"
16 #include "chromeos/chromeos_export.h"
17 #include "chromeos/dbus/dbus_method_call_status.h"
18 #include "chromeos/dbus/shill_property_changed_observer.h"
19 #include "chromeos/network/network_handler.h"
20 #include "chromeos/network/network_profile.h"
21
22 namespace base {
23 class DictionaryValue;
24 }
25
26 namespace chromeos {
27
28 class NetworkProfileObserver;
29 class NetworkStateHandler;
30
31 class CHROMEOS_EXPORT NetworkProfileHandler
32     : public ShillPropertyChangedObserver {
33  public:
34   typedef std::vector<NetworkProfile> ProfileList;
35
36   virtual ~NetworkProfileHandler();
37
38   void AddObserver(NetworkProfileObserver* observer);
39   void RemoveObserver(NetworkProfileObserver* observer);
40
41   void GetManagerPropertiesCallback(DBusMethodCallStatus call_status,
42                                     const base::DictionaryValue& properties);
43
44   // ShillPropertyChangedObserver overrides
45   virtual void OnPropertyChanged(const std::string& name,
46                                  const base::Value& value) override;
47
48   void GetProfilePropertiesCallback(const std::string& profile_path,
49                                     const base::DictionaryValue& properties);
50
51   const NetworkProfile* GetProfileForPath(
52       const std::string& profile_path) const;
53   const NetworkProfile* GetProfileForUserhash(
54       const std::string& userhash) const;
55
56   // Returns the first profile entry with a non-empty userhash.
57   // TODO(stevenjb): Replace with GetProfileForUserhash() with the correct
58   // userhash.
59   const NetworkProfile* GetDefaultUserProfile() const;
60
61   static std::string GetSharedProfilePath();
62
63  protected:
64   friend class AutoConnectHandlerTest;
65   friend class ClientCertResolverTest;
66   friend class NetworkConnectionHandlerTest;
67   friend class NetworkHandler;
68   NetworkProfileHandler();
69
70   // Add ShillManagerClient property observer and request initial list.
71   void Init();
72
73   void AddProfile(const NetworkProfile& profile);
74   void RemoveProfile(const std::string& profile_path);
75
76  private:
77   ProfileList profiles_;
78
79   // Contains the profile paths for which properties were requested. Once the
80   // properties are retrieved and the path is still in this set, a new profile
81   // object is created.
82   std::set<std::string> pending_profile_creations_;
83   ObserverList<NetworkProfileObserver> observers_;
84
85   // For Shill client callbacks
86   base::WeakPtrFactory<NetworkProfileHandler> weak_ptr_factory_;
87
88  private:
89   DISALLOW_COPY_AND_ASSIGN(NetworkProfileHandler);
90 };
91
92 }  // namespace chromeos
93
94 #endif  // CHROMEOS_NETWORK_NETWORK_PROFILE_HANDLER_H_