Chromium Code Reviews| 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_CROS_USER_POLICY_IDENTITY_STRATEGY_H_ |
| 6 #define CHROME_BROWSER_POLICY_USER_POLICY_IDENTITY_STRATEGY_H_ | 6 #define CHROME_BROWSER_POLICY_CROS_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" | |
| 12 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "chrome/browser/policy/cloud_policy_identity_strategy.h" | 12 #include "chrome/browser/policy/cloud_policy_identity_strategy.h" |
| 16 #include "chrome/browser/policy/user_policy_token_cache.h" | |
| 17 #include "content/common/notification_observer.h" | 13 #include "content/common/notification_observer.h" |
| 18 #include "content/common/notification_registrar.h" | 14 #include "content/common/notification_registrar.h" |
| 19 | 15 |
| 20 class Profile; | 16 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 // User policy identity strategy for ChromeOS user policy. Unlike the generic |
| 27 // user corresponding to a given profile. | 23 // implementation, it does not keep its own cache but relies on external |
| 28 class UserPolicyIdentityStrategy : public CloudPolicyIdentityStrategy, | 24 // entities to cache the device credentials. This is usually done by |
| 29 public NotificationObserver, | 25 // CrosUserPolicyCache. |
| 30 public UserPolicyTokenCache::Delegate { | 26 class CrosUserPolicyIdentityStrategy : public CloudPolicyIdentityStrategy, |
| 27 public NotificationObserver { | |
| 31 public: | 28 public: |
| 32 UserPolicyIdentityStrategy(Profile* profile, | 29 explicit CrosUserPolicyIdentityStrategy(Profile* profile); |
| 33 const FilePath& token_cache_file); | 30 virtual ~CrosUserPolicyIdentityStrategy(); |
| 34 virtual ~UserPolicyIdentityStrategy(); | |
| 35 | 31 |
| 36 // Start loading the token cache. | 32 // Sets device ID and token and announces its availablility. |
| 37 void LoadTokenCache(); | 33 void SetDeviceCredentials(const std::string& device_id, |
| 34 const std::string& token); | |
|
gfeher
2011/06/22 12:41:31
Is this the device's dmtoken or the user's dmtoken
Mattias Nissler (ping if slow)
2011/06/22 17:17:35
It's the user token. I thought that's obvious sinc
| |
| 35 | |
| 36 // Allows the identity strategy to register when the required data becomes | |
| 37 // available. | |
| 38 void EnableRegistration(); | |
| 38 | 39 |
| 39 // CloudPolicyIdentityStrategy implementation: | 40 // CloudPolicyIdentityStrategy implementation: |
| 40 virtual std::string GetDeviceToken() OVERRIDE; | 41 virtual std::string GetDeviceToken() OVERRIDE; |
| 41 virtual std::string GetDeviceID() OVERRIDE; | 42 virtual std::string GetDeviceID() OVERRIDE; |
| 42 virtual std::string GetMachineID() OVERRIDE; | 43 virtual std::string GetMachineID() OVERRIDE; |
| 43 virtual std::string GetMachineModel() OVERRIDE; | 44 virtual std::string GetMachineModel() OVERRIDE; |
| 44 virtual em::DeviceRegisterRequest_Type GetPolicyRegisterType() OVERRIDE; | 45 virtual em::DeviceRegisterRequest_Type GetPolicyRegisterType() OVERRIDE; |
| 45 virtual std::string GetPolicyType() OVERRIDE; | 46 virtual std::string GetPolicyType() OVERRIDE; |
| 46 virtual bool GetCredentials(std::string* username, | 47 virtual bool GetCredentials(std::string* username, |
| 47 std::string* auth_token) OVERRIDE; | 48 std::string* auth_token) OVERRIDE; |
| 48 virtual void OnDeviceTokenAvailable(const std::string& token) OVERRIDE; | 49 virtual void OnDeviceTokenAvailable(const std::string& token) OVERRIDE; |
| 49 | 50 |
| 50 private: | 51 private: |
| 51 // Checks whether a new token should be fetched and if so, sends out a | 52 // Checks whether a new token should be fetched and if so, sends out a |
| 52 // notification. | 53 // notification. |
| 53 void CheckAndTriggerFetch(); | 54 void CheckAndTriggerFetch(); |
| 54 | 55 |
| 55 // Gets the current user. | 56 // Gets the current user. |
| 56 std::string GetCurrentUser(); | 57 std::string GetCurrentUser(); |
| 57 | 58 |
| 58 // Called from the token cache when the token has been loaded. | |
| 59 virtual void OnTokenCacheLoaded(const std::string& token, | |
| 60 const std::string& device_id) OVERRIDE; | |
| 61 | |
| 62 // NotificationObserver method overrides: | 59 // NotificationObserver method overrides: |
| 63 virtual void Observe(NotificationType type, | 60 virtual void Observe(NotificationType type, |
| 64 const NotificationSource& source, | 61 const NotificationSource& source, |
| 65 const NotificationDetails& details) OVERRIDE; | 62 const NotificationDetails& details); |
| 63 | |
| 64 // Whether the to try and register when credentials are available. | |
| 65 bool should_register_; | |
| 66 | 66 |
| 67 // The profile this provider is associated with. | 67 // The profile this provider is associated with. |
| 68 Profile* profile_; | 68 Profile* profile_; |
| 69 | 69 |
| 70 // Keeps the on-disk copy of the token. | |
| 71 scoped_refptr<UserPolicyTokenCache> cache_; | |
| 72 | |
| 73 // The device ID we use. | 70 // The device ID we use. |
| 74 std::string device_id_; | 71 std::string device_id_; |
| 75 | 72 |
| 76 // Current device token. Empty if not available. | 73 // Current device token. Empty if not available. |
| 77 std::string device_token_; | 74 std::string device_token_; |
| 78 | 75 |
| 79 // Registers the provider for notification of successful Gaia logins. | 76 // Registers the provider for notification of successful Gaia logins. |
| 80 NotificationRegistrar registrar_; | 77 NotificationRegistrar registrar_; |
| 81 | 78 |
| 82 // Allows to construct weak ptrs. | 79 DISALLOW_COPY_AND_ASSIGN(CrosUserPolicyIdentityStrategy); |
| 83 base::WeakPtrFactory<UserPolicyTokenCache::Delegate> weak_ptr_factory_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(UserPolicyIdentityStrategy); | |
| 86 }; | 80 }; |
| 87 | 81 |
| 88 } // namespace policy | 82 } // namespace policy |
| 89 | 83 |
| 90 #endif // CHROME_BROWSER_POLICY_USER_POLICY_IDENTITY_STRATEGY_H_ | 84 #endif // CHROME_BROWSER_POLICY_CROS_USER_POLICY_IDENTITY_STRATEGY_H_ |
| OLD | NEW |