OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/policy/user_cloud_policy_manager.h" | 5 #include "chrome/browser/policy/user_cloud_policy_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 store_(store.Pass()) { | 49 store_(store.Pass()) { |
50 store_->Load(); | 50 store_->Load(); |
51 store_->AddObserver(this); | 51 store_->AddObserver(this); |
52 } | 52 } |
53 | 53 |
54 UserCloudPolicyManager::~UserCloudPolicyManager() { | 54 UserCloudPolicyManager::~UserCloudPolicyManager() { |
55 Shutdown(); | 55 Shutdown(); |
56 store_->RemoveObserver(this); | 56 store_->RemoveObserver(this); |
57 } | 57 } |
58 | 58 |
| 59 #if defined(OS_CHROMEOS) |
59 // static | 60 // static |
60 scoped_ptr<UserCloudPolicyManager> UserCloudPolicyManager::Create( | 61 scoped_ptr<UserCloudPolicyManager> UserCloudPolicyManager::Create( |
61 Profile* profile, | |
62 bool wait_for_policy_fetch) { | 62 bool wait_for_policy_fetch) { |
63 scoped_ptr<CloudPolicyStore> store = | 63 FilePath profile_dir; |
64 CloudPolicyStore::CreateUserPolicyStore(profile); | 64 CHECK(PathService::Get(chrome::DIR_USER_DATA, &profile_dir)); |
| 65 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 66 const FilePath policy_dir = |
| 67 profile_dir |
| 68 .Append(command_line->GetSwitchValuePath(switches::kLoginProfile)) |
| 69 .Append(kPolicyDir); |
| 70 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); |
| 71 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); |
| 72 |
| 73 scoped_ptr<CloudPolicyStore> store( |
| 74 new UserCloudPolicyStoreChromeOS( |
| 75 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), |
| 76 token_cache_file, policy_cache_file)); |
65 return scoped_ptr<UserCloudPolicyManager>( | 77 return scoped_ptr<UserCloudPolicyManager>( |
66 new UserCloudPolicyManager(store.Pass(), wait_for_policy_fetch)); | 78 new UserCloudPolicyManager(store.Pass(), wait_for_policy_fetch)); |
67 } | 79 } |
| 80 #endif |
68 | 81 |
69 void UserCloudPolicyManager::Initialize(PrefService* prefs, | 82 void UserCloudPolicyManager::Initialize(PrefService* prefs, |
70 DeviceManagementService* service, | 83 DeviceManagementService* service, |
71 UserAffiliation user_affiliation) { | 84 UserAffiliation user_affiliation) { |
72 DCHECK(service); | |
73 DCHECK(prefs); | |
74 DCHECK(!service_.get()); | 85 DCHECK(!service_.get()); |
75 prefs_ = prefs; | 86 prefs_ = prefs; |
76 scoped_ptr<CloudPolicyClient> client( | 87 scoped_ptr<CloudPolicyClient> client( |
77 new CloudPolicyClient(std::string(), std::string(), user_affiliation, | 88 new CloudPolicyClient(std::string(), std::string(), user_affiliation, |
78 POLICY_SCOPE_USER, NULL, service)); | 89 POLICY_SCOPE_USER, NULL, service)); |
79 service_.reset(new CloudPolicyService(client.Pass(), store_.get())); | 90 service_.reset(new CloudPolicyService(client.Pass(), store_.get())); |
80 service_->client()->AddObserver(this); | 91 service_->client()->AddObserver(this); |
81 | 92 |
82 if (wait_for_policy_fetch_) { | 93 if (wait_for_policy_fetch_) { |
83 // If we are supposed to wait for a policy fetch, we trigger an explicit | 94 // If we are supposed to wait for a policy fetch, we trigger an explicit |
(...skipping 27 matching lines...) Expand all Loading... |
111 // can be started. | 122 // can be started. |
112 if (service_.get() && !refresh_scheduler_.get() && prefs_) { | 123 if (service_.get() && !refresh_scheduler_.get() && prefs_) { |
113 refresh_scheduler_.reset( | 124 refresh_scheduler_.reset( |
114 new CloudPolicyRefreshScheduler( | 125 new CloudPolicyRefreshScheduler( |
115 service_->client(), store_.get(), prefs_, | 126 service_->client(), store_.get(), prefs_, |
116 prefs::kUserPolicyRefreshRate, | 127 prefs::kUserPolicyRefreshRate, |
117 MessageLoop::current()->message_loop_proxy())); | 128 MessageLoop::current()->message_loop_proxy())); |
118 } | 129 } |
119 } | 130 } |
120 | 131 |
121 bool UserCloudPolicyManager::IsClientRegistered() const { | |
122 if (!service_.get()) | |
123 return false; | |
124 return service_->client()->is_registered(); | |
125 } | |
126 | |
127 void UserCloudPolicyManager::RegisterClient(const std::string& access_token) { | |
128 DCHECK(cloud_policy_service()) << "Callers must invoke Initialize() first"; | |
129 if (!cloud_policy_service()->client()->is_registered()) | |
130 cloud_policy_service()->client()->Register(access_token); | |
131 } | |
132 | |
133 bool UserCloudPolicyManager::IsInitializationComplete() const { | 132 bool UserCloudPolicyManager::IsInitializationComplete() const { |
134 return store_->is_initialized() && !wait_for_policy_fetch_; | 133 return store_->is_initialized() && !wait_for_policy_fetch_; |
135 } | 134 } |
136 | 135 |
137 void UserCloudPolicyManager::RefreshPolicies() { | 136 void UserCloudPolicyManager::RefreshPolicies() { |
138 if (service_.get()) { | 137 if (service_.get()) { |
139 wait_for_policy_refresh_ = true; | 138 wait_for_policy_refresh_ = true; |
140 service_->RefreshPolicy( | 139 service_->RefreshPolicy( |
141 base::Bind(&UserCloudPolicyManager::OnRefreshComplete, | 140 base::Bind(&UserCloudPolicyManager::OnRefreshComplete, |
142 base::Unretained(this))); | 141 base::Unretained(this))); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 void UserCloudPolicyManager::OnInitialPolicyFetchComplete() { | 189 void UserCloudPolicyManager::OnInitialPolicyFetchComplete() { |
191 CancelWaitForPolicyFetch(); | 190 CancelWaitForPolicyFetch(); |
192 } | 191 } |
193 | 192 |
194 void UserCloudPolicyManager::OnRefreshComplete() { | 193 void UserCloudPolicyManager::OnRefreshComplete() { |
195 wait_for_policy_refresh_ = false; | 194 wait_for_policy_refresh_ = false; |
196 CheckAndPublishPolicy(); | 195 CheckAndPublishPolicy(); |
197 } | 196 } |
198 | 197 |
199 } // namespace policy | 198 } // namespace policy |
OLD | NEW |