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_store_chromeos.h" | 5 #include "chrome/browser/policy/user_cloud_policy_store_chromeos.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | |
13 #include "base/file_util.h" | 12 #include "base/file_util.h" |
14 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
15 #include "base/path_service.h" | |
16 #include "chrome/browser/chromeos/login/user_manager.h" | 14 #include "chrome/browser/chromeos/login/user_manager.h" |
17 #include "chrome/browser/policy/proto/cloud_policy.pb.h" | 15 #include "chrome/browser/policy/proto/cloud_policy.pb.h" |
18 #include "chrome/browser/policy/proto/device_management_local.pb.h" | 16 #include "chrome/browser/policy/proto/device_management_local.pb.h" |
19 #include "chrome/browser/policy/user_policy_disk_cache.h" | 17 #include "chrome/browser/policy/user_policy_disk_cache.h" |
20 #include "chrome/browser/policy/user_policy_token_cache.h" | 18 #include "chrome/browser/policy/user_policy_token_cache.h" |
21 #include "chrome/common/chrome_paths.h" | |
22 #include "chrome/common/chrome_switches.h" | |
23 #include "chromeos/dbus/dbus_thread_manager.h" | |
24 #include "chromeos/dbus/session_manager_client.h" | 19 #include "chromeos/dbus/session_manager_client.h" |
25 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
26 #include "google_apis/gaia/gaia_auth_util.h" | 21 #include "google_apis/gaia/gaia_auth_util.h" |
27 | 22 |
28 namespace em = enterprise_management; | 23 namespace em = enterprise_management; |
29 | 24 |
30 namespace policy { | 25 namespace policy { |
31 | 26 |
32 namespace { | 27 namespace { |
33 // Subdirectory in the user's profile for storing user policies. | 28 // Subdirectory in the user's profile for storing user policies. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 170 } |
176 | 171 |
177 void UserCloudPolicyStoreChromeOS::Load() { | 172 void UserCloudPolicyStoreChromeOS::Load() { |
178 // Cancel all pending requests. | 173 // Cancel all pending requests. |
179 weak_factory_.InvalidateWeakPtrs(); | 174 weak_factory_.InvalidateWeakPtrs(); |
180 session_manager_client_->RetrieveUserPolicy( | 175 session_manager_client_->RetrieveUserPolicy( |
181 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyRetrieved, | 176 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyRetrieved, |
182 weak_factory_.GetWeakPtr())); | 177 weak_factory_.GetWeakPtr())); |
183 } | 178 } |
184 | 179 |
185 void UserCloudPolicyStoreChromeOS::RemoveStoredPolicy() { | |
186 // This should never be called on ChromeOS since it is not possible to sign | |
187 // out of a Profile. The underlying policy store is only removed if the | |
188 // Profile itself is deleted. | |
189 NOTREACHED(); | |
190 } | |
191 | |
192 void UserCloudPolicyStoreChromeOS::OnPolicyRetrieved( | 180 void UserCloudPolicyStoreChromeOS::OnPolicyRetrieved( |
193 const std::string& policy_blob) { | 181 const std::string& policy_blob) { |
194 if (policy_blob.empty()) { | 182 if (policy_blob.empty()) { |
195 // Policy fetch failed. Try legacy caches if we haven't done that already. | 183 // Policy fetch failed. Try legacy caches if we haven't done that already. |
196 if (!legacy_caches_loaded_ && legacy_loader_.get()) { | 184 if (!legacy_caches_loaded_ && legacy_loader_.get()) { |
197 legacy_caches_loaded_ = true; | 185 legacy_caches_loaded_ = true; |
198 legacy_loader_->Load( | 186 legacy_loader_->Load( |
199 base::Bind(&UserCloudPolicyStoreChromeOS::OnLegacyLoadFinished, | 187 base::Bind(&UserCloudPolicyStoreChromeOS::OnLegacyLoadFinished, |
200 weak_factory_.GetWeakPtr())); | 188 weak_factory_.GetWeakPtr())); |
201 } else { | 189 } else { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 // Tell the rest of the world that the policy load completed. | 339 // Tell the rest of the world that the policy load completed. |
352 NotifyStoreLoaded(); | 340 NotifyStoreLoaded(); |
353 } | 341 } |
354 | 342 |
355 // static | 343 // static |
356 void UserCloudPolicyStoreChromeOS::RemoveLegacyCacheDir(const FilePath& dir) { | 344 void UserCloudPolicyStoreChromeOS::RemoveLegacyCacheDir(const FilePath& dir) { |
357 if (file_util::PathExists(dir) && !file_util::Delete(dir, true)) | 345 if (file_util::PathExists(dir) && !file_util::Delete(dir, true)) |
358 LOG(ERROR) << "Failed to remove cache dir " << dir.value(); | 346 LOG(ERROR) << "Failed to remove cache dir " << dir.value(); |
359 } | 347 } |
360 | 348 |
361 // static | |
362 scoped_ptr<CloudPolicyStore> CloudPolicyStore::CreateUserPolicyStore( | |
363 Profile* profile, bool force_immediate_policy_load) { | |
364 // On ChromeOS, callers should never try to load policy synchronously | |
365 // (profile initialization is always asynchronous). | |
366 DCHECK(!force_immediate_policy_load); | |
367 FilePath profile_dir; | |
368 CHECK(PathService::Get(chrome::DIR_USER_DATA, &profile_dir)); | |
369 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
370 const FilePath policy_dir = | |
371 profile_dir | |
372 .Append(command_line->GetSwitchValuePath(switches::kLoginProfile)) | |
373 .Append(kPolicyDir); | |
374 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); | |
375 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); | |
376 | |
377 return scoped_ptr<CloudPolicyStore>(new UserCloudPolicyStoreChromeOS( | |
378 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), | |
379 token_cache_file, policy_cache_file)); | |
380 } | |
381 | |
382 } // namespace policy | 349 } // namespace policy |
OLD | NEW |