OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 } | 315 } |
316 | 316 |
317 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( | 317 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( |
318 ConfigurationPolicyProvider* provider) | 318 ConfigurationPolicyProvider* provider) |
319 : provider_(provider), | 319 : provider_(provider), |
320 prefs_(new DictionaryValue()), | 320 prefs_(new DictionaryValue()), |
321 lower_priority_proxy_settings_overridden_(false), | 321 lower_priority_proxy_settings_overridden_(false), |
322 proxy_disabled_(false), | 322 proxy_disabled_(false), |
323 proxy_configuration_specified_(false), | 323 proxy_configuration_specified_(false), |
324 use_system_proxy_(false) { | 324 use_system_proxy_(false) { |
| 325 if (!provider_->Provide(this)) |
| 326 LOG(WARNING) << "Failed to get policy from provider."; |
| 327 FinalizeDefaultSearchPolicySettings(); |
325 } | 328 } |
326 | 329 |
327 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() {} | 330 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() {} |
328 | 331 |
329 PrefStore::PrefReadError ConfigurationPolicyPrefStore::ReadPrefs() { | 332 PrefStore::ReadResult ConfigurationPolicyPrefStore::GetValue( |
330 proxy_disabled_ = false; | 333 const std::string& key, |
331 proxy_configuration_specified_ = false; | 334 Value** value) const { |
332 lower_priority_proxy_settings_overridden_ = false; | 335 Value* configured_value = NULL; |
| 336 if (!prefs_->Get(key, &configured_value) || !configured_value) |
| 337 return READ_NO_VALUE; |
333 | 338 |
334 const bool success = (provider_ == NULL || provider_->Provide(this)); | 339 // Check whether there's a default value, which indicates READ_USE_DEFAULT |
335 FinalizeDefaultSearchPolicySettings(); | 340 // should be returned. |
336 return success ? PrefStore::PREF_READ_ERROR_NONE : | 341 if (configured_value->IsType(Value::TYPE_NULL)) |
337 PrefStore::PREF_READ_ERROR_OTHER; | 342 return READ_USE_DEFAULT; |
| 343 |
| 344 *value = configured_value; |
| 345 return READ_OK; |
338 } | 346 } |
339 | 347 |
340 void ConfigurationPolicyPrefStore::Apply(ConfigurationPolicyType policy, | 348 void ConfigurationPolicyPrefStore::Apply(ConfigurationPolicyType policy, |
341 Value* value) { | 349 Value* value) { |
342 if (ApplyProxyPolicy(policy, value)) | 350 if (ApplyProxyPolicy(policy, value)) |
343 return; | 351 return; |
344 | 352 |
345 if (ApplySyncPolicy(policy, value)) | 353 if (ApplySyncPolicy(policy, value)) |
346 return; | 354 return; |
347 | 355 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 // proxy-related command-line switches or set proxy-related prefs in an | 467 // proxy-related command-line switches or set proxy-related prefs in an |
460 // extension that are related, but not identical, to the ones set through | 468 // extension that are related, but not identical, to the ones set through |
461 // policy. | 469 // policy. |
462 if (!lower_priority_proxy_settings_overridden_ && | 470 if (!lower_priority_proxy_settings_overridden_ && |
463 (match_entry || | 471 (match_entry || |
464 policy == kPolicyProxyServerMode)) { | 472 policy == kPolicyProxyServerMode)) { |
465 ProxyPreferenceSet proxy_preference_set; | 473 ProxyPreferenceSet proxy_preference_set; |
466 GetProxyPreferenceSet(&proxy_preference_set); | 474 GetProxyPreferenceSet(&proxy_preference_set); |
467 for (ProxyPreferenceSet::const_iterator i = proxy_preference_set.begin(); | 475 for (ProxyPreferenceSet::const_iterator i = proxy_preference_set.begin(); |
468 i != proxy_preference_set.end(); ++i) { | 476 i != proxy_preference_set.end(); ++i) { |
469 prefs_->Set(*i, PrefStore::CreateUseDefaultSentinelValue()); | 477 // We use values of TYPE_NULL to mark preferences for which |
| 478 // READ_USE_DEFAULT should be returned by GetValue(). |
| 479 prefs_->Set(*i, Value::CreateNullValue()); |
470 } | 480 } |
471 lower_priority_proxy_settings_overridden_ = true; | 481 lower_priority_proxy_settings_overridden_ = true; |
472 } | 482 } |
473 | 483 |
474 // Translate the proxy policy into preferences. | 484 // Translate the proxy policy into preferences. |
475 if (policy == kPolicyProxyServerMode) { | 485 if (policy == kPolicyProxyServerMode) { |
476 int int_value; | 486 int int_value; |
477 bool proxy_auto_detect = false; | 487 bool proxy_auto_detect = false; |
478 if (value->GetAsInteger(&int_value)) { | 488 if (value->GetAsInteger(&int_value)) { |
479 result = true; | 489 result = true; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 std::string()); | 655 std::string()); |
646 return; | 656 return; |
647 } | 657 } |
648 } | 658 } |
649 // Required entries are not there. Remove any related entries. | 659 // Required entries are not there. Remove any related entries. |
650 RemovePreferencesOfMap(kDefaultSearchPolicyMap, | 660 RemovePreferencesOfMap(kDefaultSearchPolicyMap, |
651 arraysize(kDefaultSearchPolicyMap)); | 661 arraysize(kDefaultSearchPolicyMap)); |
652 } | 662 } |
653 | 663 |
654 } // namespace policy | 664 } // namespace policy |
OLD | NEW |