OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_ |
6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_ | 6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_ |
7 | 7 |
| 8 #include <map> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/values.h" |
13 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h" | 15 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h" |
14 #include "chrome/browser/signin/easy_unlock_service.h" | 16 #include "chrome/browser/signin/easy_unlock_service.h" |
15 | 17 |
16 namespace base { | |
17 class DictionaryValue; | |
18 class ListValue; | |
19 } | |
20 | |
21 // EasyUnlockService instance that should be used for signin profile. | 18 // EasyUnlockService instance that should be used for signin profile. |
22 class EasyUnlockServiceSignin : public EasyUnlockService { | 19 class EasyUnlockServiceSignin : public EasyUnlockService { |
23 public: | 20 public: |
24 explicit EasyUnlockServiceSignin(Profile* profile); | 21 explicit EasyUnlockServiceSignin(Profile* profile); |
25 virtual ~EasyUnlockServiceSignin(); | 22 virtual ~EasyUnlockServiceSignin(); |
26 | 23 |
27 void SetAssociatedUser(const std::string& user_id); | 24 private: |
| 25 // The load state of a user's cryptohome key data. |
| 26 enum UserDataState { |
| 27 // Initial state, the key data is empty and not being loaded. |
| 28 USER_DATA_STATE_INITIAL, |
| 29 // The key data is empty, but being loaded. |
| 30 USER_DATA_STATE_LOADING, |
| 31 // The key data has been loaded. |
| 32 USER_DATA_STATE_LOADED |
| 33 }; |
28 | 34 |
29 private: | 35 // Structure containing a user's key data loaded from cryptohome. |
| 36 struct UserData { |
| 37 UserData(); |
| 38 ~UserData(); |
| 39 |
| 40 // The loading state of the data. |
| 41 UserDataState state; |
| 42 |
| 43 // The data as returned from cryptohome. |
| 44 chromeos::EasyUnlockDeviceKeyDataList devices; |
| 45 |
| 46 // The list of remote device dictionaries understood by Easy unlock app. |
| 47 // This will be returned by |GetRemoteDevices| method. |
| 48 base::ListValue remote_devices_value; |
| 49 |
| 50 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(UserData); |
| 52 }; |
| 53 |
30 // EasyUnlockService implementation: | 54 // EasyUnlockService implementation: |
31 virtual EasyUnlockService::Type GetType() const OVERRIDE; | 55 virtual EasyUnlockService::Type GetType() const OVERRIDE; |
32 virtual std::string GetUserEmail() const OVERRIDE; | 56 virtual std::string GetUserEmail() const OVERRIDE; |
33 virtual void LaunchSetup() OVERRIDE; | 57 virtual void LaunchSetup() OVERRIDE; |
34 virtual const base::DictionaryValue* GetPermitAccess() const OVERRIDE; | 58 virtual const base::DictionaryValue* GetPermitAccess() const OVERRIDE; |
35 virtual void SetPermitAccess(const base::DictionaryValue& permit) OVERRIDE; | 59 virtual void SetPermitAccess(const base::DictionaryValue& permit) OVERRIDE; |
36 virtual void ClearPermitAccess() OVERRIDE; | 60 virtual void ClearPermitAccess() OVERRIDE; |
37 virtual const base::ListValue* GetRemoteDevices() const OVERRIDE; | 61 virtual const base::ListValue* GetRemoteDevices() const OVERRIDE; |
38 virtual void SetRemoteDevices(const base::ListValue& devices) OVERRIDE; | 62 virtual void SetRemoteDevices(const base::ListValue& devices) OVERRIDE; |
39 virtual void ClearRemoteDevices() OVERRIDE; | 63 virtual void ClearRemoteDevices() OVERRIDE; |
40 virtual void RunTurnOffFlow() OVERRIDE; | 64 virtual void RunTurnOffFlow() OVERRIDE; |
41 virtual void ResetTurnOffFlow() OVERRIDE; | 65 virtual void ResetTurnOffFlow() OVERRIDE; |
42 virtual TurnOffFlowStatus GetTurnOffFlowStatus() const OVERRIDE; | 66 virtual TurnOffFlowStatus GetTurnOffFlowStatus() const OVERRIDE; |
43 virtual std::string GetChallenge() const OVERRIDE; | 67 virtual std::string GetChallenge() const OVERRIDE; |
44 virtual bool IsAllowedInternal() OVERRIDE; | 68 virtual bool IsAllowedInternal() OVERRIDE; |
45 virtual void InitializeInternal() OVERRIDE; | 69 virtual void InitializeInternal() OVERRIDE; |
46 | 70 |
47 // Fetches |remote_devices_| info from cryptohome keys. | 71 // Loads the device data associated with the user's Easy unlock keys from |
48 void FetchCryptohomeKeys(); | 72 // crypthome. |
| 73 void LoadCurrentUserDataIfNeeded(); |
49 | 74 |
50 // Callback invoked when the cryptohome keys are fetched. | 75 // Callback invoked when the user's device data is loaded from cryptohome. |
51 void OnCryptohomeKeysFetched( | 76 void OnUserDataLoaded( |
| 77 const std::string& user_id, |
52 bool success, | 78 bool success, |
53 const chromeos::EasyUnlockDeviceKeyDataList& devices); | 79 const chromeos::EasyUnlockDeviceKeyDataList& data); |
54 | 80 |
55 // User id of the associated user. | 81 // If the device data has been loaded for the current user, returns is. |
| 82 // Otherwise, returns NULL. |
| 83 const UserData* FindLoadedDataForCurrentUser() const; |
| 84 |
| 85 // User id of the user currently associated with the service. |
56 std::string user_id_; | 86 std::string user_id_; |
57 | 87 |
58 // Remote devices of the associated user. | 88 // Maps user ids to their fetched cryptohome key data. |
59 chromeos::EasyUnlockDeviceKeyDataList remote_devices_; | 89 std::map<std::string, UserData*> user_data_; |
60 scoped_ptr<base::ListValue> remote_devices_value_; | 90 |
| 91 // Whether failed attempts to load user data should be retried. |
| 92 // This is to handle case where cryptohome daemon is not started in time the |
| 93 // service attempts to load some data. Retries will be allowed only until the |
| 94 // first data load finishes (even if it fails). |
| 95 bool allow_cryptohome_backoff_; |
61 | 96 |
62 base::WeakPtrFactory<EasyUnlockServiceSignin> weak_ptr_factory_; | 97 base::WeakPtrFactory<EasyUnlockServiceSignin> weak_ptr_factory_; |
63 | 98 |
64 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceSignin); | 99 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceSignin); |
65 }; | 100 }; |
66 | 101 |
67 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_ | 102 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_ |
OLD | NEW |