Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 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 "chrome/browser/chromeos/policy/network_policy_service.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/prefs/pref_service.h" | |
| 9 #include "chrome/browser/browser_process.h" | |
| 10 #include "chrome/browser/chromeos/login/user.h" | |
| 11 #include "chrome/browser/chromeos/login/user_manager.h" | |
| 12 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" | |
| 13 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 14 #include "chrome/browser/policy/browser_policy_connector.h" | |
| 15 #include "chrome/common/pref_names.h" | |
| 16 #include "chromeos/network/network_handler.h" | |
| 17 #include "chromeos/network/onc/onc_certificate_importer_impl.h" | |
| 18 | |
| 19 namespace policy { | |
| 20 | |
| 21 NetworkPolicyService::~NetworkPolicyService() {} | |
| 22 | |
| 23 NetworkPolicyService::NetworkPolicyService(Profile* profile, | |
| 24 PolicyService* policy_service) | |
| 25 : user_prefs_(profile->GetPrefs()), weak_ptr_factory_(this) { | |
|
Joao da Silva
2013/09/20 13:00:01
Pass the Prefs in the ctor directly
pneubeck (no reviews)
2013/10/15 13:23:11
Done.
| |
| 26 if (chromeos::ProfileHelper::IsSigninProfile(profile)) | |
| 27 return; | |
|
Joao da Silva
2013/09/20 13:00:01
How about doing this check at the factory, and not
pneubeck (no reviews)
2013/10/15 13:23:11
Done.
| |
| 28 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | |
| 29 chromeos::User* user = user_manager->GetActiveUser(); | |
| 30 CHECK(user); | |
| 31 std::string username = user->email(); | |
| 32 bool is_primary_user = | |
| 33 chromeos::UserManager::Get()->GetLoggedInUsers().size() == 1; | |
| 34 if (!is_primary_user) | |
| 35 return; | |
|
Joao da Silva
2013/09/20 13:00:01
Move this to the factory as well?
That would mean
pneubeck (no reviews)
2013/10/15 13:23:11
Done. But instead, I stopped creating PolicyCertVe
| |
| 36 | |
| 37 BrowserPolicyConnector* connector = | |
| 38 g_browser_process->browser_policy_connector(); | |
| 39 bool allow_trusted_certs_from_policy = false; | |
| 40 // Allow trusted certs from policy only for managed regular accounts. | |
| 41 const bool is_managed = | |
| 42 connector->GetUserAffiliation(username) == USER_AFFILIATION_MANAGED; | |
| 43 if (is_managed && user->GetType() == chromeos::User::USER_TYPE_REGULAR) | |
| 44 allow_trusted_certs_from_policy = true; | |
| 45 | |
| 46 // A reference to |user| is stored by the NetworkConfigurationUpdater until | |
| 47 // the Updater is destructed during Shutdown. | |
| 48 network_configuration_updater_ = | |
| 49 UserNetworkConfigurationUpdater::CreateForUserPolicy( | |
| 50 allow_trusted_certs_from_policy, | |
| 51 *user, | |
| 52 scoped_ptr<chromeos::onc::CertificateImporter>( | |
| 53 new chromeos::onc::CertificateImporterImpl), | |
| 54 policy_service, | |
| 55 chromeos::NetworkHandler::Get() | |
| 56 ->managed_network_configuration_handler()); | |
| 57 } | |
| 58 | |
| 59 void NetworkPolicyService::SetPolicyCertVerifier( | |
| 60 PolicyCertVerifier* cert_verifier) { | |
| 61 if (network_configuration_updater_) | |
| 62 network_configuration_updater_->SetPolicyCertVerifier(cert_verifier); | |
| 63 } | |
| 64 | |
| 65 base::Closure NetworkPolicyService::GetPolicyCertTrustedCallback() { | |
| 66 return base::Bind(&NetworkPolicyService::SetUsedPolicyCertificatesOnce, | |
| 67 weak_ptr_factory_.GetWeakPtr()); | |
| 68 } | |
| 69 | |
| 70 void NetworkPolicyService::GetWebTrustedCertificates( | |
| 71 net::CertificateList* certs) const { | |
| 72 certs->clear(); | |
| 73 if (network_configuration_updater_) | |
| 74 network_configuration_updater_->GetWebTrustedCertificates(certs); | |
| 75 } | |
| 76 | |
| 77 bool NetworkPolicyService::UsedPolicyCertificates() { | |
| 78 return user_prefs_->GetBoolean(prefs::kUsedPolicyCertificatesOnce); | |
| 79 } | |
| 80 | |
| 81 void NetworkPolicyService::SetUsedPolicyCertificatesOnce() { | |
| 82 user_prefs_->SetBoolean(prefs::kUsedPolicyCertificatesOnce, true); | |
| 83 } | |
| 84 | |
| 85 void NetworkPolicyService::Shutdown() { | |
| 86 network_configuration_updater_.reset(); | |
|
Joao da Silva
2013/09/20 13:00:01
weak_ptr_factory_.InvalidateWeakPtrs()?
pneubeck (no reviews)
2013/10/15 13:23:11
Done.
| |
| 87 } | |
| 88 | |
| 89 } // namespace policy | |
| OLD | NEW |