OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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_CHROMEOS_AUTHPOLICY_AUTH_POLICY_CREDENTIALS_MANAGER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_AUTHPOLICY_AUTH_POLICY_CREDENTIALS_MANAGER_H_ | |
7 | |
8 #include "base/cancelable_callback.h" | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "chromeos/dbus/authpolicy/active_directory_info.pb.h" | |
11 #include "chromeos/network/network_state_handler_observer.h" | |
12 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" | |
13 #include "components/keyed_service/core/keyed_service.h" | |
14 #include "components/signin/core/account_id/account_id.h" | |
15 #include "third_party/cros_system_api/dbus/service_constants.h" | |
16 | |
17 class Profile; | |
18 | |
19 namespace authpolicy { | |
20 class ActiveDirectoryUserStatus; | |
21 } | |
22 | |
23 namespace base { | |
24 template <typename T> | |
25 struct DefaultSingletonTraits; | |
26 } // namespace base | |
27 | |
28 // A service responsible for tracking user credential status. Created for each | |
29 // Active Directory user profile. | |
30 class AuthPolicyCredentialsManager | |
31 : public KeyedService, | |
32 public chromeos::NetworkStateHandlerObserver { | |
33 public: | |
34 explicit AuthPolicyCredentialsManager(Profile* profile); | |
35 ~AuthPolicyCredentialsManager() override; | |
36 | |
37 // KeyedService overrides. | |
38 void Shutdown() override; | |
39 | |
40 // chromeos::NetworkStateHandlerObserver overrides. | |
41 void DefaultNetworkChanged(const chromeos::NetworkState* network) override; | |
42 void NetworkConnectionStateChanged( | |
43 const chromeos::NetworkState* network) override; | |
44 void OnShuttingDown() override; | |
45 | |
46 private: | |
47 // Calls AuthPolicyClient::GetUserStatus method. | |
48 void GetUserStatus(); | |
49 | |
50 // See AuthPolicyClient::GetUserStatusCallback. | |
51 void OnGetUserStatusCallback( | |
52 authpolicy::ErrorType error, | |
53 const authpolicy::ActiveDirectoryUserStatus& user_status); | |
54 | |
55 // Post delayed task to call GetUserStatus in the future. | |
56 void ScheduleGetUserStatus(); | |
57 | |
58 // Add itself as network observer. | |
59 void StartObserveNetwork(); | |
60 // Remove itself as network observer. | |
61 void StopObserveNetwork(); | |
62 | |
63 // Update display and given name in case it has changed. | |
64 void UpdateDisplayAndGivenName( | |
65 const authpolicy::ActiveDirectoryAccountInfo& account_info); | |
66 | |
67 // Shows user notification to sign out/sign in. | |
68 void ShowNotification(int message_id); | |
69 | |
70 // Call GetUserStatus if |network_state| is connected and the previous call | |
71 // failed. | |
72 void GetUserStatusIfConnected(const chromeos::NetworkState* network_state); | |
73 | |
74 Profile* profile_; | |
75 AccountId account_id_; | |
76 std::string display_name_, given_name_; | |
77 bool rerun_get_status_on_error_ = false; | |
78 | |
79 // Stores message ids of shown notifications. Each notification is shown at | |
80 // most once. | |
81 std::unordered_set<int> shown_notifications_; | |
Thiemo Nagel
2017/05/26 12:46:21
Hash imho doesn't seem to be a great choice to sto
Roman Sorokin (ftl)
2017/05/26 13:06:33
Done.
| |
82 authpolicy::ErrorType last_error_ = authpolicy::ERROR_NONE; | |
83 base::CancelableClosure scheduled_get_user_status_call_; | |
84 | |
85 base::WeakPtrFactory<AuthPolicyCredentialsManager> weak_factory_{this}; | |
86 DISALLOW_COPY_AND_ASSIGN(AuthPolicyCredentialsManager); | |
87 }; | |
88 | |
89 // Singleton that owns all AuthPolicyCredentialsManagers and associates them | |
90 // with BrowserContexts. | |
91 class AuthPolicyCredentialsManagerFactory | |
92 : public BrowserContextKeyedServiceFactory { | |
93 public: | |
94 static AuthPolicyCredentialsManagerFactory* GetInstance(); | |
95 | |
96 static void BuildForProfileIfActiveDirectory(Profile* profile); | |
97 | |
98 private: | |
99 friend struct base::DefaultSingletonTraits< | |
100 AuthPolicyCredentialsManagerFactory>; | |
101 | |
102 AuthPolicyCredentialsManagerFactory(); | |
103 ~AuthPolicyCredentialsManagerFactory() override; | |
104 | |
105 KeyedService* BuildServiceInstanceFor( | |
106 content::BrowserContext* context) const override; | |
107 | |
108 DISALLOW_COPY_AND_ASSIGN(AuthPolicyCredentialsManagerFactory); | |
109 }; | |
110 | |
111 #endif // CHROME_BROWSER_CHROMEOS_AUTHPOLICY_AUTH_POLICY_CREDENTIALS_MANAGER_H_ | |
OLD | NEW |