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