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

Side by Side Diff: chrome/browser/chromeos/policy/network_policy_service.cc

Issue 24153012: Fix cyclic dependency between ProfilePolicyConnector and PrefService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix some includes and nits. Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
(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) {
26 if (chromeos::ProfileHelper::IsSigninProfile(profile))
27 return;
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;
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.
Mattias Nissler (ping if slow) 2013/09/20 12:35:23 While at it, can you clarify the comment to say "o
pneubeck (no reviews) 2013/10/15 13:23:11 Done.
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.
Mattias Nissler (ping if slow) 2013/09/20 12:35:23 Why? This comment doesn't add any information, jus
pneubeck (no reviews) 2013/10/15 13:23:11 It's not obvious whether the returned Updater stor
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();
87 }
88
89 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698