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/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/net/pref_proxy_config_service.h" | |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/policy/configuration_policy_provider.h" | 17 #include "chrome/browser/policy/configuration_policy_provider.h" |
17 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
18 #include "chrome/browser/policy/configuration_policy_provider_win.h" | 19 #include "chrome/browser/policy/configuration_policy_provider_win.h" |
19 #elif defined(OS_MACOSX) | 20 #elif defined(OS_MACOSX) |
20 #include "chrome/browser/policy/configuration_policy_provider_mac.h" | 21 #include "chrome/browser/policy/configuration_policy_provider_mac.h" |
21 #elif defined(OS_POSIX) | 22 #elif defined(OS_POSIX) |
22 #include "chrome/browser/policy/config_dir_policy_provider.h" | 23 #include "chrome/browser/policy/config_dir_policy_provider.h" |
23 #endif | 24 #endif |
24 #include "chrome/browser/policy/device_management_policy_provider.h" | 25 #include "chrome/browser/policy/device_management_policy_provider.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 entries, | 315 entries, |
315 entries + arraysize(entries), | 316 entries + arraysize(entries), |
316 }; | 317 }; |
317 return &policy_list; | 318 return &policy_list; |
318 } | 319 } |
319 | 320 |
320 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( | 321 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( |
321 ConfigurationPolicyProvider* provider) | 322 ConfigurationPolicyProvider* provider) |
322 : provider_(provider), | 323 : provider_(provider), |
323 prefs_(new DictionaryValue()), | 324 prefs_(new DictionaryValue()), |
324 lower_priority_proxy_settings_overridden_(false), | 325 lower_priority_proxy_settings_overridden_(false) { |
325 proxy_disabled_(false), | |
326 proxy_configuration_specified_(false), | |
327 use_system_proxy_(false) { | |
328 if (!provider_->Provide(this)) | 326 if (!provider_->Provide(this)) |
329 LOG(WARNING) << "Failed to get policy from provider."; | 327 LOG(WARNING) << "Failed to get policy from provider."; |
330 FinalizeDefaultSearchPolicySettings(); | 328 FinalizeDefaultSearchPolicySettings(); |
331 } | 329 } |
332 | 330 |
333 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() {} | 331 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() {} |
334 | 332 |
335 PrefStore::ReadResult ConfigurationPolicyPrefStore::GetValue( | 333 PrefStore::ReadResult ConfigurationPolicyPrefStore::GetValue( |
336 const std::string& key, | 334 const std::string& key, |
337 Value** value) const { | 335 Value** value) const { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 return new ConfigurationPolicyPrefStore(provider); | 391 return new ConfigurationPolicyPrefStore(provider); |
394 } | 392 } |
395 | 393 |
396 // static | 394 // static |
397 ConfigurationPolicyPrefStore* | 395 ConfigurationPolicyPrefStore* |
398 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() { | 396 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() { |
399 return new ConfigurationPolicyPrefStore( | 397 return new ConfigurationPolicyPrefStore( |
400 g_configuration_policy_provider_keeper.Get().recommended_provider()); | 398 g_configuration_policy_provider_keeper.Get().recommended_provider()); |
401 } | 399 } |
402 | 400 |
403 // static | |
404 void ConfigurationPolicyPrefStore::GetProxyPreferenceSet( | |
405 ProxyPreferenceSet* proxy_pref_set) { | |
406 proxy_pref_set->clear(); | |
407 for (size_t current = 0; current < arraysize(kProxyPolicyMap); ++current) { | |
408 proxy_pref_set->insert(kProxyPolicyMap[current].preference_path); | |
409 } | |
410 proxy_pref_set->insert(prefs::kNoProxyServer); | |
411 proxy_pref_set->insert(prefs::kProxyAutoDetect); | |
412 } | |
413 | |
414 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry* | 401 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry* |
415 ConfigurationPolicyPrefStore::FindPolicyInMap( | 402 ConfigurationPolicyPrefStore::FindPolicyInMap( |
416 ConfigurationPolicyType policy, | 403 ConfigurationPolicyType policy, |
417 const PolicyToPreferenceMapEntry* map, | 404 const PolicyToPreferenceMapEntry* map, |
418 int table_size) const { | 405 int table_size) const { |
419 for (int i = 0; i < table_size; ++i) { | 406 for (int i = 0; i < table_size; ++i) { |
420 if (map[i].policy_type == policy) | 407 if (map[i].policy_type == policy) |
421 return map + i; | 408 return map + i; |
422 } | 409 } |
423 return NULL; | 410 return NULL; |
(...skipping 20 matching lines...) Expand all Loading... | |
444 << "mismatch in provided and expected policy value for preferences" | 431 << "mismatch in provided and expected policy value for preferences" |
445 << map[current].preference_path << ". expected = " | 432 << map[current].preference_path << ". expected = " |
446 << map[current].value_type << ", actual = "<< value->GetType(); | 433 << map[current].value_type << ", actual = "<< value->GetType(); |
447 prefs_->Set(map[current].preference_path, value); | 434 prefs_->Set(map[current].preference_path, value); |
448 return true; | 435 return true; |
449 } | 436 } |
450 } | 437 } |
451 return false; | 438 return false; |
452 } | 439 } |
453 | 440 |
441 bool ConfigurationPolicyPrefStore::NonNullValueExists(const std::string& path) { | |
442 Value* value = NULL; | |
443 if (!prefs_->Get(path, &value)) | |
444 return false; | |
445 return value != NULL && !value->IsType(Value::TYPE_NULL); | |
446 } | |
447 | |
454 bool ConfigurationPolicyPrefStore::ApplyProxyPolicy( | 448 bool ConfigurationPolicyPrefStore::ApplyProxyPolicy( |
455 ConfigurationPolicyType policy, | 449 ConfigurationPolicyType policy, |
456 Value* value) { | 450 Value* value) { |
457 bool result = false; | 451 |
danno
2010/12/14 12:48:17
Add scoped_ptr<Value> for value here.
danno
2010/12/14 12:54:49
Nevermind (ignore).
| |
458 bool warn_about_proxy_disable_config = false; | 452 // Indicates if the specified proxy server mode conflicts with other proxy |
459 bool warn_about_proxy_system_config = false; | 453 // preferences. |
454 bool conflict = false; | |
455 // If |conflict| is true, then this variable specifies the selected proxy | |
456 // server mode that lead to the conflict. | |
457 PrefProxyConfigService::ProxyServerMode conflicting_mode = | |
458 PrefProxyConfigService::MANUAL; | |
459 | |
460 std::string preference_path; | |
460 | 461 |
461 const PolicyToPreferenceMapEntry* match_entry = | 462 const PolicyToPreferenceMapEntry* match_entry = |
462 FindPolicyInMap(policy, kProxyPolicyMap, arraysize(kProxyPolicyMap)); | 463 FindPolicyInMap(policy, kProxyPolicyMap, arraysize(kProxyPolicyMap)); |
463 | 464 |
464 // When the first proxy-related policy is applied, ALL proxy-related | 465 // When the first proxy-related policy is applied, ALL proxy-related |
465 // preferences that have been set by command-line switches, extensions, | 466 // preferences that have been set by command-line switches, extensions, |
466 // user preferences or any other mechanism are overridden. Otherwise | 467 // user preferences or any other mechanism are overridden. Otherwise |
467 // it's possible for a user to interfere with proxy policy by setting | 468 // it's possible for a user to interfere with proxy policy by setting |
468 // proxy-related command-line switches or set proxy-related prefs in an | 469 // proxy-related command-line switches or set proxy-related prefs in an |
469 // extension that are related, but not identical, to the ones set through | 470 // extension that are related, but not identical, to the ones set through |
470 // policy. | 471 // policy. |
471 if (!lower_priority_proxy_settings_overridden_ && | 472 if (!lower_priority_proxy_settings_overridden_ && |
472 (match_entry || | 473 (match_entry || policy == kPolicyProxyServerMode)) { |
473 policy == kPolicyProxyServerMode)) { | 474 for (size_t current = 0; current < arraysize(kProxyPolicyMap); ++current) { |
474 ProxyPreferenceSet proxy_preference_set; | |
475 GetProxyPreferenceSet(&proxy_preference_set); | |
476 for (ProxyPreferenceSet::const_iterator i = proxy_preference_set.begin(); | |
477 i != proxy_preference_set.end(); ++i) { | |
478 // We use values of TYPE_NULL to mark preferences for which | 475 // We use values of TYPE_NULL to mark preferences for which |
479 // READ_USE_DEFAULT should be returned by GetValue(). | 476 // READ_USE_DEFAULT should be returned by GetValue(). |
480 prefs_->Set(*i, Value::CreateNullValue()); | 477 prefs_->Set(kProxyPolicyMap[current].preference_path, |
478 Value::CreateNullValue()); | |
481 } | 479 } |
480 prefs_->Set(prefs::kProxyServerMode, Value::CreateNullValue()); | |
482 lower_priority_proxy_settings_overridden_ = true; | 481 lower_priority_proxy_settings_overridden_ = true; |
483 } | 482 } |
484 | 483 |
485 // Translate the proxy policy into preferences. | |
486 if (policy == kPolicyProxyServerMode) { | 484 if (policy == kPolicyProxyServerMode) { |
485 preference_path = prefs::kProxyServerMode; | |
486 | |
487 // Don't claim ownership of the policy if we find it invalid. | |
487 int int_value; | 488 int int_value; |
488 bool proxy_auto_detect = false; | 489 if (!value->GetAsInteger(&int_value)) |
489 if (value->GetAsInteger(&int_value)) { | 490 return false; |
490 result = true; | 491 PrefProxyConfigService::ProxyServerMode mode; |
491 switch (int_value) { | 492 if (!PrefProxyConfigService::IntToMode(int_value, &mode)) |
492 case kPolicyNoProxyServerMode: | 493 return false; |
493 if (!proxy_disabled_) { | |
494 if (proxy_configuration_specified_) | |
495 warn_about_proxy_disable_config = true; | |
496 proxy_disabled_ = true; | |
497 } | |
498 break; | |
499 case kPolicyAutoDetectProxyMode: | |
500 proxy_auto_detect = true; | |
501 break; | |
502 case kPolicyManuallyConfiguredProxyMode: | |
503 break; | |
504 case kPolicyUseSystemProxyMode: | |
505 if (!use_system_proxy_) { | |
506 if (proxy_configuration_specified_) | |
507 warn_about_proxy_system_config = true; | |
508 use_system_proxy_ = true; | |
509 } | |
510 break; | |
511 default: | |
512 // Not a valid policy, don't assume ownership of |value| | |
513 result = false; | |
514 break; | |
515 } | |
516 | 494 |
517 if (int_value != kPolicyUseSystemProxyMode) { | 495 // Determine if the applied proxy policy settings conflict and issue |
518 prefs_->Set(prefs::kNoProxyServer, | 496 // a corresponding warning if they do. |
519 Value::CreateBooleanValue(proxy_disabled_)); | 497 if (mode == PrefProxyConfigService::DISABLED || |
520 prefs_->Set(prefs::kProxyAutoDetect, | 498 mode == PrefProxyConfigService::SYSTEM) { |
521 Value::CreateBooleanValue(proxy_auto_detect)); | 499 for (size_t current = 0; current < arraysize(kProxyPolicyMap); |
500 ++current) { | |
501 if (NonNullValueExists(kProxyPolicyMap[current].preference_path)) { | |
502 conflict = true; | |
503 conflicting_mode = mode; | |
504 } | |
522 } | 505 } |
523 } | 506 } |
524 } else if (match_entry) { | 507 } else if (match_entry) { |
508 // Any proxy policy other than kPolicyProxyServerMode. | |
509 | |
510 preference_path = match_entry->preference_path; | |
511 | |
525 // Determine if the applied proxy policy settings conflict and issue | 512 // Determine if the applied proxy policy settings conflict and issue |
526 // a corresponding warning if they do. | 513 // a corresponding warning if they do. |
527 if (!proxy_configuration_specified_) { | 514 int int_mode = 0; |
528 if (proxy_disabled_) | 515 if (prefs_->GetInteger(prefs::kProxyServerMode, &int_mode)) { |
529 warn_about_proxy_disable_config = true; | 516 if (PrefProxyConfigService::IntToMode(int_mode, |
530 if (use_system_proxy_) | 517 &conflicting_mode)) { |
531 warn_about_proxy_system_config = true; | 518 if (conflicting_mode == PrefProxyConfigService::DISABLED || |
532 proxy_configuration_specified_ = true; | 519 conflicting_mode == PrefProxyConfigService::SYSTEM) { |
520 conflict = true; | |
521 } | |
522 } | |
533 } | 523 } |
534 if (!use_system_proxy_ && !proxy_disabled_) { | 524 } else { |
535 prefs_->Set(match_entry->preference_path, value); | 525 return false; |
536 // The ownership of value has been passed on to |prefs_|, | |
537 // don't clean it up later. | |
538 value = NULL; | |
539 } | |
540 result = true; | |
541 } | 526 } |
542 | 527 |
543 if (warn_about_proxy_disable_config) { | 528 // We accept |value| as a policy and take ownership of it. |
544 LOG(WARNING) << "A centrally-administered policy disables the use of" | 529 if (conflict) { |
545 << " a proxy but also specifies an explicit proxy" | 530 delete value; |
546 << " configuration."; | 531 |
532 if (conflicting_mode == PrefProxyConfigService::DISABLED) { | |
533 LOG(WARNING) << "A centrally-administered policy disables the use of" | |
534 << " a proxy but also specifies an explicit proxy" | |
535 << " configuration."; | |
536 } else if (conflicting_mode == PrefProxyConfigService::SYSTEM) { | |
537 LOG(WARNING) << "A centrally-administered policy dictates that the" | |
538 << " system proxy settings should be used but also specifies" | |
539 << " an explicit proxy configuration."; | |
540 } else { | |
541 NOTREACHED() << "Unexpected reason for a proxy policy conflict."; | |
542 } | |
543 } else { | |
544 prefs_->Set(preference_path, value); | |
547 } | 545 } |
548 | 546 |
549 if (warn_about_proxy_system_config) { | 547 return true; |
550 LOG(WARNING) << "A centrally-administered policy dictates that the" | |
551 << " system proxy settings should be used but also specifies" | |
552 << " an explicit proxy configuration."; | |
553 } | |
554 | |
555 // If the policy was a proxy policy, cleanup |value|. | |
556 if (result && value) | |
557 delete value; | |
558 return result; | |
559 } | 548 } |
560 | 549 |
561 bool ConfigurationPolicyPrefStore::ApplySyncPolicy( | 550 bool ConfigurationPolicyPrefStore::ApplySyncPolicy( |
562 ConfigurationPolicyType policy, Value* value) { | 551 ConfigurationPolicyType policy, Value* value) { |
563 if (policy == kPolicySyncDisabled) { | 552 if (policy == kPolicySyncDisabled) { |
564 bool disable_sync; | 553 bool disable_sync; |
565 if (value->GetAsBoolean(&disable_sync) && disable_sync) | 554 if (value->GetAsBoolean(&disable_sync) && disable_sync) |
566 prefs_->Set(prefs::kSyncManaged, value); | 555 prefs_->Set(prefs::kSyncManaged, value); |
567 else | 556 else |
568 delete value; | 557 delete value; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 std::string()); | 645 std::string()); |
657 return; | 646 return; |
658 } | 647 } |
659 } | 648 } |
660 // Required entries are not there. Remove any related entries. | 649 // Required entries are not there. Remove any related entries. |
661 RemovePreferencesOfMap(kDefaultSearchPolicyMap, | 650 RemovePreferencesOfMap(kDefaultSearchPolicyMap, |
662 arraysize(kDefaultSearchPolicyMap)); | 651 arraysize(kDefaultSearchPolicyMap)); |
663 } | 652 } |
664 | 653 |
665 } // namespace policy | 654 } // namespace policy |
OLD | NEW |