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

Side by Side Diff: components/policy/core/browser/configuration_policy_handler.cc

Issue 309553011: Enable policy support for registering protocol handler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Issue_116119_pre
Patch Set: Fix for the windows compile error Created 6 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
OLDNEW
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 "components/policy/core/browser/configuration_policy_handler.h" 5 #include "components/policy/core/browser/configuration_policy_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 361
362 if (errors && !error.empty()) { 362 if (errors && !error.empty()) {
363 if (error_path.empty()) 363 if (error_path.empty())
364 error_path = "(ROOT)"; 364 error_path = "(ROOT)";
365 errors->AddError(policy_name_, error_path, error); 365 errors->AddError(policy_name_, error_path, error);
366 } 366 }
367 367
368 return result; 368 return result;
369 } 369 }
370 370
371 // SimpleSchemaValidatingPolicyHandler implementation --------------------------
372
373 SimpleSchemaValidatingPolicyHandler::SimpleSchemaValidatingPolicyHandler(
374 const char* policy_name,
375 const char* pref_path,
376 Schema schema,
377 SchemaOnErrorStrategy strategy,
378 RecommendedPermission recommended_permission,
379 MandatoryPermission mandatory_permission)
380 : SchemaValidatingPolicyHandler(policy_name,
381 schema.GetKnownProperty(policy_name),
382 strategy),
383 pref_path_(pref_path),
384 allow_recommended_(recommended_permission == RECOMMENDED_ALLOWED),
385 allow_mandatory_(mandatory_permission == MANDATORY_ALLOWED) {
386 }
387
388 SimpleSchemaValidatingPolicyHandler::~SimpleSchemaValidatingPolicyHandler() {
389 }
390
391 bool SimpleSchemaValidatingPolicyHandler::CheckPolicySettings(
392 const PolicyMap& policies,
393 PolicyErrorMap* errors) {
394 const PolicyMap::Entry* policy_entry = policies.Get(policy_name());
395 if (!policy_entry)
396 return true;
397 if ((policy_entry->level == policy::POLICY_LEVEL_MANDATORY &&
398 !allow_mandatory_) ||
399 (policy_entry->level == policy::POLICY_LEVEL_RECOMMENDED &&
400 !allow_recommended_)) {
401 if (errors)
402 errors->AddError(policy_name(), IDS_POLICY_LEVEL_ERROR);
403 return false;
404 }
405
406 return SchemaValidatingPolicyHandler::CheckPolicySettings(policies, errors);
407 }
408
409 void SimpleSchemaValidatingPolicyHandler::ApplyPolicySettings(
410 const PolicyMap& policies,
411 PrefValueMap* prefs) {
412 if (!pref_path_)
413 return;
414 const base::Value* value = policies.GetValue(policy_name());
415 if (value)
416 prefs->SetValue(pref_path_, value->DeepCopy());
417 }
418
371 // LegacyPoliciesDeprecatingPolicyHandler implementation ----------------------- 419 // LegacyPoliciesDeprecatingPolicyHandler implementation -----------------------
372 420
373 // TODO(binjin): Add a new common base class for SchemaValidatingPolicyHandler 421 // TODO(binjin): Add a new common base class for SchemaValidatingPolicyHandler
374 // and TypeCheckingPolicyHandler representing policy handlers for a single 422 // and TypeCheckingPolicyHandler representing policy handlers for a single
375 // policy, and use it as the type of |new_policy_handler|. 423 // policy, and use it as the type of |new_policy_handler|.
376 // http://crbug.com/345299 424 // http://crbug.com/345299
377 LegacyPoliciesDeprecatingPolicyHandler::LegacyPoliciesDeprecatingPolicyHandler( 425 LegacyPoliciesDeprecatingPolicyHandler::LegacyPoliciesDeprecatingPolicyHandler(
378 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers, 426 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers,
379 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler) 427 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler)
380 : legacy_policy_handlers_(legacy_policy_handlers.Pass()), 428 : legacy_policy_handlers_(legacy_policy_handlers.Pass()),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 for (handler = legacy_policy_handlers_.begin(); 464 for (handler = legacy_policy_handlers_.begin();
417 handler != legacy_policy_handlers_.end(); 465 handler != legacy_policy_handlers_.end();
418 ++handler) { 466 ++handler) {
419 if ((*handler)->CheckPolicySettings(policies, &scoped_errors)) 467 if ((*handler)->CheckPolicySettings(policies, &scoped_errors))
420 (*handler)->ApplyPolicySettings(policies, prefs); 468 (*handler)->ApplyPolicySettings(policies, prefs);
421 } 469 }
422 } 470 }
423 } 471 }
424 472
425 } // namespace policy 473 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698