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_UPLOADER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/memory/ref_counted_memory.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "base/threading/thread_checker.h" | |
14 #include "base/time/time.h" | |
15 #include "chrome/browser/chromeos/policy/upload_job.h" | |
16 | |
17 namespace base { | |
18 class SequencedTaskRunner; | |
19 } | |
20 | |
21 namespace policy { | |
22 | |
23 // Class responsible for periodically uploading system logs, it handles the | |
24 // server responses by UploadJob:Delegate callbacks. | |
25 class SystemLogUploader : public UploadJob::Delegate { | |
26 public: | |
27 // A delegate interface used by SystemLogUploader to read the system logs | |
28 // from the disk and create an upload job. | |
29 class Delegate { | |
30 public: | |
31 // Structure that stores the system log files as pairs: (file name, loaded | |
32 // from the disk binary file data). | |
33 typedef std::vector<std::pair<std::string, std::string>> SystemLogs; | |
34 | |
35 typedef base::Callback<void(const SystemLogs* system_logs)> | |
36 LogUploadCallback; | |
37 | |
38 virtual ~Delegate() {} | |
39 | |
40 // Loads system logs and invokes |upload_callback|. | |
41 virtual void LoadSystemLogs(const LogUploadCallback& upload_callback) = 0; | |
42 | |
43 // Creates a new fully configured instance of an UploadJob. This method | |
44 // should be only called once per every scheduled system log upload. | |
Andrew T Wilson (Slow)
2015/07/31 12:07:13
Not "should be" but "will be called exactly once p
Polina Bondarenko
2015/07/31 13:52:03
Fixed, we create new upload job for every upload a
| |
45 virtual scoped_ptr<UploadJob> CreateUploadJob( | |
46 const GURL& upload_url, | |
47 UploadJob::Delegate* delegate) = 0; | |
48 }; | |
49 | |
50 explicit SystemLogUploader( | |
51 scoped_ptr<Delegate> syslog_delegate, | |
52 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | |
53 | |
54 ~SystemLogUploader() override; | |
55 | |
56 // Returns the time of the last upload attempt, or Time(0) if no upload has | |
57 // ever happened. | |
58 base::Time last_upload_attempt() const { return last_upload_attempt_; } | |
59 | |
60 // UploadJob::Delegate: | |
61 // Callbacks handle success and failure results of upload, destroy the | |
62 // upload job. | |
63 void OnSuccess() override; | |
64 void OnFailure(UploadJob::ErrorCode error_code) override; | |
65 | |
66 private: | |
67 // Starts the system log loading process. | |
68 void StartLogUpload(); | |
69 | |
70 // Starts the system log upload. | |
71 void UploadSystemLogs(const Delegate::SystemLogs* system_logs); | |
72 | |
73 // Helper method that figures out when the next system log upload should | |
74 // be scheduled. | |
75 void ScheduleNextSystemLogUpload(base::TimeDelta frequency); | |
76 | |
77 // The number of consequent retries after the failed uploads. | |
78 int retry_count_; | |
79 | |
80 // How long to wait between system log uploads. | |
81 base::TimeDelta upload_frequency_; | |
82 | |
83 // The time the last upload attempt was performed. | |
84 base::Time last_upload_attempt_; | |
85 | |
86 // TaskRunner used for scheduling upload tasks. | |
87 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
88 | |
89 // The upload job that is re-created on every system log upload. | |
90 scoped_ptr<UploadJob> upload_job_; | |
91 | |
92 // The Delegate is used to load system logs and create UploadJobs. | |
93 scoped_ptr<Delegate> syslog_delegate_; | |
94 | |
95 base::ThreadChecker thread_checker_; | |
96 | |
97 // Note: This should remain the last member so it'll be destroyed and | |
98 // invalidate the weak pointers before any other members are destroyed. | |
99 base::WeakPtrFactory<SystemLogUploader> weak_factory_; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(SystemLogUploader); | |
102 }; | |
103 | |
104 } // namespace policy | |
105 | |
106 #endif // CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_ | |
OLD | NEW |