Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / signin / easy_unlock_service_signin_chromeos.h
blob94b3cef951ee3d85c3239d409f759a07f1f29706
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 "chrome/browser/signin/screenlock_bridge.h"
19 #include "chromeos/login/login_state.h"
21 // EasyUnlockService instance that should be used for signin profile.
22 class EasyUnlockServiceSignin : public EasyUnlockService,
23 public ScreenlockBridge::Observer,
24 public chromeos::LoginState::Observer {
25 public:
26 explicit EasyUnlockServiceSignin(Profile* profile);
27 ~EasyUnlockServiceSignin() override;
29 // Sets |user_id| as the current user of the service. Note this does
30 // not change the focused user on the login screen.
31 void SetCurrentUser(const std::string& user_id);
33 private:
34 // The load state of a user's cryptohome key data.
35 enum UserDataState {
36 // Initial state, the key data is empty and not being loaded.
37 USER_DATA_STATE_INITIAL,
38 // The key data is empty, but being loaded.
39 USER_DATA_STATE_LOADING,
40 // The key data has been loaded.
41 USER_DATA_STATE_LOADED
44 // Structure containing a user's key data loaded from cryptohome.
45 struct UserData {
46 UserData();
47 ~UserData();
49 // The loading state of the data.
50 UserDataState state;
52 // The data as returned from cryptohome.
53 chromeos::EasyUnlockDeviceKeyDataList devices;
55 // The list of remote device dictionaries understood by Easy unlock app.
56 // This will be returned by |GetRemoteDevices| method.
57 base::ListValue remote_devices_value;
59 private:
60 DISALLOW_COPY_AND_ASSIGN(UserData);
63 // EasyUnlockService implementation:
64 EasyUnlockService::Type GetType() const override;
65 std::string GetUserEmail() const override;
66 void LaunchSetup() override;
67 const base::DictionaryValue* GetPermitAccess() const override;
68 void SetPermitAccess(const base::DictionaryValue& permit) override;
69 void ClearPermitAccess() override;
70 const base::ListValue* GetRemoteDevices() const override;
71 void SetRemoteDevices(const base::ListValue& devices) override;
72 void RunTurnOffFlow() override;
73 void ResetTurnOffFlow() override;
74 TurnOffFlowStatus GetTurnOffFlowStatus() const override;
75 std::string GetChallenge() const override;
76 std::string GetWrappedSecret() const override;
77 void RecordEasySignInOutcome(const std::string& user_id,
78 bool success) const override;
79 void RecordPasswordLoginEvent(const std::string& user_id) const override;
80 void StartAutoPairing(const AutoPairingResultCallback& callback) override;
81 void SetAutoPairingResult(bool success, const std::string& error) override;
82 void InitializeInternal() override;
83 void ShutdownInternal() override;
84 bool IsAllowedInternal() const override;
85 void OnWillFinalizeUnlock(bool success) override;
86 void OnSuspendDone() override;
88 // ScreenlockBridge::Observer implementation:
89 void OnScreenDidLock(
90 ScreenlockBridge::LockHandler::ScreenType screen_type) override;
91 void OnScreenDidUnlock(
92 ScreenlockBridge::LockHandler::ScreenType screen_type) override;
93 void OnFocusedUserChanged(const std::string& user_id) override;
95 // chromeos::LoginState::Observer implementation:
96 void LoggedInStateChanged() override;
98 // Loads the device data associated with the user's Easy unlock keys from
99 // crypthome.
100 void LoadCurrentUserDataIfNeeded();
102 // Callback invoked when the user's device data is loaded from cryptohome.
103 void OnUserDataLoaded(
104 const std::string& user_id,
105 bool success,
106 const chromeos::EasyUnlockDeviceKeyDataList& data);
108 // If the device data has been loaded for the current user, returns it.
109 // Otherwise, returns NULL.
110 const UserData* FindLoadedDataForCurrentUser() const;
112 // User id of the user currently associated with the service.
113 std::string user_id_;
115 // Maps user ids to their fetched cryptohome key data.
116 std::map<std::string, UserData*> user_data_;
118 // Whether failed attempts to load user data should be retried.
119 // This is to handle case where cryptohome daemon is not started in time the
120 // service attempts to load some data. Retries will be allowed only until the
121 // first data load finishes (even if it fails).
122 bool allow_cryptohome_backoff_;
124 // Whether the service has been successfully initialized, and has not been
125 // shut down.
126 bool service_active_;
128 // The timestamp for the most recent time when a user pod was focused.
129 base::TimeTicks user_pod_last_focused_timestamp_;
131 base::WeakPtrFactory<EasyUnlockServiceSignin> weak_ptr_factory_;
133 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceSignin);
136 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_