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

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

Issue 1902633006: Convert //components/policy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and use namespace alias Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/proxy_policy_provider.h" 5 #include "components/policy/core/common/proxy_policy_provider.h"
6 6
7 #include <memory>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "components/policy/core/common/policy_bundle.h" 11 #include "components/policy/core/common/policy_bundle.h"
12 12
13 namespace policy { 13 namespace policy {
14 14
15 ProxyPolicyProvider::ProxyPolicyProvider() : delegate_(NULL) {} 15 ProxyPolicyProvider::ProxyPolicyProvider() : delegate_(NULL) {}
16 16
17 ProxyPolicyProvider::~ProxyPolicyProvider() { 17 ProxyPolicyProvider::~ProxyPolicyProvider() {
18 DCHECK(!delegate_); 18 DCHECK(!delegate_);
19 } 19 }
20 20
21 void ProxyPolicyProvider::SetDelegate(ConfigurationPolicyProvider* delegate) { 21 void ProxyPolicyProvider::SetDelegate(ConfigurationPolicyProvider* delegate) {
22 if (delegate_) 22 if (delegate_)
23 delegate_->RemoveObserver(this); 23 delegate_->RemoveObserver(this);
24 delegate_ = delegate; 24 delegate_ = delegate;
25 if (delegate_) { 25 if (delegate_) {
26 delegate_->AddObserver(this); 26 delegate_->AddObserver(this);
27 OnUpdatePolicy(delegate_); 27 OnUpdatePolicy(delegate_);
28 } else { 28 } else {
29 UpdatePolicy(scoped_ptr<PolicyBundle>(new PolicyBundle())); 29 UpdatePolicy(std::unique_ptr<PolicyBundle>(new PolicyBundle()));
30 } 30 }
31 } 31 }
32 32
33 void ProxyPolicyProvider::Shutdown() { 33 void ProxyPolicyProvider::Shutdown() {
34 // Note: the delegate is not owned by the proxy provider, so this call is not 34 // Note: the delegate is not owned by the proxy provider, so this call is not
35 // forwarded. The same applies for the Init() call. 35 // forwarded. The same applies for the Init() call.
36 // Just drop the delegate without propagating updates here. 36 // Just drop the delegate without propagating updates here.
37 if (delegate_) { 37 if (delegate_) {
38 delegate_->RemoveObserver(this); 38 delegate_->RemoveObserver(this);
39 delegate_ = NULL; 39 delegate_ = NULL;
40 } 40 }
41 ConfigurationPolicyProvider::Shutdown(); 41 ConfigurationPolicyProvider::Shutdown();
42 } 42 }
43 43
44 void ProxyPolicyProvider::RefreshPolicies() { 44 void ProxyPolicyProvider::RefreshPolicies() {
45 if (delegate_) { 45 if (delegate_) {
46 delegate_->RefreshPolicies(); 46 delegate_->RefreshPolicies();
47 } else { 47 } else {
48 // Subtle: if a RefreshPolicies() call comes after Shutdown() then the 48 // Subtle: if a RefreshPolicies() call comes after Shutdown() then the
49 // current bundle should be served instead. This also does the right thing 49 // current bundle should be served instead. This also does the right thing
50 // if SetDelegate() was never called before. 50 // if SetDelegate() was never called before.
51 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); 51 std::unique_ptr<PolicyBundle> bundle(new PolicyBundle());
52 bundle->CopyFrom(policies()); 52 bundle->CopyFrom(policies());
53 UpdatePolicy(std::move(bundle)); 53 UpdatePolicy(std::move(bundle));
54 } 54 }
55 } 55 }
56 56
57 void ProxyPolicyProvider::OnUpdatePolicy( 57 void ProxyPolicyProvider::OnUpdatePolicy(
58 ConfigurationPolicyProvider* provider) { 58 ConfigurationPolicyProvider* provider) {
59 DCHECK_EQ(delegate_, provider); 59 DCHECK_EQ(delegate_, provider);
60 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); 60 std::unique_ptr<PolicyBundle> bundle(new PolicyBundle());
61 bundle->CopyFrom(delegate_->policies()); 61 bundle->CopyFrom(delegate_->policies());
62 UpdatePolicy(std::move(bundle)); 62 UpdatePolicy(std::move(bundle));
63 } 63 }
64 64
65 } // namespace policy 65 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698