| 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 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/chromeos/policy/upload_job.h" | 15 #include "chrome/browser/chromeos/policy/upload_job.h" |
| 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class SequencedTaskRunner; | 19 class SequencedTaskRunner; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace policy { | 22 namespace policy { |
| 22 | 23 |
| 23 // Class responsible for periodically uploading system logs, it handles the | 24 // Class responsible for periodically uploading system logs, it handles the |
| 24 // server responses by UploadJob:Delegate callbacks. | 25 // server responses by UploadJob:Delegate callbacks. |
| 25 class SystemLogUploader : public UploadJob::Delegate { | 26 class SystemLogUploader : public UploadJob::Delegate { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // ever happened. | 70 // ever happened. |
| 70 base::Time last_upload_attempt() const { return last_upload_attempt_; } | 71 base::Time last_upload_attempt() const { return last_upload_attempt_; } |
| 71 | 72 |
| 72 // UploadJob::Delegate: | 73 // UploadJob::Delegate: |
| 73 // Callbacks handle success and failure results of upload, destroy the | 74 // Callbacks handle success and failure results of upload, destroy the |
| 74 // upload job. | 75 // upload job. |
| 75 void OnSuccess() override; | 76 void OnSuccess() override; |
| 76 void OnFailure(UploadJob::ErrorCode error_code) override; | 77 void OnFailure(UploadJob::ErrorCode error_code) override; |
| 77 | 78 |
| 78 private: | 79 private: |
| 80 // Updates the system log upload enabled field from settings. |
| 81 void RefreshUploadSettings(); |
| 82 |
| 79 // Starts the system log loading process. | 83 // Starts the system log loading process. |
| 80 void StartLogUpload(); | 84 void StartLogUpload(); |
| 81 | 85 |
| 82 // The callback is invoked by the Delegate if system logs have been loaded | 86 // The callback is invoked by the Delegate if system logs have been loaded |
| 83 // from disk, uploads system logs. | 87 // from disk, uploads system logs. |
| 84 void UploadSystemLogs(scoped_ptr<SystemLogs> system_logs); | 88 void UploadSystemLogs(scoped_ptr<SystemLogs> system_logs); |
| 85 | 89 |
| 86 // Helper method that figures out when the next system log upload should | 90 // Helper method that figures out when the next system log upload should |
| 87 // be scheduled. | 91 // be scheduled. |
| 88 void ScheduleNextSystemLogUpload(base::TimeDelta frequency); | 92 void ScheduleNextSystemLogUpload(base::TimeDelta frequency); |
| 89 | 93 |
| 90 // The number of consequent retries after the failed uploads. | 94 // The number of consequent retries after the failed uploads. |
| 91 int retry_count_; | 95 int retry_count_; |
| 92 | 96 |
| 93 // How long to wait between system log uploads. | 97 // How long to wait between system log uploads. |
| 94 base::TimeDelta upload_frequency_; | 98 base::TimeDelta upload_frequency_; |
| 95 | 99 |
| 96 // The time the last upload attempt was performed. | 100 // The time the last upload attempt was performed. |
| 97 base::Time last_upload_attempt_; | 101 base::Time last_upload_attempt_; |
| 98 | 102 |
| 99 // TaskRunner used for scheduling upload tasks. | 103 // TaskRunner used for scheduling upload tasks. |
| 100 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 104 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 101 | 105 |
| 102 // The upload job that is re-created on every system log upload. | 106 // The upload job that is re-created on every system log upload. |
| 103 scoped_ptr<UploadJob> upload_job_; | 107 scoped_ptr<UploadJob> upload_job_; |
| 104 | 108 |
| 105 // The Delegate is used to load system logs and create UploadJobs. | 109 // The Delegate is used to load system logs and create UploadJobs. |
| 106 scoped_ptr<Delegate> syslog_delegate_; | 110 scoped_ptr<Delegate> syslog_delegate_; |
| 107 | 111 |
| 112 // True if system log upload is enabled. Kept cached in this object because |
| 113 // CrosSettings can switch to an unstrusted state temporarily, and we want to |
| 114 // use the last-known trusted values. |
| 115 bool upload_enabled_; |
| 116 |
| 117 // Observer to changes in system log upload settings. |
| 118 scoped_ptr<chromeos::CrosSettings::ObserverSubscription> |
| 119 upload_enabled_observer_; |
| 120 |
| 108 base::ThreadChecker thread_checker_; | 121 base::ThreadChecker thread_checker_; |
| 109 | 122 |
| 110 // Note: This should remain the last member so it'll be destroyed and | 123 // Note: This should remain the last member so it'll be destroyed and |
| 111 // invalidate the weak pointers before any other members are destroyed. | 124 // invalidate the weak pointers before any other members are destroyed. |
| 112 base::WeakPtrFactory<SystemLogUploader> weak_factory_; | 125 base::WeakPtrFactory<SystemLogUploader> weak_factory_; |
| 113 | 126 |
| 114 DISALLOW_COPY_AND_ASSIGN(SystemLogUploader); | 127 DISALLOW_COPY_AND_ASSIGN(SystemLogUploader); |
| 115 }; | 128 }; |
| 116 | 129 |
| 117 } // namespace policy | 130 } // namespace policy |
| 118 | 131 |
| 119 #endif // CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_ | 132 #endif // CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_ |
| OLD | NEW |