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 typedef base::Callback<void( | |
20 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
| |
21 | |
22 class Delegate { | |
23 public: | |
24 virtual ~Delegate() {} | |
25 | |
26 // Loads system logs. | |
27 virtual void LoadSystemLogs(const LogUploadCallback& upload_callback) = 0; | |
28 | |
29 // Creates a new fully configured instance of an UploadJob. This method | |
30 // may be called any number of times. | |
31 virtual scoped_ptr<UploadJob> CreateUploadJob(const GURL&, | |
32 UploadJob::Delegate*) = 0; | |
33 }; | |
34 | |
35 // Constructor. | |
36 explicit SystemLogUploadJob(scoped_ptr<Delegate> syslog_delegate); | |
37 | |
38 // Destructor. | |
39 ~SystemLogUploadJob() override; | |
40 | |
41 // Start system log upload. | |
42 void Run(const base::Closure& succeeded_callback, | |
43 const base::Closure& failed_callback); | |
44 // 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.
| |
45 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.
| |
46 | |
47 private: | |
48 // UploadJob::Delegate: | |
49 void OnSuccess() override; | |
50 void OnFailure(UploadJob::ErrorCode error_code) override; | |
51 | |
52 // Callback invoked periodically to start loading system logs. | |
53 void StartLoadSystemLogs(); | |
54 | |
55 // Callback invoked when system logs are successfully loaded, | |
56 // starts system log upload. | |
57 void StartUploadSystemLogs( | |
58 const std::map<std::string, std::string>& system_logs); | |
59 | |
60 // The URL to which the POST request should be directed. | |
61 GURL upload_url_; | |
62 | |
63 // The callback that will be called when the system logs were successfully | |
64 // uploaded. | |
65 base::Closure succeeded_callback_; | |
66 | |
67 // The callback that will be called when system log upload failed. | |
68 base::Closure failed_callback_; | |
69 | |
70 // The Delegate is used to load system logs and create UploadJobs. | |
71 scoped_ptr<Delegate> syslog_delegate_; | |
72 | |
73 // The upload job instance that will upload the log files. | |
74 scoped_ptr<UploadJob> upload_job_; | |
75 | |
76 // Note: This should remain the last member so it'll be destroyed and | |
77 // invalidate the weak pointers before any other members are destroyed. | |
78 base::WeakPtrFactory<SystemLogUploadJob> weak_factory_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(SystemLogUploadJob); | |
81 }; | |
82 | |
83 } // namespace policy | |
84 #endif // CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOAD_JOB_H_ | |
OLD | NEW |