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/config_dir_policy_loader.h" | 5 #include "chrome/browser/policy/config_dir_policy_loader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/json/json_file_value_serializer.h" | 14 #include "base/json/json_file_value_serializer.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/message_loop.h" |
16 #include "base/platform_file.h" | 17 #include "base/platform_file.h" |
17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
18 #include "chrome/browser/policy/policy_bundle.h" | 19 #include "chrome/browser/policy/policy_bundle.h" |
| 20 #include "content/public/browser/browser_thread.h" |
19 | 21 |
20 namespace policy { | 22 namespace policy { |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 // Subdirectories that contain the mandatory and recommended policies. | 26 // Subdirectories that contain the mandatory and recommended policies. |
25 const FilePath::CharType kMandatoryConfigDir[] = FILE_PATH_LITERAL("managed"); | 27 const FilePath::CharType kMandatoryConfigDir[] = FILE_PATH_LITERAL("managed"); |
26 const FilePath::CharType kRecommendedConfigDir[] = | 28 const FilePath::CharType kRecommendedConfigDir[] = |
27 FILE_PATH_LITERAL("recommended"); | 29 FILE_PATH_LITERAL("recommended"); |
28 | 30 |
29 } // namespace | 31 } // namespace |
30 | 32 |
31 ConfigDirPolicyLoader::ConfigDirPolicyLoader(const FilePath& config_dir, | 33 ConfigDirPolicyLoader::ConfigDirPolicyLoader(const FilePath& config_dir, |
32 PolicyScope scope) | 34 PolicyScope scope) |
33 : config_dir_(config_dir), | 35 : config_dir_(config_dir), |
34 scope_(scope) {} | 36 scope_(scope) {} |
35 | 37 |
36 ConfigDirPolicyLoader::~ConfigDirPolicyLoader() {} | 38 ConfigDirPolicyLoader::~ConfigDirPolicyLoader() {} |
37 | 39 |
38 void ConfigDirPolicyLoader::InitOnFile() { | 40 void ConfigDirPolicyLoader::InitOnFile() { |
| 41 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 42 // Some unit tests create a File thread that shares a MessageLoop with the |
| 43 // UI thread, and this causes DCHECKs because IO operations aren't allowed on |
| 44 // that thread. So if this is running in the context of one of those tests, |
| 45 // just exit. |
| 46 if (!MessageLoop::current()->IsType(MessageLoop::TYPE_IO)) |
| 47 return; |
39 base::files::FilePathWatcher::Callback callback = | 48 base::files::FilePathWatcher::Callback callback = |
40 base::Bind(&ConfigDirPolicyLoader::OnFileUpdated, base::Unretained(this)); | 49 base::Bind(&ConfigDirPolicyLoader::OnFileUpdated, base::Unretained(this)); |
41 mandatory_watcher_.Watch(config_dir_.Append(kMandatoryConfigDir), callback); | 50 mandatory_watcher_.Watch(config_dir_.Append(kMandatoryConfigDir), callback); |
42 recommended_watcher_.Watch(config_dir_.Append(kRecommendedConfigDir), | 51 recommended_watcher_.Watch(config_dir_.Append(kRecommendedConfigDir), |
43 callback); | 52 callback); |
44 } | 53 } |
45 | 54 |
46 scoped_ptr<PolicyBundle> ConfigDirPolicyLoader::Load() { | 55 scoped_ptr<PolicyBundle> ConfigDirPolicyLoader::Load() { |
47 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 56 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
48 LoadFromPath(config_dir_.Append(kMandatoryConfigDir), | 57 LoadFromPath(config_dir_.Append(kMandatoryConfigDir), |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 191 } |
183 } | 192 } |
184 } | 193 } |
185 | 194 |
186 void ConfigDirPolicyLoader::OnFileUpdated(const FilePath& path, bool error) { | 195 void ConfigDirPolicyLoader::OnFileUpdated(const FilePath& path, bool error) { |
187 if (!error) | 196 if (!error) |
188 Reload(false); | 197 Reload(false); |
189 } | 198 } |
190 | 199 |
191 } // namespace policy | 200 } // namespace policy |
OLD | NEW |