summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima <oshima@chromium.org>2015-08-03 14:17:36 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-03 21:18:24 +0000
commitbd220e4849741435ba7d4583b9d5022ce032d41e (patch)
tree1a2bd16dacfcc17894a21a90d91db4c6bfa1a501
parent733b4d015f97fc49bd9c03ff7ac3bf7be4b8af79 (diff)
downloadchromium_src-bd220e4849741435ba7d4583b9d5022ce032d41e.zip
chromium_src-bd220e4849741435ba7d4583b9d5022ce032d41e.tar.gz
chromium_src-bd220e4849741435ba7d4583b9d5022ce032d41e.tar.bz2
Revert "Added system log uploader."
Reason for the revert: Following tests are failing on ChromeOS dbg bots. See crbug.com/516449 for more details. DeviceDisablingTest.DisableDuringNormalOperation LoginScreenDefaultPolicyInSessionBrowsertest.DeviceLoginScreenDefaultHighContrastEnabled LoginScreenDefaultPolicyInSessionBrowsertest.DeviceLoginScreenDefaultScreenMagnifierType LoginScreenPolicyTest.DisableSupervisedUsers PowerPolicyInSessionBrowserTest.SetDevicePolicy > Added system log uploader. > > SystemLogUploader schedules log files uploads to server every 12 hours, > in case of error makes single retry attempt after 120 sec. > > SystemLogDelegate creates UploadJob for every single log upload and loads log files from the disk. > > BUG=471888 > > Review URL: https://codereview.chromium.org/1193333017 > > Cr-Commit-Position: refs/heads/master@{#341533} BUG=471888,516449 TBR=pbond@chromium.org Review URL: https://codereview.chromium.org/1259043003 Cr-Commit-Position: refs/heads/master@{#341614}
-rw-r--r--chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc3
-rw-r--r--chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h6
-rw-r--r--chrome/browser/chromeos/policy/system_log_uploader.cc226
-rw-r--r--chrome/browser/chromeos/policy/system_log_uploader.h109
-rw-r--r--chrome/chrome_browser_chromeos.gypi2
5 files changed, 1 insertions, 345 deletions
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc
index 73c5ca4..f96b997 100644
--- a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc
@@ -24,7 +24,6 @@
#include "chrome/browser/chromeos/policy/remote_commands/device_commands_factory_chromeos.h"
#include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h"
#include "chrome/browser/chromeos/policy/status_uploader.h"
-#include "chrome/browser/chromeos/policy/system_log_uploader.h"
#include "chrome/common/pref_names.h"
#include "chromeos/chromeos_constants.h"
#include "chromeos/chromeos_switches.h"
@@ -254,7 +253,6 @@ void DeviceCloudPolicyManagerChromeOS::StartConnection(
// the monitoring settings and only perform monitoring if it is active.
if (install_attributes->IsEnterpriseDevice()) {
CreateStatusUploader();
- syslog_uploader_.reset(new SystemLogUploader(nullptr, task_runner_));
heartbeat_scheduler_.reset(
new HeartbeatScheduler(g_browser_process->gcm_driver(),
install_attributes->GetDomain(),
@@ -279,7 +277,6 @@ void DeviceCloudPolicyManagerChromeOS::Unregister(
void DeviceCloudPolicyManagerChromeOS::Disconnect() {
status_uploader_.reset();
- syslog_uploader_.reset();
heartbeat_scheduler_.reset();
core()->Disconnect();
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h
index bc72ac1..a830542 100644
--- a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h
@@ -37,7 +37,6 @@ class DeviceCloudPolicyStoreChromeOS;
class EnterpriseInstallAttributes;
class HeartbeatScheduler;
class StatusUploader;
-class SystemLogUploader;
// CloudPolicyManager specialization for device policy on Chrome OS.
class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager {
@@ -132,14 +131,11 @@ class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager {
// state.
scoped_ptr<StatusUploader> status_uploader_;
- // Helper object that handles uploading system logs to the server.
- scoped_ptr<SystemLogUploader> syslog_uploader_;
-
// Helper object that handles sending heartbeats over the GCM channel to
// the server, to monitor connectivity.
scoped_ptr<HeartbeatScheduler> heartbeat_scheduler_;
- // The TaskRunner used to do device status and log uploads.
+ // The TaskRunner used to do device status uploads.
scoped_refptr<base::SequencedTaskRunner> task_runner_;
ServerBackedStateKeysBroker::Subscription state_keys_update_subscription_;
diff --git a/chrome/browser/chromeos/policy/system_log_uploader.cc b/chrome/browser/chromeos/policy/system_log_uploader.cc
deleted file mode 100644
index e59cf1b..0000000
--- a/chrome/browser/chromeos/policy/system_log_uploader.cc
+++ /dev/null
@@ -1,226 +0,0 @@
-// Copyright (c) 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/files/file_util.h"
-#include "base/location.h"
-#include "base/strings/stringprintf.h"
-#include "base/task_runner_util.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chromeos/policy/system_log_uploader.h"
-#include "chrome/browser/chromeos/policy/upload_job_impl.h"
-#include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
-#include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h"
-#include "content/public/browser/browser_thread.h"
-#include "net/http/http_request_headers.h"
-
-namespace {
-// Determines the time between log uploads.
-const int64 kDefaultUploadDelayMs = 12 * 60 * 60 * 1000; // 12 hours
-
-// Determines the time, measured from the time of last failed upload,
-// after which the log upload is retried.
-const int64 kErrorUploadDelayMs = 120 * 1000; // 120 seconds
-
-// The maximum number of successive retries.
-const int kMaxNumRetries = 1;
-
-// String constant defining the url we upload system logs to.
-const char* kSystemLogUploadUrl =
- "https://m.google.com/devicemanagement/data/api/upload";
-
-// String constant identifying the header field which stores the file type.
-const char* kFileTypeHeaderName = "File-Type";
-
-// String constant signalling that the data segment contains log files.
-const char* const kFileTypeLogFile = "log_file";
-
-// String constant signalling that the segment contains a plain text.
-const char* const kContentTypePlainText = "text/plain";
-
-// Template string constant for populating the name field.
-const char* const kNameFieldTemplate = "file%d";
-
-// The file names of the system logs to upload.
-// Note: do not add anything to this list without checking for PII in the file.
-const char* const kSystemLogFileNames[] = {"/var/log/bios_info.txt",
- "/var/log/chrome/chrome",
- "/var/log/eventlog.txt",
- "/var/log/messages",
- "/var/log/net.log",
- "/var/log/platform_info.txt",
- "/var/log/ui/ui.LATEST",
- "/var/log/update_engine.log"};
-
-// Reads the system log files as binary files, stores the files as pairs
-// (file name, data) and returns. Called on blocking thread.
-scoped_ptr<policy::SystemLogUploader::SystemLogs> ReadFiles() {
- scoped_ptr<policy::SystemLogUploader::SystemLogs> system_logs(
- new policy::SystemLogUploader::SystemLogs());
- for (auto const file_path : kSystemLogFileNames) {
- if (!base::PathExists(base::FilePath(file_path)))
- continue;
- std::string data = std::string();
- if (!base::ReadFileToString(base::FilePath(file_path), &data)) {
- LOG(ERROR) << "Failed to read the system log file from the disk "
- << file_path << std::endl;
- }
- // TODO(pbond): add check |data| for common PII (email, IP addresses and
- // etc.) and modify the |data| to remove/obfuscate the PII if any found.
- // http://crbug.com/515879.
- system_logs->push_back(std::make_pair(file_path, data));
- }
- return system_logs.Pass();
-}
-
-// An implementation of the |SystemLogUploader::Delegate|, that is used to
-// create an upload job and load system logs from the disk.
-class SystemLogDelegate : public policy::SystemLogUploader::Delegate {
- public:
- SystemLogDelegate();
- ~SystemLogDelegate() override;
-
- // SystemLogUploader::Delegate:
- void LoadSystemLogs(const LogUploadCallback& upload_callback) override;
-
- scoped_ptr<policy::UploadJob> CreateUploadJob(
- const GURL& upload_url,
- policy::UploadJob::Delegate* delegate) override;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(SystemLogDelegate);
-};
-
-SystemLogDelegate::SystemLogDelegate() {
-}
-
-SystemLogDelegate::~SystemLogDelegate() {
-}
-
-void SystemLogDelegate::LoadSystemLogs(
- const LogUploadCallback& upload_callback) {
- // Run ReadFiles() in the thread that interacts with the file system and
- // return system logs to |upload_callback| on the current thread.
- base::PostTaskAndReplyWithResult(content::BrowserThread::GetBlockingPool(),
- FROM_HERE, base::Bind(&ReadFiles),
- upload_callback);
-}
-
-scoped_ptr<policy::UploadJob> SystemLogDelegate::CreateUploadJob(
- const GURL& upload_url,
- policy::UploadJob::Delegate* delegate) {
- chromeos::DeviceOAuth2TokenService* device_oauth2_token_service =
- chromeos::DeviceOAuth2TokenServiceFactory::Get();
-
- scoped_refptr<net::URLRequestContextGetter> system_request_context =
- g_browser_process->system_request_context();
- std::string robot_account_id =
- device_oauth2_token_service->GetRobotAccountId();
- return scoped_ptr<policy::UploadJob>(new policy::UploadJobImpl(
- upload_url, robot_account_id, device_oauth2_token_service,
- system_request_context, delegate,
- make_scoped_ptr(new policy::UploadJobImpl::RandomMimeBoundaryGenerator)));
-}
-
-} // namespace
-
-namespace policy {
-
-SystemLogUploader::SystemLogUploader(
- scoped_ptr<Delegate> syslog_delegate,
- const scoped_refptr<base::SequencedTaskRunner>& task_runner)
- : retry_count_(0),
- upload_frequency_(
- base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs)),
- task_runner_(task_runner),
- syslog_delegate_(syslog_delegate.Pass()),
- weak_factory_(this) {
- if (!syslog_delegate_)
- syslog_delegate_.reset(new SystemLogDelegate());
- DCHECK(syslog_delegate_);
- // Immediately schedule the next system log upload (last_upload_attempt_ is
- // set to the start of the epoch, so this will trigger an update upload in the
- // immediate future).
- ScheduleNextSystemLogUpload(upload_frequency_);
-}
-
-SystemLogUploader::~SystemLogUploader() {
-}
-
-void SystemLogUploader::OnSuccess() {
- upload_job_.reset();
- last_upload_attempt_ = base::Time::NowFromSystemTime();
- retry_count_ = 0;
-
- // On successful log upload schedule the next log upload after
- // upload_frequency_ time from now.
- ScheduleNextSystemLogUpload(upload_frequency_);
-}
-
-void SystemLogUploader::OnFailure(UploadJob::ErrorCode error_code) {
- upload_job_.reset();
- last_upload_attempt_ = base::Time::NowFromSystemTime();
-
- // If we have hit the maximum number of retries, terminate this upload
- // attempt and schedule the next one using the normal delay. Otherwise, retry
- // uploading after kErrorUploadDelayMs milliseconds.
- if (retry_count_++ < kMaxNumRetries) {
- ScheduleNextSystemLogUpload(
- base::TimeDelta::FromMilliseconds(kErrorUploadDelayMs));
- } else {
- // No more retries.
- retry_count_ = 0;
- ScheduleNextSystemLogUpload(upload_frequency_);
- }
-}
-
-void SystemLogUploader::UploadSystemLogs(scoped_ptr<SystemLogs> system_logs) {
- // Must be called on the main thread.
- DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(!upload_job_);
-
- GURL upload_url(kSystemLogUploadUrl);
- DCHECK(upload_url.is_valid());
- upload_job_ = syslog_delegate_->CreateUploadJob(upload_url, this);
-
- // Start a system log upload.
- int file_number = 1;
- for (const auto& syslog_entry : *system_logs) {
- std::map<std::string, std::string> header_fields;
- scoped_ptr<std::string> data =
- make_scoped_ptr(new std::string(syslog_entry.second));
- header_fields.insert(std::make_pair(kFileTypeHeaderName, kFileTypeLogFile));
- header_fields.insert(std::make_pair(net::HttpRequestHeaders::kContentType,
- kContentTypePlainText));
- upload_job_->AddDataSegment(
- base::StringPrintf(kNameFieldTemplate, file_number), syslog_entry.first,
- header_fields, data.Pass());
- ++file_number;
- }
- upload_job_->Start();
-}
-
-void SystemLogUploader::StartLogUpload() {
- // Must be called on the main thread.
- DCHECK(thread_checker_.CalledOnValidThread());
-
- syslog_delegate_->LoadSystemLogs(base::Bind(
- &SystemLogUploader::UploadSystemLogs, weak_factory_.GetWeakPtr()));
-}
-
-void SystemLogUploader::ScheduleNextSystemLogUpload(base::TimeDelta frequency) {
- // Calculate when to fire off the next update.
- base::TimeDelta delay = std::max(
- (last_upload_attempt_ + frequency) - base::Time::NowFromSystemTime(),
- base::TimeDelta());
- // Ensure that we never have more than one pending delayed task.
- weak_factory_.InvalidateWeakPtrs();
- task_runner_->PostDelayedTask(FROM_HERE,
- base::Bind(&SystemLogUploader::StartLogUpload,
- weak_factory_.GetWeakPtr()),
- delay);
-}
-
-} // namespace policy
diff --git a/chrome/browser/chromeos/policy/system_log_uploader.h b/chrome/browser/chromeos/policy/system_log_uploader.h
deleted file mode 100644
index db3a260..0000000
--- a/chrome/browser/chromeos/policy/system_log_uploader.h
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright (c) 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_
-#define CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_
-
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "base/memory/ref_counted_memory.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
-#include "base/threading/thread_checker.h"
-#include "base/time/time.h"
-#include "chrome/browser/chromeos/policy/upload_job.h"
-
-namespace base {
-class SequencedTaskRunner;
-}
-
-namespace policy {
-
-// Class responsible for periodically uploading system logs, it handles the
-// server responses by UploadJob:Delegate callbacks.
-class SystemLogUploader : public UploadJob::Delegate {
- public:
- // Structure that stores the system log files as pairs: (file name, loaded
- // from the disk binary file data).
- typedef std::vector<std::pair<std::string, std::string>> SystemLogs;
-
- // A delegate interface used by SystemLogUploader to read the system logs
- // from the disk and create an upload job.
- class Delegate {
- public:
- typedef base::Callback<void(scoped_ptr<SystemLogs> system_logs)>
- LogUploadCallback;
-
- virtual ~Delegate() {}
-
- // Loads system logs and invokes |upload_callback|.
- virtual void LoadSystemLogs(const LogUploadCallback& upload_callback) = 0;
-
- // Creates a new fully configured instance of an UploadJob. This method
- // will be called exactly once per every system log upload.
- virtual scoped_ptr<UploadJob> CreateUploadJob(
- const GURL& upload_url,
- UploadJob::Delegate* delegate) = 0;
- };
-
- // Constructor. Callers can inject their own Delegate. A nullptr can be passed
- // for |syslog_delegate| to use the default implementation.
- explicit SystemLogUploader(
- scoped_ptr<Delegate> syslog_delegate,
- const scoped_refptr<base::SequencedTaskRunner>& task_runner);
-
- ~SystemLogUploader() override;
-
- // Returns the time of the last upload attempt, or Time(0) if no upload has
- // ever happened.
- base::Time last_upload_attempt() const { return last_upload_attempt_; }
-
- // UploadJob::Delegate:
- // Callbacks handle success and failure results of upload, destroy the
- // upload job.
- void OnSuccess() override;
- void OnFailure(UploadJob::ErrorCode error_code) override;
-
- private:
- // Starts the system log loading process.
- void StartLogUpload();
-
- // The callback is invoked by the Delegate if system logs have been loaded
- // from disk, uploads system logs.
- void UploadSystemLogs(scoped_ptr<SystemLogs> system_logs);
-
- // Helper method that figures out when the next system log upload should
- // be scheduled.
- void ScheduleNextSystemLogUpload(base::TimeDelta frequency);
-
- // The number of consequent retries after the failed uploads.
- int retry_count_;
-
- // How long to wait between system log uploads.
- base::TimeDelta upload_frequency_;
-
- // The time the last upload attempt was performed.
- base::Time last_upload_attempt_;
-
- // TaskRunner used for scheduling upload tasks.
- const scoped_refptr<base::SequencedTaskRunner> task_runner_;
-
- // The upload job that is re-created on every system log upload.
- scoped_ptr<UploadJob> upload_job_;
-
- // The Delegate is used to load system logs and create UploadJobs.
- scoped_ptr<Delegate> syslog_delegate_;
-
- base::ThreadChecker thread_checker_;
-
- // Note: This should remain the last member so it'll be destroyed and
- // invalidate the weak pointers before any other members are destroyed.
- base::WeakPtrFactory<SystemLogUploader> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(SystemLogUploader);
-};
-
-} // namespace policy
-
-#endif // CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_
diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi
index eb756dc..e8cf6a1 100644
--- a/chrome/chrome_browser_chromeos.gypi
+++ b/chrome/chrome_browser_chromeos.gypi
@@ -875,8 +875,6 @@
'browser/chromeos/policy/server_backed_state_keys_broker.h',
'browser/chromeos/policy/status_uploader.cc',
'browser/chromeos/policy/status_uploader.h',
- 'browser/chromeos/policy/system_log_uploader.cc',
- 'browser/chromeos/policy/system_log_uploader.h',
'browser/chromeos/policy/ticl_device_settings_provider.cc',
'browser/chromeos/policy/ticl_device_settings_provider.h',
'browser/chromeos/policy/upload_job.h',