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" | |
17 #include "base/platform_file.h" | 16 #include "base/platform_file.h" |
18 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
19 #include "chrome/browser/policy/policy_bundle.h" | 18 #include "chrome/browser/policy/policy_bundle.h" |
20 #include "content/public/browser/browser_thread.h" | |
21 | 19 |
22 namespace policy { | 20 namespace policy { |
23 | 21 |
24 namespace { | 22 namespace { |
25 | 23 |
26 // Subdirectories that contain the mandatory and recommended policies. | 24 // Subdirectories that contain the mandatory and recommended policies. |
27 const FilePath::CharType kMandatoryConfigDir[] = FILE_PATH_LITERAL("managed"); | 25 const FilePath::CharType kMandatoryConfigDir[] = FILE_PATH_LITERAL("managed"); |
28 const FilePath::CharType kRecommendedConfigDir[] = | 26 const FilePath::CharType kRecommendedConfigDir[] = |
29 FILE_PATH_LITERAL("recommended"); | 27 FILE_PATH_LITERAL("recommended"); |
30 | 28 |
31 } // namespace | 29 } // namespace |
32 | 30 |
33 ConfigDirPolicyLoader::ConfigDirPolicyLoader(const FilePath& config_dir, | 31 ConfigDirPolicyLoader::ConfigDirPolicyLoader(const FilePath& config_dir, |
34 PolicyScope scope) | 32 PolicyScope scope) |
35 : config_dir_(config_dir), | 33 : config_dir_(config_dir), |
36 scope_(scope) {} | 34 scope_(scope) {} |
37 | 35 |
38 ConfigDirPolicyLoader::~ConfigDirPolicyLoader() {} | 36 ConfigDirPolicyLoader::~ConfigDirPolicyLoader() {} |
39 | 37 |
40 void ConfigDirPolicyLoader::InitOnFile() { | 38 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; | |
48 base::files::FilePathWatcher::Callback callback = | 39 base::files::FilePathWatcher::Callback callback = |
49 base::Bind(&ConfigDirPolicyLoader::OnFileUpdated, base::Unretained(this)); | 40 base::Bind(&ConfigDirPolicyLoader::OnFileUpdated, base::Unretained(this)); |
50 mandatory_watcher_.Watch(config_dir_.Append(kMandatoryConfigDir), callback); | 41 mandatory_watcher_.Watch(config_dir_.Append(kMandatoryConfigDir), callback); |
51 recommended_watcher_.Watch(config_dir_.Append(kRecommendedConfigDir), | 42 recommended_watcher_.Watch(config_dir_.Append(kRecommendedConfigDir), |
52 callback); | 43 callback); |
53 } | 44 } |
54 | 45 |
55 scoped_ptr<PolicyBundle> ConfigDirPolicyLoader::Load() { | 46 scoped_ptr<PolicyBundle> ConfigDirPolicyLoader::Load() { |
56 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 47 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
57 LoadFromPath(config_dir_.Append(kMandatoryConfigDir), | 48 LoadFromPath(config_dir_.Append(kMandatoryConfigDir), |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 182 } |
192 } | 183 } |
193 } | 184 } |
194 | 185 |
195 void ConfigDirPolicyLoader::OnFileUpdated(const FilePath& path, bool error) { | 186 void ConfigDirPolicyLoader::OnFileUpdated(const FilePath& path, bool error) { |
196 if (!error) | 187 if (!error) |
197 Reload(false); | 188 Reload(false); |
198 } | 189 } |
199 | 190 |
200 } // namespace policy | 191 } // namespace policy |
OLD | NEW |