OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/policy/browser_policy_connector.h" | 11 #include "chrome/browser/policy/browser_policy_connector.h" |
12 #include "chrome/browser/policy/cloud_policy_subsystem.h" | 12 #include "chrome/browser/policy/cloud_policy_subsystem.h" |
13 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 13 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
14 #include "chrome/browser/policy/profile_policy_connector.h" | 14 #include "chrome/browser/policy/profile_policy_connector.h" |
15 #include "chrome/browser/policy/user_policy_cache.h" | 15 #include "chrome/browser/policy/user_policy_cache.h" |
16 #include "chrome/browser/policy/user_policy_identity_strategy.h" | 16 #include "chrome/browser/policy/user_policy_identity_strategy.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/pref_names.h" | |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); | 24 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); |
24 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token"); | 25 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token"); |
25 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy"); | 26 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy"); |
26 | 27 |
27 const int64 kServiceInitializationStartupDelay = 2000; | 28 const int64 kServiceInitializationStartupDelay = 2000; |
28 | 29 |
29 } // namespace | 30 } // namespace |
30 | 31 |
31 namespace policy { | 32 namespace policy { |
32 | 33 |
33 ProfilePolicyConnector::ProfilePolicyConnector(Profile* profile) | 34 ProfilePolicyConnector::ProfilePolicyConnector(Profile* profile) |
34 : profile_(profile) { | 35 : profile_(profile) { |
35 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 36 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
36 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { | 37 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { |
37 FilePath policy_cache_dir(profile_->GetPath()); | 38 FilePath policy_cache_dir(profile_->GetPath()); |
38 policy_cache_dir = policy_cache_dir.Append(kPolicyDir); | 39 policy_cache_dir = policy_cache_dir.Append(kPolicyDir); |
39 | 40 |
40 identity_strategy_.reset(new UserPolicyIdentityStrategy( | 41 identity_strategy_.reset(new UserPolicyIdentityStrategy( |
41 profile_, | 42 profile_, |
42 policy_cache_dir.Append(kTokenCacheFile))); | 43 policy_cache_dir.Append(kTokenCacheFile))); |
44 | |
Mattias Nissler (ping if slow)
2011/05/31 12:35:53
why the added newline?
sfeuz
2011/05/31 12:52:18
Done.
| |
43 cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 45 cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
44 identity_strategy_.get(), | 46 identity_strategy_.get(), |
45 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile)))); | 47 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile)))); |
46 | 48 |
47 BrowserPolicyConnector* browser_connector = | 49 BrowserPolicyConnector* browser_connector = |
48 g_browser_process->browser_policy_connector(); | 50 g_browser_process->browser_policy_connector(); |
49 | 51 |
50 managed_cloud_provider_.reset(new MergingPolicyProvider( | 52 managed_cloud_provider_.reset(new MergingPolicyProvider( |
51 browser_connector->GetManagedCloudProvider(), | 53 browser_connector->GetManagedCloudProvider(), |
52 cloud_policy_subsystem_->GetManagedPolicyProvider())); | 54 cloud_policy_subsystem_->GetManagedPolicyProvider())); |
(...skipping 12 matching lines...) Expand all Loading... | |
65 | 67 |
66 void ProfilePolicyConnector::ScheduleServiceInitialization( | 68 void ProfilePolicyConnector::ScheduleServiceInitialization( |
67 int64 delay_milliseconds) { | 69 int64 delay_milliseconds) { |
68 if (cloud_policy_subsystem_.get()) | 70 if (cloud_policy_subsystem_.get()) |
69 cloud_policy_subsystem_->ScheduleServiceInitialization(delay_milliseconds); | 71 cloud_policy_subsystem_->ScheduleServiceInitialization(delay_milliseconds); |
70 } | 72 } |
71 | 73 |
72 void ProfilePolicyConnector::Initialize() { | 74 void ProfilePolicyConnector::Initialize() { |
73 if (identity_strategy_.get()) | 75 if (identity_strategy_.get()) |
74 identity_strategy_->LoadTokenCache(); | 76 identity_strategy_->LoadTokenCache(); |
75 if (cloud_policy_subsystem_.get()) | 77 if (cloud_policy_subsystem_.get()) { |
76 cloud_policy_subsystem_->Initialize(profile_->GetPrefs(), | 78 cloud_policy_subsystem_->Initialize(prefs::kUserPolicyRefreshRate, |
77 kServiceInitializationStartupDelay); | 79 kServiceInitializationStartupDelay); |
80 // Temporarily set the subsystem to listen to profile pref service, since | |
81 // we cannot yet serve user cloud policy to |local_state| and we don't want | |
82 // the profile reference in the subsystem. | |
83 profile_pref_registrar_.Init(profile_->GetPrefs()); | |
84 profile_pref_registrar_.Add(prefs::kUserPolicyRefreshRate, | |
85 cloud_policy_subsystem_.get()); | |
Mattias Nissler (ping if slow)
2011/05/31 12:35:53
indentation
sfeuz
2011/05/31 12:52:18
Done.
| |
86 } | |
78 } | 87 } |
79 | 88 |
80 void ProfilePolicyConnector::Shutdown() { | 89 void ProfilePolicyConnector::Shutdown() { |
81 if (cloud_policy_subsystem_.get()) | 90 if (cloud_policy_subsystem_.get()) { |
91 // Remove the temporary profile observer. | |
92 profile_pref_registrar_.RemoveAll(); | |
82 cloud_policy_subsystem_->Shutdown(); | 93 cloud_policy_subsystem_->Shutdown(); |
94 } | |
83 } | 95 } |
84 | 96 |
85 ConfigurationPolicyProvider* | 97 ConfigurationPolicyProvider* |
86 ProfilePolicyConnector::GetManagedCloudProvider() { | 98 ProfilePolicyConnector::GetManagedCloudProvider() { |
87 return managed_cloud_provider_.get(); | 99 return managed_cloud_provider_.get(); |
88 } | 100 } |
89 | 101 |
90 ConfigurationPolicyProvider* | 102 ConfigurationPolicyProvider* |
91 ProfilePolicyConnector::GetRecommendedCloudProvider() { | 103 ProfilePolicyConnector::GetRecommendedCloudProvider() { |
92 return recommended_cloud_provider_.get(); | 104 return recommended_cloud_provider_.get(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, | 166 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, |
155 observer_list_, OnProviderGoingAway()); | 167 observer_list_, OnProviderGoingAway()); |
156 browser_registrar_.reset(); | 168 browser_registrar_.reset(); |
157 profile_registrar_.reset(); | 169 profile_registrar_.reset(); |
158 browser_policy_provider_ = NULL; | 170 browser_policy_provider_ = NULL; |
159 profile_policy_provider_ = NULL; | 171 profile_policy_provider_ = NULL; |
160 } | 172 } |
161 } | 173 } |
162 | 174 |
163 } // namespace policy | 175 } // namespace policy |
OLD | NEW |