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

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

Issue 5701003: Intorduce a separate preference for 'proxy server mode' (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix indentation nit Created 10 years 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) 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/prefs/proxy_prefs.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
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 return new ConfigurationPolicyPrefStore(provider); 395 return new ConfigurationPolicyPrefStore(provider);
398 } 396 }
399 397
400 // static 398 // static
401 ConfigurationPolicyPrefStore* 399 ConfigurationPolicyPrefStore*
402 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() { 400 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() {
403 return new ConfigurationPolicyPrefStore( 401 return new ConfigurationPolicyPrefStore(
404 g_configuration_policy_provider_keeper.Get().recommended_provider()); 402 g_configuration_policy_provider_keeper.Get().recommended_provider());
405 } 403 }
406 404
407 // static
408 void ConfigurationPolicyPrefStore::GetProxyPreferenceSet(
409 ProxyPreferenceSet* proxy_pref_set) {
410 proxy_pref_set->clear();
411 for (size_t current = 0; current < arraysize(kProxyPolicyMap); ++current) {
412 proxy_pref_set->insert(kProxyPolicyMap[current].preference_path);
413 }
414 proxy_pref_set->insert(prefs::kNoProxyServer);
415 proxy_pref_set->insert(prefs::kProxyAutoDetect);
416 }
417
418 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry* 405 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry*
419 ConfigurationPolicyPrefStore::FindPolicyInMap( 406 ConfigurationPolicyPrefStore::FindPolicyInMap(
420 ConfigurationPolicyType policy, 407 ConfigurationPolicyType policy,
421 const PolicyToPreferenceMapEntry* map, 408 const PolicyToPreferenceMapEntry* map,
422 int table_size) const { 409 int table_size) const {
423 for (int i = 0; i < table_size; ++i) { 410 for (int i = 0; i < table_size; ++i) {
424 if (map[i].policy_type == policy) 411 if (map[i].policy_type == policy)
425 return map + i; 412 return map + i;
426 } 413 }
427 return NULL; 414 return NULL;
(...skipping 20 matching lines...) Expand all
448 << "mismatch in provided and expected policy value for preferences" 435 << "mismatch in provided and expected policy value for preferences"
449 << map[current].preference_path << ". expected = " 436 << map[current].preference_path << ". expected = "
450 << map[current].value_type << ", actual = "<< value->GetType(); 437 << map[current].value_type << ", actual = "<< value->GetType();
451 prefs_->Set(map[current].preference_path, value); 438 prefs_->Set(map[current].preference_path, value);
452 return true; 439 return true;
453 } 440 }
454 } 441 }
455 return false; 442 return false;
456 } 443 }
457 444
445 bool ConfigurationPolicyPrefStore::NonNullValueExists(const std::string& path) {
446 Value* value = NULL;
447 if (!prefs_->Get(path, &value))
448 return false;
449 return value != NULL && !value->IsType(Value::TYPE_NULL);
450 }
451
458 bool ConfigurationPolicyPrefStore::ApplyProxyPolicy( 452 bool ConfigurationPolicyPrefStore::ApplyProxyPolicy(
459 ConfigurationPolicyType policy, 453 ConfigurationPolicyType policy,
460 Value* value) { 454 Value* value) {
461 bool result = false; 455
462 bool warn_about_proxy_disable_config = false; 456 // Indicates if the specified proxy server mode conflicts with other proxy
463 bool warn_about_proxy_system_config = false; 457 // preferences.
458 bool conflict = false;
459 // If |conflict| is true, then this variable specifies the selected proxy
460 // server mode that lead to the conflict.
Mattias Nissler (ping if slow) 2010/12/20 13:34:03 s/lead/led/
battre (please use the other) 2010/12/21 14:18:18 Gone.
461 ProxyPrefs::ProxyServerMode conflicting_mode = ProxyPrefs::MANUAL;
462
463 std::string preference_path;
Mattias Nissler (ping if slow) 2010/12/20 13:34:03 Could use a comment saying what this is used for.
battre (please use the other) 2010/12/21 14:18:18 Gone.
464 464
465 const PolicyToPreferenceMapEntry* match_entry = 465 const PolicyToPreferenceMapEntry* match_entry =
466 FindPolicyInMap(policy, kProxyPolicyMap, arraysize(kProxyPolicyMap)); 466 FindPolicyInMap(policy, kProxyPolicyMap, arraysize(kProxyPolicyMap));
467 467
468 // When the first proxy-related policy is applied, ALL proxy-related 468 // When the first proxy-related policy is applied, ALL proxy-related
469 // preferences that have been set by command-line switches, extensions, 469 // preferences that have been set by command-line switches, extensions,
470 // user preferences or any other mechanism are overridden. Otherwise 470 // user preferences or any other mechanism are overridden. Otherwise
471 // it's possible for a user to interfere with proxy policy by setting 471 // it's possible for a user to interfere with proxy policy by setting
472 // proxy-related command-line switches or set proxy-related prefs in an 472 // proxy-related command-line switches or set proxy-related prefs in an
473 // extension that are related, but not identical, to the ones set through 473 // extension that are related, but not identical, to the ones set through
474 // policy. 474 // policy.
475 if (!lower_priority_proxy_settings_overridden_ && 475 if (!lower_priority_proxy_settings_overridden_ &&
476 (match_entry || 476 (match_entry || policy == kPolicyProxyServerMode)) {
477 policy == kPolicyProxyServerMode)) { 477 for (size_t current = 0; current < arraysize(kProxyPolicyMap); ++current) {
478 ProxyPreferenceSet proxy_preference_set;
479 GetProxyPreferenceSet(&proxy_preference_set);
480 for (ProxyPreferenceSet::const_iterator i = proxy_preference_set.begin();
481 i != proxy_preference_set.end(); ++i) {
482 // We use values of TYPE_NULL to mark preferences for which 478 // We use values of TYPE_NULL to mark preferences for which
483 // READ_USE_DEFAULT should be returned by GetValue(). 479 // READ_USE_DEFAULT should be returned by GetValue().
484 prefs_->Set(*i, Value::CreateNullValue()); 480 prefs_->Set(kProxyPolicyMap[current].preference_path,
481 Value::CreateNullValue());
485 } 482 }
483 prefs_->Set(prefs::kProxyServerMode, Value::CreateNullValue());
486 lower_priority_proxy_settings_overridden_ = true; 484 lower_priority_proxy_settings_overridden_ = true;
487 } 485 }
488 486
489 // Translate the proxy policy into preferences.
490 if (policy == kPolicyProxyServerMode) { 487 if (policy == kPolicyProxyServerMode) {
488 preference_path = prefs::kProxyServerMode;
489
490 // Don't claim ownership of the policy if we find it invalid.
491 int int_value; 491 int int_value;
492 bool proxy_auto_detect = false; 492 if (!value->GetAsInteger(&int_value))
493 if (value->GetAsInteger(&int_value)) { 493 return false;
494 result = true; 494 ProxyPrefs::ProxyServerMode mode;
495 switch (int_value) { 495 if (!ProxyPrefs::IntToProxyMode(int_value, &mode))
496 case kPolicyNoProxyServerMode: 496 return false;
497 if (!proxy_disabled_) {
498 if (proxy_configuration_specified_)
499 warn_about_proxy_disable_config = true;
500 proxy_disabled_ = true;
501 }
502 break;
503 case kPolicyAutoDetectProxyMode:
504 proxy_auto_detect = true;
505 break;
506 case kPolicyManuallyConfiguredProxyMode:
507 break;
508 case kPolicyUseSystemProxyMode:
509 if (!use_system_proxy_) {
510 if (proxy_configuration_specified_)
511 warn_about_proxy_system_config = true;
512 use_system_proxy_ = true;
513 }
514 break;
515 default:
516 // Not a valid policy, don't assume ownership of |value|
517 result = false;
518 break;
519 }
520 497
521 if (int_value != kPolicyUseSystemProxyMode) { 498 // Determine if the applied proxy policy settings conflict and issue
522 prefs_->Set(prefs::kNoProxyServer, 499 // a corresponding warning if they do.
523 Value::CreateBooleanValue(proxy_disabled_)); 500 if (mode == ProxyPrefs::DISABLED || mode == ProxyPrefs::SYSTEM) {
524 prefs_->Set(prefs::kProxyAutoDetect, 501 for (size_t current = 0; current < arraysize(kProxyPolicyMap);
525 Value::CreateBooleanValue(proxy_auto_detect)); 502 ++current) {
503 if (NonNullValueExists(kProxyPolicyMap[current].preference_path)) {
504 conflict = true;
505 conflicting_mode = mode;
506 }
526 } 507 }
527 } 508 }
528 } else if (match_entry) { 509 } else if (match_entry) {
510 // Any proxy policy other than kPolicyProxyServerMode.
511
512 preference_path = match_entry->preference_path;
513
529 // Determine if the applied proxy policy settings conflict and issue 514 // Determine if the applied proxy policy settings conflict and issue
530 // a corresponding warning if they do. 515 // a corresponding warning if they do.
531 if (!proxy_configuration_specified_) { 516 int int_mode = 0;
532 if (proxy_disabled_) 517 if (prefs_->GetInteger(prefs::kProxyServerMode, &int_mode)) {
533 warn_about_proxy_disable_config = true; 518 if (ProxyPrefs::IntToProxyMode(int_mode, &conflicting_mode)) {
534 if (use_system_proxy_) 519 if (conflicting_mode == ProxyPrefs::DISABLED ||
535 warn_about_proxy_system_config = true; 520 conflicting_mode == ProxyPrefs::SYSTEM) {
536 proxy_configuration_specified_ = true; 521 conflict = true;
522 }
523 }
537 } 524 }
538 if (!use_system_proxy_ && !proxy_disabled_) { 525 } else {
539 prefs_->Set(match_entry->preference_path, value); 526 return false;
540 // The ownership of value has been passed on to |prefs_|,
541 // don't clean it up later.
542 value = NULL;
543 }
544 result = true;
545 } 527 }
546 528
547 if (warn_about_proxy_disable_config) { 529 // We accept |value| as a policy and take ownership of it.
548 LOG(WARNING) << "A centrally-administered policy disables the use of" 530 if (conflict) {
549 << " a proxy but also specifies an explicit proxy" 531 delete value;
550 << " configuration."; 532
533 if (conflicting_mode == ProxyPrefs::DISABLED) {
534 LOG(WARNING) << "A centrally-administered policy disables the use of"
535 << " a proxy but also specifies an explicit proxy"
536 << " configuration.";
537 } else if (conflicting_mode == ProxyPrefs::SYSTEM) {
538 LOG(WARNING) << "A centrally-administered policy dictates that the"
539 << " system proxy settings should be used but also specifies"
540 << " an explicit proxy configuration.";
541 } else {
542 NOTREACHED() << "Unexpected reason for a proxy policy conflict.";
543 }
Mattias Nissler (ping if slow) 2010/12/20 13:34:03 Hm, this whole logic for detecting we have a confl
battre (please use the other) 2010/12/21 14:18:18 I thought the same and implemented a Completed() m
544 } else {
545 prefs_->Set(preference_path, value);
551 } 546 }
552 547
553 if (warn_about_proxy_system_config) { 548 return true;
554 LOG(WARNING) << "A centrally-administered policy dictates that the"
555 << " system proxy settings should be used but also specifies"
556 << " an explicit proxy configuration.";
557 }
558
559 // If the policy was a proxy policy, cleanup |value|.
560 if (result && value)
561 delete value;
562 return result;
563 } 549 }
564 550
565 bool ConfigurationPolicyPrefStore::ApplySyncPolicy( 551 bool ConfigurationPolicyPrefStore::ApplySyncPolicy(
566 ConfigurationPolicyType policy, Value* value) { 552 ConfigurationPolicyType policy, Value* value) {
567 if (policy == kPolicySyncDisabled) { 553 if (policy == kPolicySyncDisabled) {
568 bool disable_sync; 554 bool disable_sync;
569 if (value->GetAsBoolean(&disable_sync) && disable_sync) 555 if (value->GetAsBoolean(&disable_sync) && disable_sync)
570 prefs_->Set(prefs::kSyncManaged, value); 556 prefs_->Set(prefs::kSyncManaged, value);
571 else 557 else
572 delete value; 558 delete value;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 std::string()); 646 std::string());
661 return; 647 return;
662 } 648 }
663 } 649 }
664 // Required entries are not there. Remove any related entries. 650 // Required entries are not there. Remove any related entries.
665 RemovePreferencesOfMap(kDefaultSearchPolicyMap, 651 RemovePreferencesOfMap(kDefaultSearchPolicyMap,
666 arraysize(kDefaultSearchPolicyMap)); 652 arraysize(kDefaultSearchPolicyMap));
667 } 653 }
668 654
669 } // namespace policy 655 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698