| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/storage/policy_value_store.h" | 5 #include "chrome/browser/extensions/api/storage/policy_value_store.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/api/storage/settings_namespace.h" | 9 #include "chrome/browser/extensions/api/storage/settings_namespace.h" |
| 10 #include "chrome/browser/policy/policy_map.h" | 10 #include "chrome/browser/policy/policy_map.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 PolicyValueStore::PolicyValueStore( | 31 PolicyValueStore::PolicyValueStore( |
| 32 const std::string& extension_id, | 32 const std::string& extension_id, |
| 33 const scoped_refptr<SettingsObserverList>& observers, | 33 const scoped_refptr<SettingsObserverList>& observers, |
| 34 scoped_ptr<ValueStore> delegate) | 34 scoped_ptr<ValueStore> delegate) |
| 35 : extension_id_(extension_id), | 35 : extension_id_(extension_id), |
| 36 observers_(observers), | 36 observers_(observers), |
| 37 delegate_(delegate.Pass()) {} | 37 delegate_(delegate.Pass()) {} |
| 38 | 38 |
| 39 PolicyValueStore::~PolicyValueStore() {} | 39 PolicyValueStore::~PolicyValueStore() {} |
| 40 | 40 |
| 41 void PolicyValueStore::SetCurrentPolicy(const policy::PolicyMap& policy, | 41 void PolicyValueStore::SetCurrentPolicy(const policy::PolicyMap& policy) { |
| 42 bool notify_if_changed) { | |
| 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 44 // Convert |policy| to a dictionary value. Only include mandatory policies | 43 // Convert |policy| to a dictionary value. Only include mandatory policies |
| 45 // for now. | 44 // for now. |
| 46 base::DictionaryValue current_policy; | 45 base::DictionaryValue current_policy; |
| 47 for (policy::PolicyMap::const_iterator it = policy.begin(); | 46 for (policy::PolicyMap::const_iterator it = policy.begin(); |
| 48 it != policy.end(); ++it) { | 47 it != policy.end(); ++it) { |
| 49 if (it->second.level == policy::POLICY_LEVEL_MANDATORY) { | 48 if (it->second.level == policy::POLICY_LEVEL_MANDATORY) { |
| 50 current_policy.SetWithoutPathExpansion( | 49 current_policy.SetWithoutPathExpansion( |
| 51 it->first, it->second.value->DeepCopy()); | 50 it->first, it->second.value->DeepCopy()); |
| 52 } | 51 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 86 |
| 88 // IGNORE_QUOTA because these settings aren't writable by the extension, and | 87 // IGNORE_QUOTA because these settings aren't writable by the extension, and |
| 89 // are configured by the domain administrator. | 88 // are configured by the domain administrator. |
| 90 ValueStore::WriteOptions options = ValueStore::IGNORE_QUOTA; | 89 ValueStore::WriteOptions options = ValueStore::IGNORE_QUOTA; |
| 91 result = delegate_->Set(options, current_policy); | 90 result = delegate_->Set(options, current_policy); |
| 92 if (!result->HasError()) { | 91 if (!result->HasError()) { |
| 93 changes.insert( | 92 changes.insert( |
| 94 changes.end(), result->changes().begin(), result->changes().end()); | 93 changes.end(), result->changes().begin(), result->changes().end()); |
| 95 } | 94 } |
| 96 | 95 |
| 97 if (!changes.empty() && notify_if_changed) { | 96 if (!changes.empty()) { |
| 98 observers_->Notify( | 97 observers_->Notify( |
| 99 &SettingsObserver::OnSettingsChanged, | 98 &SettingsObserver::OnSettingsChanged, |
| 100 extension_id_, | 99 extension_id_, |
| 101 settings_namespace::MANAGED, | 100 settings_namespace::MANAGED, |
| 102 ValueStoreChange::ToJson(changes)); | 101 ValueStoreChange::ToJson(changes)); |
| 103 } | 102 } |
| 104 } | 103 } |
| 105 | 104 |
| 106 void PolicyValueStore::DeleteStorage() { | 105 void PolicyValueStore::DeleteStorage() { |
| 107 // This is called from our owner, indicating that storage for this extension | 106 // This is called from our owner, indicating that storage for this extension |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 ValueStore::WriteResult PolicyValueStore::Remove( | 155 ValueStore::WriteResult PolicyValueStore::Remove( |
| 157 const std::vector<std::string>& keys) { | 156 const std::vector<std::string>& keys) { |
| 158 return MakeWriteResult(ReadOnlyError(util::NoKey())); | 157 return MakeWriteResult(ReadOnlyError(util::NoKey())); |
| 159 } | 158 } |
| 160 | 159 |
| 161 ValueStore::WriteResult PolicyValueStore::Clear() { | 160 ValueStore::WriteResult PolicyValueStore::Clear() { |
| 162 return MakeWriteResult(ReadOnlyError(util::NoKey())); | 161 return MakeWriteResult(ReadOnlyError(util::NoKey())); |
| 163 } | 162 } |
| 164 | 163 |
| 165 } // namespace extensions | 164 } // namespace extensions |
| OLD | NEW |