| 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_TOKEN_CACHE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_USER_POLICY_TOKEN_CACHE_H_ |
| 6 #define CHROME_BROWSER_POLICY_USER_POLICY_TOKEN_CACHE_H_ | 6 #define CHROME_BROWSER_POLICY_USER_POLICY_TOKEN_CACHE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.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/proto/device_management_local.pb.h" | 15 #include "chrome/browser/policy/cloud_policy_data_store.h" |
| 16 | 16 |
| 17 namespace policy { | 17 namespace policy { |
| 18 | 18 |
| 19 // Responsible for managing the on-disk token cache. | 19 // Responsible for managing the on-disk token cache. |
| 20 class UserPolicyTokenCache | 20 class UserPolicyTokenCache |
| 21 : public base::RefCountedThreadSafe<UserPolicyTokenCache> { | 21 : public base::RefCountedThreadSafe<UserPolicyTokenCache>, |
| 22 public CloudPolicyDataStore::Observer { |
| 22 public: | 23 public: |
| 23 // Callback interface for reporting a successfull load. | 24 UserPolicyTokenCache(const base::WeakPtr<CloudPolicyDataStore>& data_store, |
| 24 class Delegate { | |
| 25 public: | |
| 26 virtual ~Delegate(); | |
| 27 virtual void OnTokenCacheLoaded(const std::string& token, | |
| 28 const std::string& device_id) = 0; | |
| 29 }; | |
| 30 | |
| 31 UserPolicyTokenCache(const base::WeakPtr<Delegate>& delegate, | |
| 32 const FilePath& cache_file); | 25 const FilePath& cache_file); |
| 33 | 26 |
| 34 // Starts loading the disk cache. After the load is finished, the result is | 27 // Starts loading the disk cache. After the load is finished, the result is |
| 35 // reported through the delegate. | 28 // reported through the delegate. |
| 36 void Load(); | 29 void Load(); |
| 37 | 30 |
| 38 // Stores credentials asynchronously to disk. | 31 // Stores credentials asynchronously to disk. |
| 39 void Store(const std::string& token, const std::string& device_id); | 32 void Store(const std::string& token, const std::string& device_id); |
| 40 | 33 |
| 34 // CloudPolicyData::Observer implementation: |
| 35 virtual void OnDeviceTokenChanged() OVERRIDE; |
| 36 virtual void OnCredentialsChanged() OVERRIDE; |
| 37 virtual void OnDataStoreGoingAway() OVERRIDE; |
| 38 |
| 41 private: | 39 private: |
| 42 friend class base::RefCountedThreadSafe<UserPolicyTokenCache>; | 40 friend class base::RefCountedThreadSafe<UserPolicyTokenCache>; |
| 43 ~UserPolicyTokenCache(); | 41 virtual ~UserPolicyTokenCache(); |
| 44 | 42 |
| 45 void LoadOnFileThread(); | 43 void LoadOnFileThread(); |
| 46 void NotifyOnUIThread(const std::string& token, | 44 void NotifyOnUIThread(const std::string& token, |
| 47 const std::string& device_id); | 45 const std::string& device_id); |
| 48 void StoreOnFileThread(const std::string& token, | 46 void StoreOnFileThread(const std::string& token, |
| 49 const std::string& device_id); | 47 const std::string& device_id); |
| 50 | 48 |
| 51 const base::WeakPtr<Delegate> delegate_; | 49 const base::WeakPtr<CloudPolicyDataStore> data_store_; |
| 52 const FilePath cache_file_; | 50 const FilePath cache_file_; |
| 53 | 51 |
| 54 DISALLOW_COPY_AND_ASSIGN(UserPolicyTokenCache); | 52 DISALLOW_COPY_AND_ASSIGN(UserPolicyTokenCache); |
| 55 }; | 53 }; |
| 56 | 54 |
| 57 } // namespace policy | 55 } // namespace policy |
| 58 | 56 |
| 59 #endif // CHROME_BROWSER_POLICY_USER_POLICY_TOKEN_CACHE_H_ | 57 #endif // CHROME_BROWSER_POLICY_USER_POLICY_TOKEN_CACHE_H_ |
| OLD | NEW |