Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / signin / easy_unlock_service_signin_chromeos.h
blob634de98d5bac2ec2007c02345c4011674d89b2a8
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_
6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_
8 #include <map>
9 #include <string>
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h"
15 #include "base/values.h"
16 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h"
17 #include "chrome/browser/signin/easy_unlock_service.h"
18 #include "chromeos/login/login_state.h"
19 #include "components/proximity_auth/screenlock_bridge.h"
21 // EasyUnlockService instance that should be used for signin profile.
22 class EasyUnlockServiceSignin
23 : public EasyUnlockService,
24 public proximity_auth::ScreenlockBridge::Observer,
25 public chromeos::LoginState::Observer {
26 public:
27 explicit EasyUnlockServiceSignin(Profile* profile);
28 ~EasyUnlockServiceSignin() override;
30 // Sets |user_id| as the current user of the service. Note this does
31 // not change the focused user on the login screen.
32 void SetCurrentUser(const std::string& user_id);
34 private:
35 // The load state of a user's cryptohome key data.
36 enum UserDataState {
37 // Initial state, the key data is empty and not being loaded.
38 USER_DATA_STATE_INITIAL,
39 // The key data is empty, but being loaded.
40 USER_DATA_STATE_LOADING,
41 // The key data has been loaded.
42 USER_DATA_STATE_LOADED
45 // Structure containing a user's key data loaded from cryptohome.
46 struct UserData {
47 UserData();
48 ~UserData();
50 // The loading state of the data.
51 UserDataState state;
53 // The data as returned from cryptohome.
54 chromeos::EasyUnlockDeviceKeyDataList devices;
56 // The list of remote device dictionaries understood by Easy unlock app.
57 // This will be returned by |GetRemoteDevices| method.
58 base::ListValue remote_devices_value;
60 private:
61 DISALLOW_COPY_AND_ASSIGN(UserData);
64 // EasyUnlockService implementation:
65 EasyUnlockService::Type GetType() const override;
66 std::string GetUserEmail() const override;
67 void LaunchSetup() override;
68 const base::DictionaryValue* GetPermitAccess() const override;
69 void SetPermitAccess(const base::DictionaryValue& permit) override;
70 void ClearPermitAccess() override;
71 const base::ListValue* GetRemoteDevices() const override;
72 void SetRemoteDevices(const base::ListValue& devices) override;
73 void RunTurnOffFlow() override;
74 void ResetTurnOffFlow() override;
75 TurnOffFlowStatus GetTurnOffFlowStatus() const override;
76 std::string GetChallenge() const override;
77 std::string GetWrappedSecret() const override;
78 void RecordEasySignInOutcome(const std::string& user_id,
79 bool success) const override;
80 void RecordPasswordLoginEvent(const std::string& user_id) const override;
81 void StartAutoPairing(const AutoPairingResultCallback& callback) override;
82 void SetAutoPairingResult(bool success, const std::string& error) override;
83 void InitializeInternal() override;
84 void ShutdownInternal() override;
85 bool IsAllowedInternal() const override;
86 void OnWillFinalizeUnlock(bool success) override;
87 void OnSuspendDone() override;
89 // proximity_auth::ScreenlockBridge::Observer implementation:
90 void OnScreenDidLock(proximity_auth::ScreenlockBridge::LockHandler::ScreenType
91 screen_type) override;
92 void OnScreenDidUnlock(
93 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type)
94 override;
95 void OnFocusedUserChanged(const std::string& user_id) override;
97 // chromeos::LoginState::Observer implementation:
98 void LoggedInStateChanged() override;
100 // Loads the device data associated with the user's Easy unlock keys from
101 // crypthome.
102 void LoadCurrentUserDataIfNeeded();
104 // Callback invoked when the user's device data is loaded from cryptohome.
105 void OnUserDataLoaded(
106 const std::string& user_id,
107 bool success,
108 const chromeos::EasyUnlockDeviceKeyDataList& data);
110 // If the device data has been loaded for the current user, returns it.
111 // Otherwise, returns NULL.
112 const UserData* FindLoadedDataForCurrentUser() const;
114 // User id of the user currently associated with the service.
115 std::string user_id_;
117 // Maps user ids to their fetched cryptohome key data.
118 std::map<std::string, UserData*> user_data_;
120 // Whether failed attempts to load user data should be retried.
121 // This is to handle case where cryptohome daemon is not started in time the
122 // service attempts to load some data. Retries will be allowed only until the
123 // first data load finishes (even if it fails).
124 bool allow_cryptohome_backoff_;
126 // Whether the service has been successfully initialized, and has not been
127 // shut down.
128 bool service_active_;
130 // The timestamp for the most recent time when a user pod was focused.
131 base::TimeTicks user_pod_last_focused_timestamp_;
133 base::WeakPtrFactory<EasyUnlockServiceSignin> weak_ptr_factory_;
135 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceSignin);
138 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_