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