OLD | NEW |
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 "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" | 5 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/policy/cloud/cloud_policy_service.h" | 8 #include "chrome/browser/policy/cloud/cloud_policy_service.h" |
9 #include "chrome/browser/policy/policy_bundle.h" | 9 #include "chrome/browser/policy/policy_bundle.h" |
10 #include "chrome/browser/policy/policy_service.h" | 10 #include "chrome/browser/policy/policy_service.h" |
11 | 11 |
12 namespace policy { | 12 namespace policy { |
13 | 13 |
14 DeviceLocalAccountPolicyProvider::DeviceLocalAccountPolicyProvider( | 14 DeviceLocalAccountPolicyProvider::DeviceLocalAccountPolicyProvider( |
15 const std::string& account_id, | 15 const std::string& user_id, |
16 DeviceLocalAccountPolicyService* service) | 16 DeviceLocalAccountPolicyService* service) |
17 : account_id_(account_id), | 17 : user_id_(user_id), |
18 service_(service), | 18 service_(service), |
19 store_initialized_(false), | 19 store_initialized_(false), |
20 waiting_for_policy_refresh_(false), | 20 waiting_for_policy_refresh_(false), |
21 weak_factory_(this) { | 21 weak_factory_(this) { |
22 service_->AddObserver(this); | 22 service_->AddObserver(this); |
23 UpdateFromBroker(); | 23 UpdateFromBroker(); |
24 } | 24 } |
25 | 25 |
26 DeviceLocalAccountPolicyProvider::~DeviceLocalAccountPolicyProvider() { | 26 DeviceLocalAccountPolicyProvider::~DeviceLocalAccountPolicyProvider() { |
27 service_->RemoveObserver(this); | 27 service_->RemoveObserver(this); |
(...skipping 12 matching lines...) Expand all Loading... |
40 waiting_for_policy_refresh_ = true; | 40 waiting_for_policy_refresh_ = true; |
41 broker->core()->service()->RefreshPolicy( | 41 broker->core()->service()->RefreshPolicy( |
42 base::Bind(&DeviceLocalAccountPolicyProvider::ReportPolicyRefresh, | 42 base::Bind(&DeviceLocalAccountPolicyProvider::ReportPolicyRefresh, |
43 weak_factory_.GetWeakPtr())); | 43 weak_factory_.GetWeakPtr())); |
44 } else { | 44 } else { |
45 UpdateFromBroker(); | 45 UpdateFromBroker(); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 void DeviceLocalAccountPolicyProvider::OnPolicyUpdated( | 49 void DeviceLocalAccountPolicyProvider::OnPolicyUpdated( |
50 const std::string& account_id) { | 50 const std::string& user_id) { |
51 if (account_id == account_id_) | 51 if (user_id == user_id_) |
52 UpdateFromBroker(); | 52 UpdateFromBroker(); |
53 } | 53 } |
54 | 54 |
55 void DeviceLocalAccountPolicyProvider::OnDeviceLocalAccountsChanged() { | 55 void DeviceLocalAccountPolicyProvider::OnDeviceLocalAccountsChanged() { |
56 UpdateFromBroker(); | 56 UpdateFromBroker(); |
57 } | 57 } |
58 | 58 |
59 DeviceLocalAccountPolicyBroker* DeviceLocalAccountPolicyProvider::GetBroker() { | 59 DeviceLocalAccountPolicyBroker* DeviceLocalAccountPolicyProvider::GetBroker() { |
60 return service_->GetBrokerForAccount(account_id_); | 60 return service_->GetBrokerForUser(user_id_); |
61 } | 61 } |
62 | 62 |
63 void DeviceLocalAccountPolicyProvider::ReportPolicyRefresh(bool success) { | 63 void DeviceLocalAccountPolicyProvider::ReportPolicyRefresh(bool success) { |
64 waiting_for_policy_refresh_ = false; | 64 waiting_for_policy_refresh_ = false; |
65 UpdateFromBroker(); | 65 UpdateFromBroker(); |
66 } | 66 } |
67 | 67 |
68 void DeviceLocalAccountPolicyProvider::UpdateFromBroker() { | 68 void DeviceLocalAccountPolicyProvider::UpdateFromBroker() { |
69 DeviceLocalAccountPolicyBroker* broker = GetBroker(); | 69 DeviceLocalAccountPolicyBroker* broker = GetBroker(); |
70 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 70 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
(...skipping 10 matching lines...) Expand all Loading... |
81 } else { | 81 } else { |
82 // Keep existing policy, but do send an update. | 82 // Keep existing policy, but do send an update. |
83 waiting_for_policy_refresh_ = false; | 83 waiting_for_policy_refresh_ = false; |
84 weak_factory_.InvalidateWeakPtrs(); | 84 weak_factory_.InvalidateWeakPtrs(); |
85 bundle->CopyFrom(policies()); | 85 bundle->CopyFrom(policies()); |
86 } | 86 } |
87 UpdatePolicy(bundle.Pass()); | 87 UpdatePolicy(bundle.Pass()); |
88 } | 88 } |
89 | 89 |
90 } // namespace policy | 90 } // namespace policy |
OLD | NEW |