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

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

Issue 8499021: UserPolicyCache only becomes ready after policy has been fetched. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 9 years, 1 month 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
Index: chrome/browser/policy/user_policy_cache.cc
diff --git a/chrome/browser/policy/user_policy_cache.cc b/chrome/browser/policy/user_policy_cache.cc
index 3cf8da57bd513dadeb544b791e82ab5f9ad30d0d..b9fd81500f2837332792f89c62981038a7d28038 100644
--- a/chrome/browser/policy/user_policy_cache.cc
+++ b/chrome/browser/policy/user_policy_cache.cc
@@ -28,8 +28,11 @@ namespace policy {
void DecodePolicy(const em::CloudPolicySettings& policy,
PolicyMap* mandatory, PolicyMap* recommended);
-UserPolicyCache::UserPolicyCache(const FilePath& backing_file_path)
- : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
+UserPolicyCache::UserPolicyCache(const FilePath& backing_file_path,
+ bool wait_for_policy_fetch)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
+ disk_cache_ready_(false),
+ fetch_ready_(!wait_for_policy_fetch) {
disk_cache_ = new UserPolicyDiskCache(weak_ptr_factory_.GetWeakPtr(),
backing_file_path);
}
@@ -72,6 +75,13 @@ void UserPolicyCache::SetUnmanaged() {
disk_cache_->Store(cached_policy);
}
+void UserPolicyCache::SetFetchingDone() {
+ if (!fetch_ready_)
+ DVLOG(1) << "SetFetchingDone, cache is now fetch_ready_";
+ fetch_ready_ = true;
+ CheckIfReady();
+}
+
void UserPolicyCache::OnDiskCacheLoaded(
UserPolicyDiskCache::LoadResult result,
const em::CachedCloudPolicyResponse& cached_response) {
@@ -89,7 +99,8 @@ void UserPolicyCache::OnDiskCacheLoaded(
}
// Ready to feed policy up the chain!
- SetReady();
+ disk_cache_ready_ = true;
+ CheckIfReady();
}
bool UserPolicyCache::DecodePolicyData(const em::PolicyData& policy_data,
@@ -107,6 +118,11 @@ bool UserPolicyCache::DecodePolicyData(const em::PolicyData& policy_data,
return true;
}
+void UserPolicyCache::CheckIfReady() {
+ if (!IsReady() && disk_cache_ready_ && fetch_ready_)
+ SetReady();
+}
+
// Everything below is only needed for supporting old-style GenericNamedValue
// based policy data and can be removed once this support is no longer needed.

Powered by Google App Engine
This is Rietveld 408576698