Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/policy/profile_policy_connector.h" | 5 #include "chrome/browser/policy/profile_policy_connector.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/policy/browser_policy_connector.h" | 11 #include "chrome/browser/policy/browser_policy_connector.h" |
| 12 #include "chrome/browser/policy/cloud/cloud_policy_manager.h" | 12 #include "chrome/browser/policy/cloud/cloud_policy_manager.h" |
| 13 #include "chrome/browser/policy/configuration_policy_provider.h" | 13 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 14 #include "chrome/browser/policy/policy_service.h" | 14 #include "chrome/browser/policy/forwarding_policy_provider.h" |
| 15 #include "chrome/browser/policy/policy_service_impl.h" | |
| 15 | 16 |
| 16 #if defined(OS_CHROMEOS) | 17 #if defined(OS_CHROMEOS) |
| 17 #include "chrome/browser/chromeos/login/user.h" | 18 #include "chrome/browser/chromeos/login/user.h" |
| 18 #include "chrome/browser/chromeos/login/user_manager.h" | 19 #include "chrome/browser/chromeos/login/user_manager.h" |
| 19 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" | 20 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" |
| 20 #include "chrome/browser/chromeos/policy/login_profile_policy_provider.h" | 21 #include "chrome/browser/chromeos/policy/login_profile_policy_provider.h" |
| 21 #include "chrome/browser/policy/policy_service.h" | |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 namespace policy { | 24 namespace policy { |
| 25 | 25 |
| 26 ProfilePolicyConnector::ProfilePolicyConnector() | 26 ProfilePolicyConnector::ProfilePolicyConnector() |
| 27 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
| 28 : is_primary_user_(false) | 28 : is_primary_user_(false) |
| 29 #endif | 29 #endif |
| 30 {} | 30 {} |
| 31 | 31 |
| 32 ProfilePolicyConnector::~ProfilePolicyConnector() {} | 32 ProfilePolicyConnector::~ProfilePolicyConnector() {} |
| 33 | 33 |
| 34 void ProfilePolicyConnector::Init( | 34 void ProfilePolicyConnector::Init( |
| 35 bool force_immediate_load, | 35 bool force_immediate_load, |
| 36 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
| 37 const chromeos::User* user, | 37 const chromeos::User* user, |
| 38 #endif | |
| 38 SchemaRegistry* schema_registry, | 39 SchemaRegistry* schema_registry, |
| 39 #endif | |
| 40 CloudPolicyManager* user_cloud_policy_manager) { | 40 CloudPolicyManager* user_cloud_policy_manager) { |
| 41 // |providers| contains a list of the policy providers available for the | |
| 42 // PolicyService of this connector, in decreasing order of priority. | |
| 43 // | |
| 44 // Note: all the providers appended to this vector must eventually become | |
| 45 // initialized for every policy domain, otherwise some subsystems will never | |
| 46 // use the policies exposed by the PolicyService! | |
| 47 // The default ConfigurationPolicyProvider::IsInitializationComplete() | |
| 48 // result is true, so take care if a provider overrides that. | |
| 49 std::vector<ConfigurationPolicyProvider*> providers; | |
| 50 | |
| 41 BrowserPolicyConnector* connector = | 51 BrowserPolicyConnector* connector = |
| 42 g_browser_process->browser_policy_connector(); | 52 g_browser_process->browser_policy_connector(); |
| 43 // |providers| contains a list of the policy providers available for the | 53 |
| 44 // PolicyService of this connector. | 54 if (connector->GetPlatformProvider()) { |
|
Joao da Silva
2013/11/13 17:30:49
This was the fix the Android, because it doesn't h
| |
| 45 std::vector<ConfigurationPolicyProvider*> providers; | 55 forwarding_policy_provider_.reset( |
| 56 new ForwardingPolicyProvider(connector->GetPlatformProvider())); | |
| 57 forwarding_policy_provider_->Init(schema_registry); | |
| 58 providers.push_back(forwarding_policy_provider_.get()); | |
| 59 } | |
| 46 | 60 |
| 47 if (user_cloud_policy_manager) | 61 if (user_cloud_policy_manager) |
| 48 providers.push_back(user_cloud_policy_manager); | 62 providers.push_back(user_cloud_policy_manager); |
| 49 | 63 |
| 50 #if defined(OS_CHROMEOS) | 64 #if defined(OS_CHROMEOS) |
| 51 if (!user) { | 65 if (!user) { |
| 52 DCHECK(schema_registry); | 66 DCHECK(schema_registry); |
| 53 // This case occurs for the signin profile. | 67 // This case occurs for the signin profile. |
| 54 special_user_policy_provider_.reset( | 68 special_user_policy_provider_.reset( |
| 55 new LoginProfilePolicyProvider(connector->GetPolicyService())); | 69 new LoginProfilePolicyProvider(connector->GetPolicyService())); |
| 56 special_user_policy_provider_->Init(schema_registry); | 70 special_user_policy_provider_->Init(schema_registry); |
| 57 } else { | 71 } else { |
| 58 // |user| should never be NULL except for the signin profile. | 72 // |user| should never be NULL except for the signin profile. |
| 59 is_primary_user_ = user == chromeos::UserManager::Get()->GetPrimaryUser(); | 73 is_primary_user_ = user == chromeos::UserManager::Get()->GetPrimaryUser(); |
| 60 if (user->GetType() == chromeos::User::USER_TYPE_PUBLIC_ACCOUNT) { | 74 if (user->GetType() == chromeos::User::USER_TYPE_PUBLIC_ACCOUNT) { |
| 61 InitializeDeviceLocalAccountPolicyProvider(user->email(), | 75 InitializeDeviceLocalAccountPolicyProvider(user->email(), |
| 62 schema_registry); | 76 schema_registry); |
| 63 } | 77 } |
| 64 } | 78 } |
| 65 if (special_user_policy_provider_) | 79 if (special_user_policy_provider_) |
| 66 providers.push_back(special_user_policy_provider_.get()); | 80 providers.push_back(special_user_policy_provider_.get()); |
| 67 #endif | 81 #endif |
| 68 | 82 |
| 69 policy_service_ = connector->CreatePolicyService(providers); | 83 policy_service_.reset(new PolicyServiceImpl(providers)); |
| 70 | 84 |
| 71 #if defined(OS_CHROMEOS) | 85 #if defined(OS_CHROMEOS) |
| 72 if (is_primary_user_) { | 86 if (is_primary_user_) { |
| 73 if (user_cloud_policy_manager) | 87 if (user_cloud_policy_manager) |
| 74 connector->SetUserPolicyDelegate(user_cloud_policy_manager); | 88 connector->SetUserPolicyDelegate(user_cloud_policy_manager); |
| 75 else if (special_user_policy_provider_) | 89 else if (special_user_policy_provider_) |
| 76 connector->SetUserPolicyDelegate(special_user_policy_provider_.get()); | 90 connector->SetUserPolicyDelegate(special_user_policy_provider_.get()); |
| 77 } | 91 } |
| 78 #endif | 92 #endif |
| 79 } | 93 } |
| 80 | 94 |
| 81 void ProfilePolicyConnector::InitForTesting(scoped_ptr<PolicyService> service) { | 95 void ProfilePolicyConnector::InitForTesting(scoped_ptr<PolicyService> service) { |
| 82 policy_service_ = service.Pass(); | 96 policy_service_ = service.Pass(); |
| 83 } | 97 } |
| 84 | 98 |
| 85 void ProfilePolicyConnector::Shutdown() { | 99 void ProfilePolicyConnector::Shutdown() { |
| 86 #if defined(OS_CHROMEOS) | 100 #if defined(OS_CHROMEOS) |
| 87 if (is_primary_user_) | 101 if (is_primary_user_) |
| 88 g_browser_process->browser_policy_connector()->SetUserPolicyDelegate(NULL); | 102 g_browser_process->browser_policy_connector()->SetUserPolicyDelegate(NULL); |
| 89 if (special_user_policy_provider_) | 103 if (special_user_policy_provider_) |
| 90 special_user_policy_provider_->Shutdown(); | 104 special_user_policy_provider_->Shutdown(); |
| 91 #endif | 105 #endif |
| 106 if (forwarding_policy_provider_) | |
| 107 forwarding_policy_provider_->Shutdown(); | |
| 92 } | 108 } |
| 93 | 109 |
| 94 #if defined(OS_CHROMEOS) | 110 #if defined(OS_CHROMEOS) |
| 95 void ProfilePolicyConnector::InitializeDeviceLocalAccountPolicyProvider( | 111 void ProfilePolicyConnector::InitializeDeviceLocalAccountPolicyProvider( |
| 96 const std::string& username, | 112 const std::string& username, |
| 97 SchemaRegistry* schema_registry) { | 113 SchemaRegistry* schema_registry) { |
| 98 BrowserPolicyConnector* connector = | 114 BrowserPolicyConnector* connector = |
| 99 g_browser_process->browser_policy_connector(); | 115 g_browser_process->browser_policy_connector(); |
| 100 DeviceLocalAccountPolicyService* device_local_account_policy_service = | 116 DeviceLocalAccountPolicyService* device_local_account_policy_service = |
| 101 connector->GetDeviceLocalAccountPolicyService(); | 117 connector->GetDeviceLocalAccountPolicyService(); |
| 102 if (!device_local_account_policy_service) | 118 if (!device_local_account_policy_service) |
| 103 return; | 119 return; |
| 104 special_user_policy_provider_.reset(new DeviceLocalAccountPolicyProvider( | 120 special_user_policy_provider_.reset(new DeviceLocalAccountPolicyProvider( |
| 105 username, device_local_account_policy_service)); | 121 username, device_local_account_policy_service)); |
| 106 special_user_policy_provider_->Init(schema_registry); | 122 special_user_policy_provider_->Init(schema_registry); |
| 107 } | 123 } |
| 108 #endif | 124 #endif |
| 109 | 125 |
| 110 } // namespace policy | 126 } // namespace policy |
| OLD | NEW |