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

Side by Side Diff: chrome/browser/policy/configuration_policy_pref_store.cc

Issue 7096013: Allow device policy code to be optionally included. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make changes requested by torne. Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/policy/configuration_policy_pref_store.h" 5 #include "chrome/browser/policy/configuration_policy_pref_store.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 !iter->second || 841 !iter->second ||
842 iter->second->IsType(Value::TYPE_NULL) || 842 iter->second->IsType(Value::TYPE_NULL) ||
843 (iter->second->IsType(Value::TYPE_STRING) && 843 (iter->second->IsType(Value::TYPE_STRING) &&
844 iter->second->GetAsString(&tmp) && 844 iter->second->GetAsString(&tmp) &&
845 tmp.empty())) { 845 tmp.empty())) {
846 return false; 846 return false;
847 } 847 }
848 return true; 848 return true;
849 } 849 }
850 850
851 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( 851 // static
852 ConfigurationPolicyProvider* provider) 852 ConfigurationPolicyPrefStore* ConfigurationPolicyPrefStore::Create(
853 : provider_(provider), 853 ConfigurationPolicyProvider* provider) {
854 initialization_complete_(false) { 854 return new ConfigurationPolicyPrefStore(provider);
855 if (provider_) {
856 // Read initial policy.
857 policy_keeper_.reset(new ConfigurationPolicyPrefKeeper(provider));
858 registrar_.Init(provider_, this);
859 initialization_complete_ = provider->IsInitializationComplete();
860 } else {
861 initialization_complete_ = true;
862 }
863 } 855 }
864 856
865 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() { 857 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() {
866 } 858 }
867 859
868 void ConfigurationPolicyPrefStore::AddObserver(PrefStore::Observer* observer) { 860 void ConfigurationPolicyPrefStore::AddObserver(PrefStore::Observer* observer) {
869 observers_.AddObserver(observer); 861 observers_.AddObserver(observer);
870 } 862 }
871 863
872 void ConfigurationPolicyPrefStore::RemoveObserver( 864 void ConfigurationPolicyPrefStore::RemoveObserver(
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 #endif 1096 #endif
1105 }; 1097 };
1106 1098
1107 static ConfigurationPolicyProvider::PolicyDefinitionList policy_list = { 1099 static ConfigurationPolicyProvider::PolicyDefinitionList policy_list = {
1108 entries, 1100 entries,
1109 entries + arraysize(entries), 1101 entries + arraysize(entries),
1110 }; 1102 };
1111 return &policy_list; 1103 return &policy_list;
1112 } 1104 }
1113 1105
1106 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore(
1107 ConfigurationPolicyProvider* provider)
1108 : provider_(provider),
1109 initialization_complete_(false) {
1110 if (provider_) {
1111 // Read initial policy.
1112 policy_keeper_.reset(new ConfigurationPolicyPrefKeeper(provider));
1113 registrar_.Init(provider_, this);
1114 initialization_complete_ = provider->IsInitializationComplete();
1115 } else {
1116 initialization_complete_ = true;
1117 }
1118 }
1119
1114 void ConfigurationPolicyPrefStore::Refresh() { 1120 void ConfigurationPolicyPrefStore::Refresh() {
1115 if (!provider_) 1121 if (!provider_)
1116 return; 1122 return;
1117 1123
1118 // Construct a new keeper, determine what changed and swap the keeper in. 1124 // Construct a new keeper, determine what changed and swap the keeper in.
1119 scoped_ptr<ConfigurationPolicyPrefKeeper> new_keeper( 1125 scoped_ptr<ConfigurationPolicyPrefKeeper> new_keeper(
1120 new ConfigurationPolicyPrefKeeper(provider_)); 1126 new ConfigurationPolicyPrefKeeper(provider_));
1121 std::vector<std::string> changed_prefs; 1127 std::vector<std::string> changed_prefs;
1122 new_keeper->GetDifferingPrefPaths(policy_keeper_.get(), &changed_prefs); 1128 new_keeper->GetDifferingPrefPaths(policy_keeper_.get(), &changed_prefs);
1123 policy_keeper_.reset(new_keeper.release()); 1129 policy_keeper_.reset(new_keeper.release());
1124 1130
1125 // Send out change notifications. 1131 // Send out change notifications.
1126 for (std::vector<std::string>::const_iterator pref(changed_prefs.begin()); 1132 for (std::vector<std::string>::const_iterator pref(changed_prefs.begin());
1127 pref != changed_prefs.end(); 1133 pref != changed_prefs.end();
1128 ++pref) { 1134 ++pref) {
1129 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, 1135 FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
1130 OnPrefValueChanged(*pref)); 1136 OnPrefValueChanged(*pref));
1131 } 1137 }
1132 1138
1133 // Update the initialization flag. 1139 // Update the initialization flag.
1134 if (!initialization_complete_ && 1140 if (!initialization_complete_ &&
1135 provider_->IsInitializationComplete()) { 1141 provider_->IsInitializationComplete()) {
1136 initialization_complete_ = true; 1142 initialization_complete_ = true;
1137 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, 1143 FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
1138 OnInitializationCompleted(true)); 1144 OnInitializationCompleted(true));
1139 } 1145 }
1140 } 1146 }
1141 1147
1142 } // namespace policy 1148 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698