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