Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Unified Diff: chrome/browser/policy/user_policy_token_cache.cc

Issue 7298012: Consolidate data storage and notifications in the cloud policy subsystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/policy/user_policy_token_cache.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e2341d88740b284a19cdff0ea078b875255b2040..74e06bc8605fd40dfccae62601329bb45757f378 100644
--- a/chrome/browser/policy/user_policy_token_cache.cc
+++ b/chrome/browser/policy/user_policy_token_cache.cc
@@ -7,6 +7,7 @@
#include "base/file_util.h"
#include "base/metrics/histogram.h"
#include "chrome/browser/policy/enterprise_metrics.h"
+#include "chrome/browser/policy/proto/device_management_local.pb.h"
#include "content/browser/browser_thread.h"
namespace {
@@ -31,13 +32,13 @@ namespace policy {
namespace em = enterprise_management;
-UserPolicyTokenCache::Delegate::~Delegate() {}
-
UserPolicyTokenCache::UserPolicyTokenCache(
- const base::WeakPtr<Delegate>& delegate,
+ const base::WeakPtr<CloudPolicyDataStore>& data_store,
const FilePath& cache_file)
- : delegate_(delegate),
- cache_file_(cache_file) {}
+ : data_store_(data_store),
+ cache_file_(cache_file) {
+ data_store_->AddObserver(this);
+}
void UserPolicyTokenCache::Load() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -58,6 +59,8 @@ void UserPolicyTokenCache::Store(const std::string& token,
}
UserPolicyTokenCache::~UserPolicyTokenCache() {
+ if (data_store_)
+ data_store_->RemoveObserver(this);
}
void UserPolicyTokenCache::LoadOnFileThread() {
@@ -89,8 +92,11 @@ 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);
+ if (data_store_) {
+ data_store_->set_device_id(device_id);
+ data_store_->SetDeviceToken(token, true);
+ data_store_->NotifyDeviceTokenChanged();
+ }
}
void UserPolicyTokenCache::StoreOnFileThread(const std::string& token,
@@ -124,4 +130,19 @@ void UserPolicyTokenCache::StoreOnFileThread(const std::string& token,
SampleUMA(kMetricTokenStoreSucceeded);
}
+void UserPolicyTokenCache::OnDeviceTokenChanged() {
+ if (!data_store_->device_token().empty() &&
+ !data_store_->device_id().empty()) {
+ // This will also happen after loading the cache.
+ Store(data_store_->device_token(), data_store_->device_id());
+ }
+}
+
+void UserPolicyTokenCache::OnCredentialsChanged() {
+}
+
+void UserPolicyTokenCache::OnDataStoreGoingAway() {
+ data_store_->RemoveObserver(this);
+}
+
} // namespace policy
« no previous file with comments | « chrome/browser/policy/user_policy_token_cache.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698