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/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_util.h" | |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
13 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" | 18 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" |
18 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" | 19 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" |
19 #include "chrome/browser/chromeos/login/startup_utils.h" | 20 #include "chrome/browser/chromeos/login/startup_utils.h" |
20 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" | 21 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
21 #include "chrome/browser/chromeos/policy/device_status_collector.h" | 22 #include "chrome/browser/chromeos/policy/device_status_collector.h" |
22 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 23 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
23 #include "chrome/browser/chromeos/policy/heartbeat_scheduler.h" | 24 #include "chrome/browser/chromeos/policy/heartbeat_scheduler.h" |
24 #include "chrome/browser/chromeos/policy/remote_commands/device_commands_factory _chromeos.h" | 25 #include "chrome/browser/chromeos/policy/remote_commands/device_commands_factory _chromeos.h" |
25 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" | 26 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" |
26 #include "chrome/browser/chromeos/policy/status_uploader.h" | 27 #include "chrome/browser/chromeos/policy/status_uploader.h" |
28 #include "chrome/browser/chromeos/policy/system_log_uploader.h" | |
29 #include "chrome/browser/chromeos/policy/upload_job_impl.h" | |
30 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | |
31 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " | |
27 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
28 #include "chromeos/chromeos_constants.h" | 33 #include "chromeos/chromeos_constants.h" |
29 #include "chromeos/chromeos_switches.h" | 34 #include "chromeos/chromeos_switches.h" |
30 #include "chromeos/system/statistics_provider.h" | 35 #include "chromeos/system/statistics_provider.h" |
31 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 36 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
32 #include "components/policy/core/common/cloud/cloud_policy_service.h" | 37 #include "components/policy/core/common/cloud/cloud_policy_service.h" |
33 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 38 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
34 #include "components/policy/core/common/remote_commands/remote_commands_factory. h" | 39 #include "components/policy/core/common/remote_commands/remote_commands_factory. h" |
35 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
36 #include "crypto/sha2.h" | 41 #include "crypto/sha2.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 | 100 |
96 return value; | 101 return value; |
97 } | 102 } |
98 | 103 |
99 // Checks whether forced re-enrollment is enabled. | 104 // Checks whether forced re-enrollment is enabled. |
100 bool ForcedReEnrollmentEnabled() { | 105 bool ForcedReEnrollmentEnabled() { |
101 return chromeos::AutoEnrollmentController::GetMode() == | 106 return chromeos::AutoEnrollmentController::GetMode() == |
102 chromeos::AutoEnrollmentController::MODE_FORCED_RE_ENROLLMENT; | 107 chromeos::AutoEnrollmentController::MODE_FORCED_RE_ENROLLMENT; |
103 } | 108 } |
104 | 109 |
110 // The file names of the system logs to upload. | |
111 // Note: do not add anything to this list without checking for PII in the file. | |
112 const char* const kSystemLogFileNames[] = {"/var/log/bios_info.txt", | |
113 "/var/log/chrome/chrome", | |
114 "/var/log/eventlog.txt", | |
115 "/var/log/messages", | |
116 "/var/log/net.log", | |
117 "/var/log/platform_info.txt", | |
118 "/var/log/ui/ui.LATEST", | |
119 "/var/log/update_engine.log"}; | |
120 | |
121 // There is an implementation of the |SystemLogUploader::Delegate|, | |
122 // that is used to create an upload job and load system logs from the disk. | |
123 class SystemLogDelegate : public policy::SystemLogUploader::Delegate { | |
124 public: | |
125 SystemLogDelegate(); | |
126 ~SystemLogDelegate() override; | |
127 | |
128 // SystemLogUploader::Delegate: | |
129 void LoadSystemLogs(const LogUploadCallback& upload_callback) override; | |
130 | |
131 scoped_ptr<policy::UploadJob> CreateUploadJob( | |
132 const GURL& upload_url, | |
133 policy::UploadJob::Delegate* delegate) override; | |
134 | |
135 private: | |
136 // FileReader - helper class that thread safely reads files from the disk. | |
137 class FileReader : public base::RefCountedThreadSafe<FileReader> { | |
Andrew T Wilson (Slow)
2015/07/31 12:07:13
Since this class doesn't have any actual data memb
Polina Bondarenko
2015/07/31 13:52:03
Done, removed StartRead function, moved its functi
| |
138 public: | |
139 FileReader() {} | |
140 void StartRead(const LogUploadCallback& upload_callback, | |
Andrew T Wilson (Slow)
2015/07/31 12:07:13
Document what this does/what should be passed.
Polina Bondarenko
2015/07/31 13:52:03
Removed this function, for LoadSystemLogs function
| |
141 base::CancelableTaskTracker* tracker); | |
142 | |
143 private: | |
144 friend class base::RefCountedThreadSafe<FileReader>; | |
145 ~FileReader() {} | |
146 | |
147 // Reads the system log files as binary files, stores the files as pairs | |
148 // (file name, data) in the external structure to pass it to the | |
149 // |upload_callback|. Called on the file thread (non-blocking). | |
150 void Read(SystemLogDelegate::SystemLogs* system_logs); | |
151 | |
152 DISALLOW_COPY_AND_ASSIGN(FileReader); | |
153 }; | |
154 | |
155 // Used in reading log files. | |
156 scoped_refptr<FileReader> file_reader_; | |
157 base::CancelableTaskTracker tracker_; | |
158 | |
159 DISALLOW_COPY_AND_ASSIGN(SystemLogDelegate); | |
160 }; | |
161 | |
162 SystemLogDelegate::SystemLogDelegate() : file_reader_(new FileReader) { | |
163 } | |
164 | |
165 SystemLogDelegate::~SystemLogDelegate() { | |
166 } | |
167 | |
168 void SystemLogDelegate::LoadSystemLogs( | |
169 const LogUploadCallback& upload_callback) { | |
170 file_reader_->StartRead(upload_callback, &tracker_); | |
171 } | |
172 | |
173 scoped_ptr<policy::UploadJob> SystemLogDelegate::CreateUploadJob( | |
Andrew T Wilson (Slow)
2015/07/31 12:07:13
So, it's weird to me that this code lives here in
Polina Bondarenko
2015/07/31 13:52:03
Done, mpved to system_log_uploader.cc
| |
174 const GURL& upload_url, | |
175 policy::UploadJob::Delegate* delegate) { | |
176 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service = | |
177 chromeos::DeviceOAuth2TokenServiceFactory::Get(); | |
178 | |
179 scoped_refptr<net::URLRequestContextGetter> system_request_context = | |
180 g_browser_process->system_request_context(); | |
181 std::string robot_account_id = | |
182 device_oauth2_token_service->GetRobotAccountId(); | |
183 return scoped_ptr<policy::UploadJob>(new policy::UploadJobImpl( | |
184 upload_url, robot_account_id, device_oauth2_token_service, | |
185 system_request_context, delegate, | |
186 make_scoped_ptr(new policy::UploadJobImpl::RandomMimeBoundaryGenerator))); | |
187 } | |
188 | |
189 void SystemLogDelegate::FileReader::StartRead( | |
190 const SystemLogDelegate::LogUploadCallback& upload_callback, | |
191 base::CancelableTaskTracker* tracker) { | |
192 // Owned by reply callback posted below. | |
193 SystemLogs* system_logs = new SystemLogs(); | |
194 | |
195 // Run Read() in the thread that interacts with the file | |
196 // system and return to the current thread. | |
197 tracker->PostTaskAndReply( | |
198 content::BrowserThread::GetMessageLoopProxyForThread( | |
199 content::BrowserThread::FILE).get(), | |
200 FROM_HERE, base::Bind(&FileReader::Read, this, system_logs), | |
Andrew T Wilson (Slow)
2015/07/31 12:07:13
I don't understand why we need a FileReader class.
Polina Bondarenko
2015/07/31 13:52:03
Done.
| |
201 base::Bind(upload_callback, base::Owned(system_logs))); | |
202 } | |
203 | |
204 void SystemLogDelegate::FileReader::Read(SystemLogs* system_logs) { | |
205 // Must be called on the file thread. | |
206 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | |
207 | |
208 for (auto const file_path : kSystemLogFileNames) { | |
209 if (!base::PathExists(base::FilePath(file_path))) | |
210 continue; | |
211 system_logs->push_back(std::make_pair(file_path, std::string())); | |
212 if (!base::ReadFileToString(base::FilePath(file_path), | |
Andrew T Wilson (Slow)
2015/07/31 12:07:13
We also want to add something that scans for commo
Polina Bondarenko
2015/07/31 13:52:03
Done.
| |
213 &(system_logs->back().second))) { | |
214 LOG(ERROR) << "Failed to read the system log file from the disk " | |
215 << file_path << std::endl; | |
216 } | |
217 } | |
218 } | |
219 | |
105 } // namespace | 220 } // namespace |
106 | 221 |
107 DeviceCloudPolicyManagerChromeOS::DeviceCloudPolicyManagerChromeOS( | 222 DeviceCloudPolicyManagerChromeOS::DeviceCloudPolicyManagerChromeOS( |
108 scoped_ptr<DeviceCloudPolicyStoreChromeOS> store, | 223 scoped_ptr<DeviceCloudPolicyStoreChromeOS> store, |
109 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 224 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
110 ServerBackedStateKeysBroker* state_keys_broker) | 225 ServerBackedStateKeysBroker* state_keys_broker) |
111 : CloudPolicyManager( | 226 : CloudPolicyManager( |
112 dm_protocol::kChromeDevicePolicyType, | 227 dm_protocol::kChromeDevicePolicyType, |
113 std::string(), | 228 std::string(), |
114 store.get(), | 229 store.get(), |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 attestation_policy_observer_.reset( | 361 attestation_policy_observer_.reset( |
247 new chromeos::attestation::AttestationPolicyObserver(client())); | 362 new chromeos::attestation::AttestationPolicyObserver(client())); |
248 | 363 |
249 // Enable device reporting and status monitoring for enterprise enrolled | 364 // Enable device reporting and status monitoring for enterprise enrolled |
250 // devices. We want to create these objects for enrolled devices, even if | 365 // devices. We want to create these objects for enrolled devices, even if |
251 // monitoring is currently inactive, in case monitoring is turned back on in | 366 // monitoring is currently inactive, in case monitoring is turned back on in |
252 // a future policy fetch - the classes themselves track the current state of | 367 // a future policy fetch - the classes themselves track the current state of |
253 // the monitoring settings and only perform monitoring if it is active. | 368 // the monitoring settings and only perform monitoring if it is active. |
254 if (install_attributes->IsEnterpriseDevice()) { | 369 if (install_attributes->IsEnterpriseDevice()) { |
255 CreateStatusUploader(); | 370 CreateStatusUploader(); |
371 syslog_uploader_.reset(new SystemLogUploader( | |
372 make_scoped_ptr(new SystemLogDelegate()), task_runner_)); | |
256 heartbeat_scheduler_.reset( | 373 heartbeat_scheduler_.reset( |
257 new HeartbeatScheduler(g_browser_process->gcm_driver(), | 374 new HeartbeatScheduler(g_browser_process->gcm_driver(), |
258 install_attributes->GetDomain(), | 375 install_attributes->GetDomain(), |
259 install_attributes->GetDeviceId(), | 376 install_attributes->GetDeviceId(), |
260 task_runner_)); | 377 task_runner_)); |
261 } | 378 } |
262 | 379 |
263 NotifyConnected(); | 380 NotifyConnected(); |
264 } | 381 } |
265 | 382 |
266 void DeviceCloudPolicyManagerChromeOS::Unregister( | 383 void DeviceCloudPolicyManagerChromeOS::Unregister( |
267 const UnregisterCallback& callback) { | 384 const UnregisterCallback& callback) { |
268 if (!service()) { | 385 if (!service()) { |
269 LOG(ERROR) << "Tried to unregister but DeviceCloudPolicyManagerChromeOS is " | 386 LOG(ERROR) << "Tried to unregister but DeviceCloudPolicyManagerChromeOS is " |
270 << "not connected."; | 387 << "not connected."; |
271 callback.Run(false); | 388 callback.Run(false); |
272 return; | 389 return; |
273 } | 390 } |
274 | 391 |
275 service()->Unregister(callback); | 392 service()->Unregister(callback); |
276 } | 393 } |
277 | 394 |
278 void DeviceCloudPolicyManagerChromeOS::Disconnect() { | 395 void DeviceCloudPolicyManagerChromeOS::Disconnect() { |
279 status_uploader_.reset(); | 396 status_uploader_.reset(); |
397 syslog_uploader_.reset(); | |
280 heartbeat_scheduler_.reset(); | 398 heartbeat_scheduler_.reset(); |
281 core()->Disconnect(); | 399 core()->Disconnect(); |
282 | 400 |
283 NotifyDisconnected(); | 401 NotifyDisconnected(); |
284 } | 402 } |
285 | 403 |
286 void DeviceCloudPolicyManagerChromeOS::OnStateKeysUpdated() { | 404 void DeviceCloudPolicyManagerChromeOS::OnStateKeysUpdated() { |
287 if (client() && ForcedReEnrollmentEnabled()) | 405 if (client() && ForcedReEnrollmentEnabled()) |
288 client()->SetStateKeysToUpload(state_keys_broker_->state_keys()); | 406 client()->SetStateKeysToUpload(state_keys_broker_->state_keys()); |
289 } | 407 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 client(), | 453 client(), |
336 make_scoped_ptr(new DeviceStatusCollector( | 454 make_scoped_ptr(new DeviceStatusCollector( |
337 local_state_, chromeos::system::StatisticsProvider::GetInstance(), | 455 local_state_, chromeos::system::StatisticsProvider::GetInstance(), |
338 DeviceStatusCollector::LocationUpdateRequester(), | 456 DeviceStatusCollector::LocationUpdateRequester(), |
339 DeviceStatusCollector::VolumeInfoFetcher(), | 457 DeviceStatusCollector::VolumeInfoFetcher(), |
340 DeviceStatusCollector::CPUStatisticsFetcher())), | 458 DeviceStatusCollector::CPUStatisticsFetcher())), |
341 task_runner_)); | 459 task_runner_)); |
342 } | 460 } |
343 | 461 |
344 } // namespace policy | 462 } // namespace policy |
OLD | NEW |