Index: chrome/browser/chromeos/policy/system_log_upload_job.h |
diff --git a/chrome/browser/chromeos/policy/system_log_upload_job.h b/chrome/browser/chromeos/policy/system_log_upload_job.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0e89e4272c19b8e74b9be0c0796205ea8bfe9402 |
--- /dev/null |
+++ b/chrome/browser/chromeos/policy/system_log_upload_job.h |
@@ -0,0 +1,84 @@ |
+// 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_UPLOAD_JOB_H_ |
+#define CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOAD_JOB_H_ |
+ |
+#include "base/cancelable_callback.h" |
+#include "base/macros.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "chrome/browser/chromeos/policy/upload_job.h" |
+ |
+namespace policy { |
+ |
+// Class responsible for periodically uploading system logs. |
+class SystemLogUploadJob : public UploadJob::Delegate { |
+ public: |
+ typedef base::Callback<void( |
+ const std::map<std::string, std::string>& system_logs)> LogUploadCallback; |
Andrew T Wilson (Slow)
2015/06/29 15:06:09
Maybe make a typedef for std::map<string, string>
Polina Bondarenko
2015/07/02 15:28:04
Done, changed to std::vector of pairs
|
+ |
+ class Delegate { |
+ public: |
+ virtual ~Delegate() {} |
+ |
+ // Loads system logs. |
+ virtual void LoadSystemLogs(const LogUploadCallback& upload_callback) = 0; |
+ |
+ // Creates a new fully configured instance of an UploadJob. This method |
+ // may be called any number of times. |
+ virtual scoped_ptr<UploadJob> CreateUploadJob(const GURL&, |
+ UploadJob::Delegate*) = 0; |
+ }; |
+ |
+ // Constructor. |
+ explicit SystemLogUploadJob(scoped_ptr<Delegate> syslog_delegate); |
+ |
+ // Destructor. |
+ ~SystemLogUploadJob() override; |
+ |
+ // Start system log upload. |
+ void Run(const base::Closure& succeeded_callback, |
+ const base::Closure& failed_callback); |
+ // Terminate system log upload. |
Andrew T Wilson (Slow)
2015/06/29 15:06:09
nit: blank line above
Polina Bondarenko
2015/07/02 15:28:04
Done, removed the function.
|
+ void Terminate(); |
Andrew T Wilson (Slow)
2015/06/29 15:06:09
Why have a Terminate() function? Can the caller ju
Polina Bondarenko
2015/07/02 15:28:04
Done.
|
+ |
+ private: |
+ // UploadJob::Delegate: |
+ void OnSuccess() override; |
+ void OnFailure(UploadJob::ErrorCode error_code) override; |
+ |
+ // Callback invoked periodically to start loading system logs. |
+ void StartLoadSystemLogs(); |
+ |
+ // Callback invoked when system logs are successfully loaded, |
+ // starts system log upload. |
+ void StartUploadSystemLogs( |
+ const std::map<std::string, std::string>& system_logs); |
+ |
+ // The URL to which the POST request should be directed. |
+ GURL upload_url_; |
+ |
+ // The callback that will be called when the system logs were successfully |
+ // uploaded. |
+ base::Closure succeeded_callback_; |
+ |
+ // The callback that will be called when system log upload failed. |
+ base::Closure failed_callback_; |
+ |
+ // The Delegate is used to load system logs and create UploadJobs. |
+ scoped_ptr<Delegate> syslog_delegate_; |
+ |
+ // The upload job instance that will upload the log files. |
+ scoped_ptr<UploadJob> upload_job_; |
+ |
+ // 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<SystemLogUploadJob> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SystemLogUploadJob); |
+}; |
+ |
+} // namespace policy |
+#endif // CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOAD_JOB_H_ |