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

Side by Side Diff: chrome/browser/policy/profile_policy_connector.cc

Issue 6520008: Device policy infrastructure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address Mattias' comments Created 9 years, 10 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 (c) 2011 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 <algorithm>
6 #include <string>
7
8 #include "base/command_line.h"
9 #include "base/file_util.h"
10 #include "chrome/browser/policy/cloud_policy_subsystem.h"
11 #include "chrome/browser/policy/profile_policy_connector.h"
12 #include "chrome/browser/policy/user_policy_identity_strategy.h"
13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/net/url_request_context_getter.h"
17 #include "chrome/common/pref_names.h"
18
19 namespace {
20
21 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management");
22 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token");
23 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy");
24
25 } // namespace
26
27 namespace policy {
28
29 ProfilePolicyConnector::ProfilePolicyConnector(Profile* profile)
30 : profile_(profile) {
31 // TODO(mnissler): We access the file system here. The cloud policy context
32 // below needs to do so anyway, since it needs to read the policy cache from
33 // disk. If this proves to be a problem, we need to do this initialization
34 // asynchronously on the file thread and put in synchronization that allows us
35 // to wait for the cache to be read during the browser startup code paths.
36 // Another option would be to provide a generic IO-safe initializer called
37 // from the PrefService that we could hook up with through the policy
38 // provider.
39 CommandLine* command_line = CommandLine::ForCurrentProcess();
40 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
41 FilePath policy_cache_dir(profile_->GetPath());
42 policy_cache_dir = policy_cache_dir.Append(kPolicyDir);
43 if (!file_util::CreateDirectory(policy_cache_dir)) {
44 LOG(WARNING) << "Failed to create policy state dir "
45 << policy_cache_dir.value()
46 << ", skipping cloud policy initialization.";
47 return;
48 }
49
50 identity_strategy.reset(new UserPolicyIdentityStrategy(
51 profile_,
52 policy_cache_dir.Append(kTokenCacheFile)));
53 cloud_policy_subsystem_.reset(new CloudPolicySubsystem(
54 policy_cache_dir.Append(kPolicyCacheFile),
55 identity_strategy.get()));
56 }
57 }
58
59 ProfilePolicyConnector::~ProfilePolicyConnector() {
60 cloud_policy_subsystem_.reset();
61 identity_strategy.reset();
62 }
63
64 void ProfilePolicyConnector::Initialize() {
65 // TODO(jkummerow, mnissler): Move this out of the browser startup path.
66 if (cloud_policy_subsystem_.get()) {
67 cloud_policy_subsystem_->Initialize(profile_->GetPrefs(),
68 prefs::kPolicyUserPolicyRefreshRate,
69 profile_->GetRequestContext());
70 }
71 }
72
73 void ProfilePolicyConnector::Shutdown() {
74 if (cloud_policy_subsystem_.get())
75 cloud_policy_subsystem_->Shutdown();
76 }
77
78 ConfigurationPolicyProvider*
79 ProfilePolicyConnector::GetManagedCloudProvider() {
80 if (cloud_policy_subsystem_.get())
81 return cloud_policy_subsystem_->GetManagedPolicyProvider();
82
83 return NULL;
84 }
85
86 ConfigurationPolicyProvider*
87 ProfilePolicyConnector::GetRecommendedCloudProvider() {
88 if (cloud_policy_subsystem_.get())
89 return cloud_policy_subsystem_->GetRecommendedPolicyProvider();
90
91 return NULL;
92 }
93
94 // static
95 void ProfilePolicyConnector::RegisterPrefs(PrefService* user_prefs) {
96 user_prefs->RegisterIntegerPref(prefs::kPolicyUserPolicyRefreshRate,
97 kDefaultPolicyRefreshRateInMilliseconds);
98 }
99
100 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698