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

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: 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 // Refresh rate sanity interval bounds.
22 const int64 kPolicyRefreshRateMinMs = 30 * 60 * 1000; // 30 minutes
23 const int64 kPolicyRefreshRateMaxMs = 24 * 60 * 60 * 1000; // 1 day
24
25 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management");
26 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token");
27 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy");
28
29 } // namespace
30
31 namespace policy {
32
33 ProfilePolicyConnector::ProfilePolicyConnector(Profile* profile)
34 : profile_(profile) {
35 // TODO(mnissler): We access the file system here. The cloud policy context
36 // below needs to do so anyway, since it needs to read the policy cache from
37 // disk. If this proves to be a problem, we need to do this initialization
38 // asynchronously on the file thread and put in synchronization that allows us
39 // to wait for the cache to be read during the browser startup code paths.
40 // Another option would be to provide a generic IO-safe initializer called
41 // from the PrefService that we could hook up with through the policy
42 // provider.
43 CommandLine* command_line = CommandLine::ForCurrentProcess();
44 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
45 FilePath policy_cache_dir(profile_->GetPath());
46 policy_cache_dir = policy_cache_dir.Append(kPolicyDir);
47 if (!file_util::CreateDirectory(policy_cache_dir)) {
48 LOG(WARNING) << "Failed to create policy state dir "
49 << policy_cache_dir.value()
50 << ", skipping cloud policy initialization.";
51 return;
52 }
53
54 identity_strategy.reset(new UserPolicyIdentityStrategy(
55 profile_,
56 policy_cache_dir.Append(kTokenCacheFile)));
57 cloud_policy_subsystem_.reset(new CloudPolicySubsystem(
58 policy_cache_dir.Append(kPolicyCacheFile),
59 identity_strategy.get()));
60 }
61 }
62
63 ProfilePolicyConnector::~ProfilePolicyConnector() {
64 cloud_policy_subsystem_.reset();
65 identity_strategy.reset();
66 }
67
68 void ProfilePolicyConnector::Initialize() {
69 if (cloud_policy_subsystem_.get()) {
70 cloud_policy_subsystem_->Initialize(profile_->GetPrefs(),
71 prefs::kPolicyUserPolicyRefreshRate,
72 profile_->GetRequestContext());
73 }
74 }
75
76 void ProfilePolicyConnector::Shutdown() {
77 if (cloud_policy_subsystem_.get())
78 cloud_policy_subsystem_->Shutdown();
79 }
80
81 ConfigurationPolicyProvider*
82 ProfilePolicyConnector::GetManagedPolicyProvider() {
83 if (cloud_policy_subsystem_.get())
84 return cloud_policy_subsystem_->GetManagedPolicyProvider();
85
86 return NULL;
87 }
88
89 ConfigurationPolicyProvider*
90 ProfilePolicyConnector::GetRecommendedPolicyProvider() {
91 if (cloud_policy_subsystem_.get())
92 return cloud_policy_subsystem_->GetRecommendedPolicyProvider();
93
94 return NULL;
95 }
96
97 // static
98 void ProfilePolicyConnector::RegisterPrefs(PrefService* user_prefs) {
99 user_prefs->RegisterIntegerPref(prefs::kPolicyUserPolicyRefreshRate,
100 kDefaultPolicyRefreshRateInMilliseconds);
101 }
102
103 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698