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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/profile_policy_connector.cc
diff --git a/chrome/browser/policy/profile_policy_connector.cc b/chrome/browser/policy/profile_policy_connector.cc
new file mode 100644
index 0000000000000000000000000000000000000000..431aa26937cf9e3e08aaf85b0146dea6587a409e
--- /dev/null
+++ b/chrome/browser/policy/profile_policy_connector.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <algorithm>
+#include <string>
+
+#include "base/command_line.h"
+#include "base/file_util.h"
+#include "chrome/browser/policy/cloud_policy_subsystem.h"
+#include "chrome/browser/policy/profile_policy_connector.h"
+#include "chrome/browser/policy/user_policy_identity_strategy.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/net/url_request_context_getter.h"
+#include "chrome/common/pref_names.h"
+
+namespace {
+
+const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management");
+const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token");
+const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy");
+
+} // namespace
+
+namespace policy {
+
+ProfilePolicyConnector::ProfilePolicyConnector(Profile* profile)
+ : profile_(profile) {
+ // TODO(mnissler): We access the file system here. The cloud policy context
+ // below needs to do so anyway, since it needs to read the policy cache from
+ // disk. If this proves to be a problem, we need to do this initialization
+ // asynchronously on the file thread and put in synchronization that allows us
+ // to wait for the cache to be read during the browser startup code paths.
+ // Another option would be to provide a generic IO-safe initializer called
+ // from the PrefService that we could hook up with through the policy
+ // provider.
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
+ FilePath policy_cache_dir(profile_->GetPath());
+ policy_cache_dir = policy_cache_dir.Append(kPolicyDir);
+ if (!file_util::CreateDirectory(policy_cache_dir)) {
+ LOG(WARNING) << "Failed to create policy state dir "
+ << policy_cache_dir.value()
+ << ", skipping cloud policy initialization.";
+ return;
+ }
+
+ identity_strategy.reset(new UserPolicyIdentityStrategy(
+ profile_,
+ policy_cache_dir.Append(kTokenCacheFile)));
+ cloud_policy_subsystem_.reset(new CloudPolicySubsystem(
+ policy_cache_dir.Append(kPolicyCacheFile),
+ identity_strategy.get()));
+ }
+}
+
+ProfilePolicyConnector::~ProfilePolicyConnector() {
+ cloud_policy_subsystem_.reset();
+ identity_strategy.reset();
+}
+
+void ProfilePolicyConnector::Initialize() {
+ // TODO(jkummerow, mnissler): Move this out of the browser startup path.
+ if (cloud_policy_subsystem_.get()) {
+ cloud_policy_subsystem_->Initialize(profile_->GetPrefs(),
+ prefs::kPolicyUserPolicyRefreshRate,
+ profile_->GetRequestContext());
+ }
+}
+
+void ProfilePolicyConnector::Shutdown() {
+ if (cloud_policy_subsystem_.get())
+ cloud_policy_subsystem_->Shutdown();
+}
+
+ConfigurationPolicyProvider*
+ ProfilePolicyConnector::GetManagedCloudProvider() {
+ if (cloud_policy_subsystem_.get())
+ return cloud_policy_subsystem_->GetManagedPolicyProvider();
+
+ return NULL;
+}
+
+ConfigurationPolicyProvider*
+ ProfilePolicyConnector::GetRecommendedCloudProvider() {
+ if (cloud_policy_subsystem_.get())
+ return cloud_policy_subsystem_->GetRecommendedPolicyProvider();
+
+ return NULL;
+}
+
+// static
+void ProfilePolicyConnector::RegisterPrefs(PrefService* user_prefs) {
+ user_prefs->RegisterIntegerPref(prefs::kPolicyUserPolicyRefreshRate,
+ kDefaultPolicyRefreshRateInMilliseconds);
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698