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 // See AuthPolicyClient::GetUserStatusCallback. |
| 50 void OnGetUserStatusCallback( |
| 51 authpolicy::ErrorType error, |
| 52 const authpolicy::ActiveDirectoryUserStatus& user_status); |
| 53 // Post delayed task to call GetUserStatus in the future. |
| 54 void ScheduleGetUserStatus(); |
| 55 |
| 56 // Add itself as network observer. |
| 57 void StartObserveNetwork(); |
| 58 // Remove itself as network observer. |
| 59 void StopObserveNetwork(); |
| 60 |
| 61 // Update display and given name in case it has changed. |
| 62 void UpdateDisplayAndGivenName( |
| 63 const authpolicy::ActiveDirectoryAccountInfo& account_info); |
| 64 |
| 65 // Shows user notification to sign out/sign in. |
| 66 void ShowNotification(int message_id); |
| 67 |
| 68 // Call GetUserStatus if |network_state| is connected and the previous call |
| 69 // failed. |
| 70 void GetUserStatusIfConnected(const chromeos::NetworkState* network_state); |
| 71 |
| 72 Profile* profile_; |
| 73 AccountId account_id_; |
| 74 std::string display_name_, given_name_; |
| 75 bool should_call_get_status_again_ = false; |
| 76 bool was_notification_shown_ = false; |
| 77 authpolicy::ErrorType last_error_ = authpolicy::ERROR_NONE; |
| 78 base::CancelableClosure scheduled_get_user_status_call_; |
| 79 |
| 80 base::WeakPtrFactory<AuthPolicyCredentialsManager> weak_factory_; |
| 81 DISALLOW_COPY_AND_ASSIGN(AuthPolicyCredentialsManager); |
| 82 }; |
| 83 |
| 84 // Singleton that owns all AuthPolicyCredentialsManagers and associates them |
| 85 // with BrowserContexts. |
| 86 class AuthPolicyCredentialsManagerFactory |
| 87 : public BrowserContextKeyedServiceFactory { |
| 88 public: |
| 89 static AuthPolicyCredentialsManagerFactory* GetInstance(); |
| 90 |
| 91 static void BuildForProfileIfActiveDirectory(Profile* profile); |
| 92 |
| 93 private: |
| 94 friend struct base::DefaultSingletonTraits< |
| 95 AuthPolicyCredentialsManagerFactory>; |
| 96 |
| 97 AuthPolicyCredentialsManagerFactory(); |
| 98 ~AuthPolicyCredentialsManagerFactory() override; |
| 99 |
| 100 KeyedService* BuildServiceInstanceFor( |
| 101 content::BrowserContext* context) const override; |
| 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(AuthPolicyCredentialsManagerFactory); |
| 104 }; |
| 105 |
| 106 #endif // CHROME_BROWSER_CHROMEOS_AUTHPOLICY_AUTH_POLICY_CREDENTIALS_MANAGER_H_ |
OLD | NEW |