| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_POLICY_USER_POLICY_IDENTITY_STRATEGY_H_ | 5 #ifndef CHROME_BROWSER_POLICY_USER_POLICY_IDENTITY_STRATEGY_H_ |
| 6 #define CHROME_BROWSER_POLICY_USER_POLICY_IDENTITY_STRATEGY_H_ | 6 #define CHROME_BROWSER_POLICY_USER_POLICY_IDENTITY_STRATEGY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chrome/browser/policy/cloud_policy_identity_strategy.h" | 14 #include "chrome/browser/policy/cloud_policy_identity_strategy.h" |
| 15 #include "content/common/notification_observer.h" | |
| 16 #include "content/common/notification_registrar.h" | |
| 17 | |
| 18 class Profile; | |
| 19 | 15 |
| 20 namespace policy { | 16 namespace policy { |
| 21 | 17 |
| 22 class DeviceManagementBackend; | 18 class DeviceManagementBackend; |
| 23 | 19 |
| 24 // A token provider implementation that provides a user device token for the | 20 // A token provider implementation that provides a user device token for the |
| 25 // user corresponding to a given profile. | 21 // user corresponding to given credentials. |
| 26 class UserPolicyIdentityStrategy : public CloudPolicyIdentityStrategy, | 22 class UserPolicyIdentityStrategy : public CloudPolicyIdentityStrategy { |
| 27 public NotificationObserver { | |
| 28 public: | 23 public: |
| 29 UserPolicyIdentityStrategy(Profile* profile, | 24 UserPolicyIdentityStrategy(const std::string& user_name, |
| 30 const FilePath& token_cache_file); | 25 const FilePath& token_cache_file); |
| 31 virtual ~UserPolicyIdentityStrategy(); | 26 virtual ~UserPolicyIdentityStrategy(); |
| 32 | 27 |
| 33 // Start loading the token cache. | 28 // Start loading the token cache. |
| 34 void LoadTokenCache(); | 29 void LoadTokenCache(); |
| 35 | 30 |
| 31 // Set a newly arriving auth_token and maybe trigger a fetch. |
| 32 void SetAuthToken(const std::string& auth_token); |
| 33 |
| 36 // CloudPolicyIdentityStrategy implementation: | 34 // CloudPolicyIdentityStrategy implementation: |
| 37 virtual std::string GetDeviceToken() OVERRIDE; | 35 virtual std::string GetDeviceToken() OVERRIDE; |
| 38 virtual std::string GetDeviceID() OVERRIDE; | 36 virtual std::string GetDeviceID() OVERRIDE; |
| 39 virtual std::string GetMachineID() OVERRIDE; | 37 virtual std::string GetMachineID() OVERRIDE; |
| 40 virtual std::string GetMachineModel() OVERRIDE; | 38 virtual std::string GetMachineModel() OVERRIDE; |
| 41 virtual em::DeviceRegisterRequest_Type GetPolicyRegisterType() OVERRIDE; | 39 virtual em::DeviceRegisterRequest_Type GetPolicyRegisterType() OVERRIDE; |
| 42 virtual std::string GetPolicyType() OVERRIDE; | 40 virtual std::string GetPolicyType() OVERRIDE; |
| 43 virtual bool GetCredentials(std::string* username, | 41 virtual bool GetCredentials(std::string* username, |
| 44 std::string* auth_token) OVERRIDE; | 42 std::string* auth_token) OVERRIDE; |
| 45 virtual void OnDeviceTokenAvailable(const std::string& token) OVERRIDE; | 43 virtual void OnDeviceTokenAvailable(const std::string& token) OVERRIDE; |
| 46 | 44 |
| 47 private: | 45 private: |
| 48 class TokenCache; | 46 class TokenCache; |
| 49 | 47 |
| 50 // Checks whether a new token should be fetched and if so, sends out a | 48 // Checks whether a new token should be fetched and if so, sends out a |
| 51 // notification. | 49 // notification. |
| 52 void CheckAndTriggerFetch(); | 50 void CheckAndTriggerFetch(); |
| 53 | 51 |
| 54 // Gets the current user. | 52 // Gets the current user. |
| 55 std::string GetCurrentUser(); | 53 std::string GetCurrentUser(); |
| 56 | 54 |
| 57 // Called from the token cache when the token has been loaded. | 55 // Called from the token cache when the token has been loaded. |
| 58 void OnCacheLoaded(const std::string& token, const std::string& device_id); | 56 void OnCacheLoaded(const std::string& token, const std::string& device_id); |
| 59 | 57 |
| 60 // NotificationObserver method overrides: | |
| 61 virtual void Observe(NotificationType type, | |
| 62 const NotificationSource& source, | |
| 63 const NotificationDetails& details); | |
| 64 | |
| 65 // The profile this provider is associated with. | |
| 66 Profile* profile_; | |
| 67 | |
| 68 // Keeps the on-disk copy of the token. | 58 // Keeps the on-disk copy of the token. |
| 69 scoped_refptr<TokenCache> cache_; | 59 scoped_refptr<TokenCache> cache_; |
| 70 | 60 |
| 71 // The device ID we use. | 61 // The device ID we use. |
| 72 std::string device_id_; | 62 std::string device_id_; |
| 73 | 63 |
| 74 // Current device token. Empty if not available. | 64 // Current device token. Empty if not available. |
| 75 std::string device_token_; | 65 std::string device_token_; |
| 76 | 66 |
| 77 // Registers the provider for notification of successful Gaia logins. | 67 // Current auth token. Empty if not available. |
| 78 NotificationRegistrar registrar_; | 68 std::string auth_token_; |
| 69 |
| 70 // Current user name. Empty if not available. This is set on creation and not |
| 71 // changed afterwards |
| 72 std::string user_name_; |
| 79 | 73 |
| 80 // Allows to construct weak ptrs. | 74 // Allows to construct weak ptrs. |
| 81 base::WeakPtrFactory<UserPolicyIdentityStrategy> weak_ptr_factory_; | 75 base::WeakPtrFactory<UserPolicyIdentityStrategy> weak_ptr_factory_; |
| 82 | 76 |
| 83 DISALLOW_COPY_AND_ASSIGN(UserPolicyIdentityStrategy); | 77 DISALLOW_COPY_AND_ASSIGN(UserPolicyIdentityStrategy); |
| 84 }; | 78 }; |
| 85 | 79 |
| 86 } // namespace policy | 80 } // namespace policy |
| 87 | 81 |
| 88 #endif // CHROME_BROWSER_POLICY_USER_POLICY_IDENTITY_STRATEGY_H_ | 82 #endif // CHROME_BROWSER_POLICY_USER_POLICY_IDENTITY_STRATEGY_H_ |
| OLD | NEW |