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

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

Issue 6312121: Add initial device policy infrastructure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup/compile fixes. 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 "base/command_line.h"
6 #include "chrome/browser/policy/cloud_policy_cache.h"
7 #include "chrome/browser/policy/cloud_policy_client.h"
8 #include "chrome/browser/policy/cloud_policy_context.h"
9 #include "chrome/browser/policy/cloud_policy_controller.h"
10 #include "chrome/browser/policy/configuration_policy_provider.h"
11 #include "chrome/browser/policy/device_management_service.h"
12 #include "chrome/browser/policy/device_token_fetcher.h"
13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/notification_details.h"
16 #include "chrome/common/notification_source.h"
17 #include "chrome/common/notification_type.h"
18 #include "chrome/common/pref_names.h"
19
20 namespace {
21
22 // Refresh rate sanity interval bounds.
23 const int64 kPolicyRefreshRateMinMs = 30 * 60 * 1000; // 30 minutes
24 const int64 kPolicyRefreshRateMaxMs = 24 * 60 * 60 * 1000; // 1 day
25
26 }
27
28 namespace policy {
29
30 CloudPolicyContext::CloudPolicyContext(const FilePath& policy_cache_file,
31 CloudPolicyController* controller)
32 : prefs_(NULL) {
33 CommandLine* command_line = CommandLine::ForCurrentProcess();
34 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
35 device_management_service_.reset(new DeviceManagementService(
36 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl)));
37 cloud_policy_cache_.reset(new CloudPolicyCache(policy_cache_file));
38 cloud_policy_cache_->LoadFromFile();
39
40 device_token_fetcher_.reset(
41 new DeviceTokenFetcher(device_management_service_.get(),
42 cloud_policy_cache_.get()));
43
44 cloud_policy_client_.reset(
45 new CloudPolicyClient(cloud_policy_cache_.get(),
46 device_management_service_->CreateBackend(),
47 device_token_fetcher_.get(),
48 controller));
49 }
50 }
51
52 CloudPolicyContext::~CloudPolicyContext() {
53 DCHECK(!prefs_);
54 cloud_policy_client_.reset();
55 device_token_fetcher_.reset();
56 cloud_policy_cache_.reset();
57 device_management_service_.reset();
58 }
59
60 void CloudPolicyContext::Initialize(PrefService* prefs,
61 URLRequestContextGetter* request_context) {
62 DCHECK(!prefs_);
63 prefs_ = prefs;
64
65 if (device_management_service_.get())
66 device_management_service_->Initialize(request_context);
67
68 policy_refresh_rate_.Init(prefs::kPolicyRefreshRate, prefs_, this);
69 UpdatePolicyRefreshRate();
70 }
71
72 void CloudPolicyContext::Shutdown() {
73 if (device_management_service_.get())
74 device_management_service_->Shutdown();
75 cloud_policy_client_.reset();
76 cloud_policy_cache_.reset();
77 policy_refresh_rate_.Destroy();
78 prefs_ = NULL;
79 }
80
81 ConfigurationPolicyProvider* CloudPolicyContext::GetManagedPolicyProvider() {
82 if (cloud_policy_cache_.get())
83 return cloud_policy_cache_->GetManagedPolicyProvider();
84
85 return NULL;
86 }
87
88 ConfigurationPolicyProvider*
89 CloudPolicyContext::GetRecommendedPolicyProvider() {
90 if (cloud_policy_cache_.get())
91 return cloud_policy_cache_->GetRecommendedPolicyProvider();
92
93 return NULL;
94 }
95
96 // static
97 void CloudPolicyContext::RegisterPrefs(PrefService* user_prefs) {
98 user_prefs->RegisterIntegerPref(prefs::kPolicyRefreshRate,
99 kDefaultPolicyRefreshRateInMilliseconds);
100 }
101
102 void CloudPolicyContext::UpdatePolicyRefreshRate() {
103 if (cloud_policy_client_.get()) {
104 // Clamp to sane values.
105 int64 refresh_rate = policy_refresh_rate_.GetValue();
106 refresh_rate = std::max(kPolicyRefreshRateMinMs, refresh_rate);
107 refresh_rate = std::min(kPolicyRefreshRateMaxMs, refresh_rate);
108 cloud_policy_client_->SetRefreshRate(refresh_rate);
109 }
110 }
111
112 void CloudPolicyContext::Observe(NotificationType type,
113 const NotificationSource& source,
114 const NotificationDetails& details) {
115 if (type == NotificationType::PREF_CHANGED &&
116 prefs::kPolicyRefreshRate == *(Details<std::string>(details).ptr()) &&
117 prefs_ == Source<PrefService>(source).ptr()) {
118 UpdatePolicyRefreshRate();
119 } else {
120 NOTREACHED();
121 }
122 }
123
124 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698