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

Side by Side Diff: components/policy/core/common/cloud/cloud_policy_service.cc

Issue 762863002: Removed policy::PolicyNamespaceKey. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pass values in ctors Created 6 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
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/common/cloud/cloud_policy_service.h" 5 #include "components/policy/core/common/cloud/cloud_policy_service.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "policy/proto/device_management_backend.pb.h" 8 #include "policy/proto/device_management_backend.pb.h"
9 9
10 namespace em = enterprise_management; 10 namespace em = enterprise_management;
11 11
12 namespace policy { 12 namespace policy {
13 13
14 CloudPolicyService::CloudPolicyService(const PolicyNamespaceKey& policy_ns_key, 14 CloudPolicyService::CloudPolicyService(const std::string& policy_type,
15 const std::string& settings_entity_id,
15 CloudPolicyClient* client, 16 CloudPolicyClient* client,
16 CloudPolicyStore* store) 17 CloudPolicyStore* store)
17 : policy_ns_key_(policy_ns_key), 18 : policy_type_(policy_type),
19 settings_entity_id_(settings_entity_id),
18 client_(client), 20 client_(client),
19 store_(store), 21 store_(store),
20 refresh_state_(REFRESH_NONE), 22 refresh_state_(REFRESH_NONE),
21 initialization_complete_(false) { 23 initialization_complete_(false) {
22 client_->AddNamespaceToFetch(policy_ns_key_); 24 client_->AddPolicyTypeToFetch(policy_type_, settings_entity_id_);
23 client_->AddObserver(this); 25 client_->AddObserver(this);
24 store_->AddObserver(this); 26 store_->AddObserver(this);
25 27
26 // Make sure we initialize |client_| from the policy data that might be 28 // Make sure we initialize |client_| from the policy data that might be
27 // already present in |store_|. 29 // already present in |store_|.
28 OnStoreLoaded(store_); 30 OnStoreLoaded(store_);
29 } 31 }
30 32
31 CloudPolicyService::~CloudPolicyService() { 33 CloudPolicyService::~CloudPolicyService() {
32 client_->RemoveNamespaceToFetch(policy_ns_key_); 34 client_->RemovePolicyTypeToFetch(policy_type_, settings_entity_id_);
33 client_->RemoveObserver(this); 35 client_->RemoveObserver(this);
34 store_->RemoveObserver(this); 36 store_->RemoveObserver(this);
35 } 37 }
36 38
37 std::string CloudPolicyService::ManagedBy() const { 39 std::string CloudPolicyService::ManagedBy() const {
38 const em::PolicyData* policy = store_->policy(); 40 const em::PolicyData* policy = store_->policy();
39 if (policy) { 41 if (policy) {
40 std::string username = policy->username(); 42 std::string username = policy->username();
41 std::size_t pos = username.find('@'); 43 std::size_t pos = username.find('@');
42 if (pos != std::string::npos) 44 if (pos != std::string::npos)
(...skipping 14 matching lines...) Expand all
57 refresh_state_ = REFRESH_POLICY_FETCH; 59 refresh_state_ = REFRESH_POLICY_FETCH;
58 client_->FetchPolicy(); 60 client_->FetchPolicy();
59 } 61 }
60 62
61 void CloudPolicyService::OnPolicyFetched(CloudPolicyClient* client) { 63 void CloudPolicyService::OnPolicyFetched(CloudPolicyClient* client) {
62 if (client_->status() != DM_STATUS_SUCCESS) { 64 if (client_->status() != DM_STATUS_SUCCESS) {
63 RefreshCompleted(false); 65 RefreshCompleted(false);
64 return; 66 return;
65 } 67 }
66 68
67 const em::PolicyFetchResponse* policy = client_->GetPolicyFor(policy_ns_key_); 69 const em::PolicyFetchResponse* policy =
70 client_->GetPolicyFor(policy_type_, settings_entity_id_);
68 if (policy) { 71 if (policy) {
69 if (refresh_state_ != REFRESH_NONE) 72 if (refresh_state_ != REFRESH_NONE)
70 refresh_state_ = REFRESH_POLICY_STORE; 73 refresh_state_ = REFRESH_POLICY_STORE;
71 store_->Store(*policy, client->fetched_invalidation_version()); 74 store_->Store(*policy, client->fetched_invalidation_version());
72 } else { 75 } else {
73 RefreshCompleted(false); 76 RefreshCompleted(false);
74 } 77 }
75 } 78 }
76 79
77 void CloudPolicyService::OnRegistrationStateChanged(CloudPolicyClient* client) { 80 void CloudPolicyService::OnRegistrationStateChanged(CloudPolicyClient* client) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 154
152 void CloudPolicyService::AddObserver(Observer* observer) { 155 void CloudPolicyService::AddObserver(Observer* observer) {
153 observers_.AddObserver(observer); 156 observers_.AddObserver(observer);
154 } 157 }
155 158
156 void CloudPolicyService::RemoveObserver(Observer* observer) { 159 void CloudPolicyService::RemoveObserver(Observer* observer) {
157 observers_.RemoveObserver(observer); 160 observers_.RemoveObserver(observer);
158 } 161 }
159 162
160 } // namespace policy 163 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698