| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/system_log_uploader.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 5 #include "base/bind.h" | 9 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 7 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 9 #include "base/location.h" | 13 #include "base/location.h" |
| 10 #include "base/macros.h" | 14 #include "base/macros.h" |
| 11 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 14 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 15 #include "base/task_runner_util.h" | 19 #include "base/task_runner_util.h" |
| 16 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chromeos/policy/system_log_uploader.h" | |
| 18 #include "chrome/browser/chromeos/policy/upload_job_impl.h" | 21 #include "chrome/browser/chromeos/policy/upload_job_impl.h" |
| 19 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 22 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
| 20 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" | 23 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" |
| 21 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 22 #include "components/policy/core/browser/browser_policy_connector.h" | 25 #include "components/policy/core/browser/browser_policy_connector.h" |
| 23 #include "components/policy/core/common/cloud/enterprise_metrics.h" | 26 #include "components/policy/core/common/cloud/enterprise_metrics.h" |
| 24 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 25 #include "net/http/http_request_headers.h" | 28 #include "net/http/http_request_headers.h" |
| 26 #include "third_party/re2/src/re2/re2.h" | 29 #include "third_party/re2/src/re2/re2.h" |
| 27 | 30 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 if (!base::PathExists(base::FilePath(file_path))) | 81 if (!base::PathExists(base::FilePath(file_path))) |
| 79 continue; | 82 continue; |
| 80 std::string data = std::string(); | 83 std::string data = std::string(); |
| 81 if (!base::ReadFileToString(base::FilePath(file_path), &data)) { | 84 if (!base::ReadFileToString(base::FilePath(file_path), &data)) { |
| 82 LOG(ERROR) << "Failed to read the system log file from the disk " | 85 LOG(ERROR) << "Failed to read the system log file from the disk " |
| 83 << file_path << std::endl; | 86 << file_path << std::endl; |
| 84 } | 87 } |
| 85 system_logs->push_back(std::make_pair( | 88 system_logs->push_back(std::make_pair( |
| 86 file_path, policy::SystemLogUploader::RemoveSensitiveData(data))); | 89 file_path, policy::SystemLogUploader::RemoveSensitiveData(data))); |
| 87 } | 90 } |
| 88 return system_logs.Pass(); | 91 return system_logs; |
| 89 } | 92 } |
| 90 | 93 |
| 91 // An implementation of the |SystemLogUploader::Delegate|, that is used to | 94 // An implementation of the |SystemLogUploader::Delegate|, that is used to |
| 92 // create an upload job and load system logs from the disk. | 95 // create an upload job and load system logs from the disk. |
| 93 class SystemLogDelegate : public policy::SystemLogUploader::Delegate { | 96 class SystemLogDelegate : public policy::SystemLogUploader::Delegate { |
| 94 public: | 97 public: |
| 95 SystemLogDelegate(); | 98 SystemLogDelegate(); |
| 96 ~SystemLogDelegate() override; | 99 ~SystemLogDelegate() override; |
| 97 | 100 |
| 98 // SystemLogUploader::Delegate: | 101 // SystemLogUploader::Delegate: |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 189 |
| 187 // Template string constant for populating the name field. | 190 // Template string constant for populating the name field. |
| 188 const char* const SystemLogUploader::kNameFieldTemplate = "file%d"; | 191 const char* const SystemLogUploader::kNameFieldTemplate = "file%d"; |
| 189 | 192 |
| 190 SystemLogUploader::SystemLogUploader( | 193 SystemLogUploader::SystemLogUploader( |
| 191 scoped_ptr<Delegate> syslog_delegate, | 194 scoped_ptr<Delegate> syslog_delegate, |
| 192 const scoped_refptr<base::SequencedTaskRunner>& task_runner) | 195 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
| 193 : retry_count_(0), | 196 : retry_count_(0), |
| 194 upload_frequency_(GetUploadFrequency()), | 197 upload_frequency_(GetUploadFrequency()), |
| 195 task_runner_(task_runner), | 198 task_runner_(task_runner), |
| 196 syslog_delegate_(syslog_delegate.Pass()), | 199 syslog_delegate_(std::move(syslog_delegate)), |
| 197 upload_enabled_(false), | 200 upload_enabled_(false), |
| 198 weak_factory_(this) { | 201 weak_factory_(this) { |
| 199 if (!syslog_delegate_) | 202 if (!syslog_delegate_) |
| 200 syslog_delegate_.reset(new SystemLogDelegate()); | 203 syslog_delegate_.reset(new SystemLogDelegate()); |
| 201 DCHECK(syslog_delegate_); | 204 DCHECK(syslog_delegate_); |
| 202 | 205 |
| 203 // Watch for policy changes. | 206 // Watch for policy changes. |
| 204 upload_enabled_observer_ = chromeos::CrosSettings::Get()->AddSettingsObserver( | 207 upload_enabled_observer_ = chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 205 chromeos::kSystemLogUploadEnabled, | 208 chromeos::kSystemLogUploadEnabled, |
| 206 base::Bind(&SystemLogUploader::RefreshUploadSettings, | 209 base::Bind(&SystemLogUploader::RefreshUploadSettings, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 int file_number = 1; | 322 int file_number = 1; |
| 320 for (const auto& syslog_entry : *system_logs) { | 323 for (const auto& syslog_entry : *system_logs) { |
| 321 std::map<std::string, std::string> header_fields; | 324 std::map<std::string, std::string> header_fields; |
| 322 scoped_ptr<std::string> data = | 325 scoped_ptr<std::string> data = |
| 323 make_scoped_ptr(new std::string(syslog_entry.second)); | 326 make_scoped_ptr(new std::string(syslog_entry.second)); |
| 324 header_fields.insert(std::make_pair(kFileTypeHeaderName, kFileTypeLogFile)); | 327 header_fields.insert(std::make_pair(kFileTypeHeaderName, kFileTypeLogFile)); |
| 325 header_fields.insert(std::make_pair(net::HttpRequestHeaders::kContentType, | 328 header_fields.insert(std::make_pair(net::HttpRequestHeaders::kContentType, |
| 326 kContentTypePlainText)); | 329 kContentTypePlainText)); |
| 327 upload_job_->AddDataSegment( | 330 upload_job_->AddDataSegment( |
| 328 base::StringPrintf(kNameFieldTemplate, file_number), syslog_entry.first, | 331 base::StringPrintf(kNameFieldTemplate, file_number), syslog_entry.first, |
| 329 header_fields, data.Pass()); | 332 header_fields, std::move(data)); |
| 330 ++file_number; | 333 ++file_number; |
| 331 } | 334 } |
| 332 upload_job_->Start(); | 335 upload_job_->Start(); |
| 333 } | 336 } |
| 334 | 337 |
| 335 void SystemLogUploader::StartLogUpload() { | 338 void SystemLogUploader::StartLogUpload() { |
| 336 // Must be called on the main thread. | 339 // Must be called on the main thread. |
| 337 DCHECK(thread_checker_.CalledOnValidThread()); | 340 DCHECK(thread_checker_.CalledOnValidThread()); |
| 338 | 341 |
| 339 if (upload_enabled_) { | 342 if (upload_enabled_) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 354 base::TimeDelta()); | 357 base::TimeDelta()); |
| 355 // Ensure that we never have more than one pending delayed task. | 358 // Ensure that we never have more than one pending delayed task. |
| 356 weak_factory_.InvalidateWeakPtrs(); | 359 weak_factory_.InvalidateWeakPtrs(); |
| 357 task_runner_->PostDelayedTask(FROM_HERE, | 360 task_runner_->PostDelayedTask(FROM_HERE, |
| 358 base::Bind(&SystemLogUploader::StartLogUpload, | 361 base::Bind(&SystemLogUploader::StartLogUpload, |
| 359 weak_factory_.GetWeakPtr()), | 362 weak_factory_.GetWeakPtr()), |
| 360 delay); | 363 delay); |
| 361 } | 364 } |
| 362 | 365 |
| 363 } // namespace policy | 366 } // namespace policy |
| OLD | NEW |