forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetwork_metadata_store.h
134 lines (107 loc) · 5.21 KB
/
network_metadata_store.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_NETWORK_NETWORK_METADATA_STORE_H_
#define CHROMEOS_NETWORK_NETWORK_METADATA_STORE_H_
#include <string>
#include "base/component_export.h"
#include "base/observer_list.h"
#include "base/values.h"
#include "chromeos/login/login_state/login_state.h"
#include "chromeos/network/network_configuration_observer.h"
#include "chromeos/network/network_connection_observer.h"
#include "chromeos/network/network_metadata_observer.h"
class PrefService;
class PrefRegistrySimple;
namespace base {
class TimeDelta;
}
namespace chromeos {
class NetworkConfigurationHandler;
class NetworkConnectionHandler;
class NetworkStateHandler;
// Stores metadata about networks using the UserProfilePrefStore for networks
// that are on the local profile and the LocalStatePrefStore for shared
// networks.
class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkMetadataStore
: public NetworkConnectionObserver,
public NetworkConfigurationObserver,
public LoginState::Observer {
public:
NetworkMetadataStore(
NetworkConfigurationHandler* network_configuration_handler,
NetworkConnectionHandler* network_connection_handler,
NetworkStateHandler* network_state_handler,
PrefService* profile_pref_service,
PrefService* device_pref_service,
bool is_enterprise_managed);
~NetworkMetadataStore() override;
// Registers preferences used by this class in the provided |registry|. This
// should be called for both the Profile registry and the Local State registry
// prior to using this class.
static void RegisterPrefs(PrefRegistrySimple* registry);
// LoginState::Observer overrides.
void LoggedInStateChanged() override;
// NetworkConnectionObserver::
void ConnectSucceeded(const std::string& service_path) override;
void ConnectFailed(const std::string& service_path,
const std::string& error_name) override;
// NetworkConfigurationObserver::
void OnConfigurationCreated(const std::string& service_path,
const std::string& guid) override;
void OnConfigurationModified(const std::string& service_path,
const std::string& guid,
base::DictionaryValue* set_properties) override;
void OnConfigurationRemoved(const std::string& service_path,
const std::string& guid) override;
// Records that the network was added by sync.
void SetIsConfiguredBySync(const std::string& network_guid);
// Returns the timestamp when the network was last connected to, or 0 if it
// has never had a successful connection.
base::TimeDelta GetLastConnectedTimestamp(const std::string& network_guid);
void SetLastConnectedTimestamp(const std::string& network_guid,
const base::TimeDelta& timestamp);
// Networks which were added directly from sync data will return true.
bool GetIsConfiguredBySync(const std::string& network_guid);
// Networks which were created by the logged in user will return true.
bool GetIsCreatedByUser(const std::string& network_guid);
// When another user modifies a watched field.
bool GetIsFieldExternallyModified(const std::string& network_guid,
const std::string& field);
// If a connection to a Wi-Fi network fails because of a bad password before
// it has ever connected successfully, then this will return true. Once there
// has been a successful connection with the currently saved password, this
// will always return false.
bool GetHasBadPassword(const std::string& network_guid);
// When the active user is the device owner and its the first login, this
// marks networks that were added in OOBE to the user's list.
void OwnSharedNetworksOnFirstUserLogin();
// Manage observers.
void AddObserver(NetworkMetadataObserver* observer);
void RemoveObserver(NetworkMetadataObserver* observer);
base::WeakPtr<NetworkMetadataStore> GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
private:
void RemoveNetworkFromPref(const std::string& network_guid,
PrefService* pref_service);
void SetPref(const std::string& network_guid,
const std::string& key,
base::Value value);
const base::Value* GetPref(const std::string& network_guid,
const std::string& key);
void UpdateExternalModifications(const std::string& network_guid,
const std::string& field);
// Sets the owner metadata when there is an active user, otherwise a no-op.
void SetIsCreatedByUser(const std::string& network_guid);
base::ObserverList<NetworkMetadataObserver> observers_;
NetworkConfigurationHandler* network_configuration_handler_;
NetworkConnectionHandler* network_connection_handler_;
NetworkStateHandler* network_state_handler_;
PrefService* profile_pref_service_;
PrefService* device_pref_service_;
bool is_enterprise_managed_;
base::WeakPtrFactory<NetworkMetadataStore> weak_ptr_factory_{this};
};
} // namespace chromeos
#endif // CHROMEOS_NETWORK_NETWORK_METADATA_STORE_H_