OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOAD_JOB_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOAD_JOB_H_ |
| 7 |
| 8 #include "base/cancelable_callback.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "chrome/browser/chromeos/policy/upload_job.h" |
| 13 |
| 14 namespace policy { |
| 15 |
| 16 // Class responsible for periodically uploading system logs. |
| 17 class SystemLogUploadJob : public UploadJob::Delegate { |
| 18 public: |
| 19 // Structure that stores the system log files as pairs: (file name, loaded |
| 20 // from the disk binary file data). |
| 21 typedef std::vector<std::pair<std::string, std::string>> SystemLogs; |
| 22 |
| 23 typedef base::Callback<void(const SystemLogs* system_logs)> LogUploadCallback; |
| 24 |
| 25 class Delegate { |
| 26 public: |
| 27 virtual ~Delegate() {} |
| 28 |
| 29 // Loads system logs and invokes |upload_callback|. |
| 30 virtual void LoadSystemLogs(const LogUploadCallback& upload_callback) = 0; |
| 31 |
| 32 // Creates a new fully configured instance of an UploadJob. This method |
| 33 // may be called any number of times. |
| 34 virtual scoped_ptr<UploadJob> CreateUploadJob(const GURL&, |
| 35 UploadJob::Delegate*) = 0; |
| 36 }; |
| 37 |
| 38 explicit SystemLogUploadJob(scoped_ptr<Delegate> syslog_delegate); |
| 39 |
| 40 ~SystemLogUploadJob() override; |
| 41 |
| 42 // Starts the system log upload. |
| 43 virtual void Run(const base::Closure& succeeded_callback, |
| 44 const base::Closure& failed_callback); |
| 45 |
| 46 private: |
| 47 // UploadJob::Delegate: |
| 48 void OnSuccess() override; |
| 49 void OnFailure(UploadJob::ErrorCode error_code) override; |
| 50 |
| 51 // Callback invoked periodically to start loading system logs. |
| 52 void StartLoadSystemLogs(); |
| 53 |
| 54 // Callback invoked when system logs are successfully loaded, |
| 55 // starts the system log upload. |
| 56 void StartUploadSystemLogs(const SystemLogs* system_logs); |
| 57 |
| 58 // The URL to which the POST request should be directed. |
| 59 GURL upload_url_; |
| 60 |
| 61 // The callback that will be called when the system logs were successfully |
| 62 // uploaded. |
| 63 base::Closure succeeded_callback_; |
| 64 |
| 65 // The callback that will be called when system log upload failed. |
| 66 base::Closure failed_callback_; |
| 67 |
| 68 // The Delegate is used to load system logs and create UploadJobs. |
| 69 scoped_ptr<Delegate> syslog_delegate_; |
| 70 |
| 71 // The upload job instance that will upload the log files. |
| 72 scoped_ptr<UploadJob> upload_job_; |
| 73 |
| 74 // Note: This should remain the last member so it'll be destroyed and |
| 75 // invalidate the weak pointers before any other members are destroyed. |
| 76 base::WeakPtrFactory<SystemLogUploadJob> weak_factory_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(SystemLogUploadJob); |
| 79 }; |
| 80 |
| 81 } // namespace policy |
| 82 |
| 83 #endif // CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOAD_JOB_H_ |
OLD | NEW |