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

Side by Side Diff: components/policy/core/common/schema.cc

Issue 50143010: Added a SchemaMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-5-ref-counted-schema
Patch Set: rebase Created 7 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/common/schema.h" 5 #include "components/policy/core/common/schema.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 node_ = schema.node_; 292 node_ = schema.node_;
293 return *this; 293 return *this;
294 } 294 }
295 295
296 // static 296 // static
297 Schema Schema::Wrap(const SchemaData* data) { 297 Schema Schema::Wrap(const SchemaData* data) {
298 scoped_refptr<const InternalStorage> storage = InternalStorage::Wrap(data); 298 scoped_refptr<const InternalStorage> storage = InternalStorage::Wrap(data);
299 return Schema(storage, storage->root_node()); 299 return Schema(storage, storage->root_node());
300 } 300 }
301 301
302 bool Schema::Validate(const base::Value& value) const {
303 if (!valid()) {
304 // Schema not found, invalid entry.
305 return false;
306 }
307
308 if (!value.IsType(type()))
309 return false;
310
311 const base::DictionaryValue* dict = NULL;
312 const base::ListValue* list = NULL;
313 if (value.GetAsDictionary(&dict)) {
314 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd();
315 it.Advance()) {
316 if (!GetProperty(it.key()).Validate(it.value()))
317 return false;
318 }
319 } else if (value.GetAsList(&list)) {
320 for (base::ListValue::const_iterator it = list->begin();
321 it != list->end(); ++it) {
322 if (!*it || !GetItems().Validate(**it))
323 return false;
324 }
325 }
326
327 return true;
328 }
329
302 // static 330 // static
303 Schema Schema::Parse(const std::string& content, std::string* error) { 331 Schema Schema::Parse(const std::string& content, std::string* error) {
304 // Validate as a generic JSON schema. 332 // Validate as a generic JSON schema.
305 scoped_ptr<base::DictionaryValue> dict = 333 scoped_ptr<base::DictionaryValue> dict =
306 JSONSchemaValidator::IsValidSchema(content, error); 334 JSONSchemaValidator::IsValidSchema(content, error);
307 if (!dict) 335 if (!dict)
308 return Schema(); 336 return Schema();
309 337
310 // Validate the main type. 338 // Validate the main type.
311 std::string string_value; 339 std::string string_value;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 406
379 Schema Schema::GetItems() const { 407 Schema Schema::GetItems() const {
380 CHECK(valid()); 408 CHECK(valid());
381 CHECK_EQ(base::Value::TYPE_LIST, type()); 409 CHECK_EQ(base::Value::TYPE_LIST, type());
382 if (node_->extra == kInvalid) 410 if (node_->extra == kInvalid)
383 return Schema(); 411 return Schema();
384 return Schema(storage_, storage_->schema(node_->extra)); 412 return Schema(storage_, storage_->schema(node_->extra));
385 } 413 }
386 414
387 } // namespace policy 415 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/schema.h ('k') | components/policy/core/common/schema_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698