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