| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/cert/internal/cert_error_scoper.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "net/cert/internal/cert_error_params.h" | |
| 12 #include "net/cert/internal/cert_errors.h" | |
| 13 | |
| 14 namespace net { | |
| 15 | |
| 16 CertErrorScoper::CertErrorScoper(CertErrors* parent_errors) { | |
| 17 DCHECK(parent_errors); | |
| 18 parent_errors_ = parent_errors; | |
| 19 parent_scoper_ = parent_errors->SetScoper(this); | |
| 20 } | |
| 21 | |
| 22 CertErrorScoper::~CertErrorScoper() { | |
| 23 CertErrorScoper* prev = parent_errors_->SetScoper(parent_scoper_); | |
| 24 DCHECK_EQ(prev, this); | |
| 25 } | |
| 26 | |
| 27 CertErrorNode* CertErrorScoper::LazyGetRootNode() { | |
| 28 if (!root_node_) { | |
| 29 // Create the node. | |
| 30 auto root_node = BuildRootNode(); | |
| 31 root_node_ = root_node.get(); | |
| 32 | |
| 33 // Attach it to the node hiearchy (ownership of this node is passed off | |
| 34 // to its parent, which is ultimately rooted in the CertErrors object). | |
| 35 if (parent_scoper_) { | |
| 36 parent_scoper_->LazyGetRootNode()->AddChild(std::move(root_node)); | |
| 37 } else { | |
| 38 parent_errors_->nodes_.push_back(std::move(root_node)); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 return root_node_; | |
| 43 } | |
| 44 | |
| 45 CertErrorScoperNoParams::CertErrorScoperNoParams(CertErrors* parent_errors, | |
| 46 CertErrorId id) | |
| 47 : CertErrorScoper(parent_errors), id_(id) {} | |
| 48 | |
| 49 std::unique_ptr<CertErrorNode> CertErrorScoperNoParams::BuildRootNode() { | |
| 50 return base::MakeUnique<CertErrorNode>(CertErrorNodeType::TYPE_CONTEXT, id_, | |
| 51 nullptr); | |
| 52 } | |
| 53 | |
| 54 } // namespace net | |
| OLD | NEW |