Chromium Code Reviews| Index: chrome/browser/policy/user_policy_token_cache.cc |
| diff --git a/chrome/browser/policy/user_policy_token_cache.cc b/chrome/browser/policy/user_policy_token_cache.cc |
| index adba4a4e89c75f5cc9fb03081d753a99fba66216..31ab9d57253a07220a51348d78e642bdd542618a 100644 |
| --- a/chrome/browser/policy/user_policy_token_cache.cc |
| +++ b/chrome/browser/policy/user_policy_token_cache.cc |
| @@ -11,13 +11,13 @@ namespace policy { |
| namespace em = enterprise_management; |
| -UserPolicyTokenCache::Delegate::~Delegate() {} |
| - |
| UserPolicyTokenCache::UserPolicyTokenCache( |
| - const base::WeakPtr<Delegate>& delegate, |
| + CloudPolicyData* data, |
| const FilePath& cache_file) |
| - : delegate_(delegate), |
| - cache_file_(cache_file) {} |
| + : data_(data), |
| + cache_file_(cache_file) { |
| + data_->AddObserver(this); |
| +} |
| void UserPolicyTokenCache::Load() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -38,6 +38,8 @@ void UserPolicyTokenCache::Store(const std::string& token, |
| } |
| UserPolicyTokenCache::~UserPolicyTokenCache() { |
| + if (data_ != NULL) |
| + data_->RemoveObserver(this); |
| } |
| void UserPolicyTokenCache::LoadOnFileThread() { |
| @@ -66,8 +68,9 @@ void UserPolicyTokenCache::LoadOnFileThread() { |
| void UserPolicyTokenCache::NotifyOnUIThread(const std::string& token, |
| const std::string& device_id) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - if (delegate_.get()) |
| - delegate_->OnTokenCacheLoaded(token, device_id); |
| + data_->set_device_id(device_id); |
|
pastarmovj
2011/07/06 12:11:57
Is it secure to assume data_ is not NULL here alwa
gfeher
2011/07/06 15:14:20
Good point. Done.
|
| + data_->SetDeviceToken(token, true); |
| + data_->NotifyDeviceTokenChanged(); |
| } |
| void UserPolicyTokenCache::StoreOnFileThread(const std::string& token, |
| @@ -93,4 +96,20 @@ void UserPolicyTokenCache::StoreOnFileThread(const std::string& token, |
| file_util::WriteFile(cache_file_, data.c_str(), data.length()); |
| } |
| +void UserPolicyTokenCache::OnDeviceTokenChanged() { |
| + if (!data_->device_token().empty() && |
| + !data_->device_id().empty()) { |
| + // This will also happen after loading the cache. |
| + Store(data_->device_token(), data_->device_id()); |
| + } |
| +} |
| + |
| +void UserPolicyTokenCache::OnCredentialsChanged() { |
| +} |
| + |
| +void UserPolicyTokenCache::OnPolicyDataGoingAway() { |
| + data_->RemoveObserver(this); |
| + data_ = NULL; |
| +} |
| + |
| } // namespace policy |