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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <memory> |
| 11 |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
12 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "chrome/browser/chromeos/policy/upload_job.h" | 18 #include "chrome/browser/chromeos/policy/upload_job.h" |
18 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 class SequencedTaskRunner; | 22 class SequencedTaskRunner; |
22 } | 23 } |
23 | 24 |
(...skipping 18 matching lines...) Expand all Loading... |
42 // Http header constants to upload. | 43 // Http header constants to upload. |
43 static const char* const kNameFieldTemplate; | 44 static const char* const kNameFieldTemplate; |
44 static const char* const kFileTypeHeaderName; | 45 static const char* const kFileTypeHeaderName; |
45 static const char* const kFileTypeLogFile; | 46 static const char* const kFileTypeLogFile; |
46 static const char* const kContentTypePlainText; | 47 static const char* const kContentTypePlainText; |
47 | 48 |
48 // A delegate interface used by SystemLogUploader to read the system logs | 49 // A delegate interface used by SystemLogUploader to read the system logs |
49 // from the disk and create an upload job. | 50 // from the disk and create an upload job. |
50 class Delegate { | 51 class Delegate { |
51 public: | 52 public: |
52 typedef base::Callback<void(scoped_ptr<SystemLogs> system_logs)> | 53 typedef base::Callback<void(std::unique_ptr<SystemLogs> system_logs)> |
53 LogUploadCallback; | 54 LogUploadCallback; |
54 | 55 |
55 virtual ~Delegate() {} | 56 virtual ~Delegate() {} |
56 | 57 |
57 // Loads system logs and invokes |upload_callback|. | 58 // Loads system logs and invokes |upload_callback|. |
58 virtual void LoadSystemLogs(const LogUploadCallback& upload_callback) = 0; | 59 virtual void LoadSystemLogs(const LogUploadCallback& upload_callback) = 0; |
59 | 60 |
60 // Creates a new fully configured instance of an UploadJob. This method | 61 // Creates a new fully configured instance of an UploadJob. This method |
61 // will be called exactly once per every system log upload. | 62 // will be called exactly once per every system log upload. |
62 virtual scoped_ptr<UploadJob> CreateUploadJob( | 63 virtual std::unique_ptr<UploadJob> CreateUploadJob( |
63 const GURL& upload_url, | 64 const GURL& upload_url, |
64 UploadJob::Delegate* delegate) = 0; | 65 UploadJob::Delegate* delegate) = 0; |
65 }; | 66 }; |
66 | 67 |
67 // Constructor. Callers can inject their own Delegate. A nullptr can be passed | 68 // Constructor. Callers can inject their own Delegate. A nullptr can be passed |
68 // for |syslog_delegate| to use the default implementation. | 69 // for |syslog_delegate| to use the default implementation. |
69 explicit SystemLogUploader( | 70 explicit SystemLogUploader( |
70 scoped_ptr<Delegate> syslog_delegate, | 71 std::unique_ptr<Delegate> syslog_delegate, |
71 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 72 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
72 | 73 |
73 ~SystemLogUploader() override; | 74 ~SystemLogUploader() override; |
74 | 75 |
75 // Returns the time of the last upload attempt, or Time(0) if no upload has | 76 // Returns the time of the last upload attempt, or Time(0) if no upload has |
76 // ever happened. | 77 // ever happened. |
77 base::Time last_upload_attempt() const { return last_upload_attempt_; } | 78 base::Time last_upload_attempt() const { return last_upload_attempt_; } |
78 | 79 |
79 // UploadJob::Delegate: | 80 // UploadJob::Delegate: |
80 // Callbacks handle success and failure results of upload, destroy the | 81 // Callbacks handle success and failure results of upload, destroy the |
81 // upload job. | 82 // upload job. |
82 void OnSuccess() override; | 83 void OnSuccess() override; |
83 void OnFailure(UploadJob::ErrorCode error_code) override; | 84 void OnFailure(UploadJob::ErrorCode error_code) override; |
84 | 85 |
85 // Remove lines from |data| that contain common PII (IP addresses, BSSIDs, | 86 // Remove lines from |data| that contain common PII (IP addresses, BSSIDs, |
86 // SSIDs, URLs, e-mail addresses). | 87 // SSIDs, URLs, e-mail addresses). |
87 static std::string RemoveSensitiveData( | 88 static std::string RemoveSensitiveData( |
88 feedback::AnonymizerTool* const anonymizer, | 89 feedback::AnonymizerTool* const anonymizer, |
89 const std::string& data); | 90 const std::string& data); |
90 | 91 |
91 private: | 92 private: |
92 // Updates the system log upload enabled field from settings. | 93 // Updates the system log upload enabled field from settings. |
93 void RefreshUploadSettings(); | 94 void RefreshUploadSettings(); |
94 | 95 |
95 // Starts the system log loading process. | 96 // Starts the system log loading process. |
96 void StartLogUpload(); | 97 void StartLogUpload(); |
97 | 98 |
98 // The callback is invoked by the Delegate if system logs have been loaded | 99 // The callback is invoked by the Delegate if system logs have been loaded |
99 // from disk, uploads system logs. | 100 // from disk, uploads system logs. |
100 void UploadSystemLogs(scoped_ptr<SystemLogs> system_logs); | 101 void UploadSystemLogs(std::unique_ptr<SystemLogs> system_logs); |
101 | 102 |
102 // Helper method that figures out when the next system log upload should | 103 // Helper method that figures out when the next system log upload should |
103 // be scheduled. | 104 // be scheduled. |
104 void ScheduleNextSystemLogUpload(base::TimeDelta frequency); | 105 void ScheduleNextSystemLogUpload(base::TimeDelta frequency); |
105 | 106 |
106 // The number of consequent retries after the failed uploads. | 107 // The number of consequent retries after the failed uploads. |
107 int retry_count_; | 108 int retry_count_; |
108 | 109 |
109 // How long to wait between system log uploads. | 110 // How long to wait between system log uploads. |
110 base::TimeDelta upload_frequency_; | 111 base::TimeDelta upload_frequency_; |
111 | 112 |
112 // The time the last upload attempt was performed. | 113 // The time the last upload attempt was performed. |
113 base::Time last_upload_attempt_; | 114 base::Time last_upload_attempt_; |
114 | 115 |
115 // TaskRunner used for scheduling upload tasks. | 116 // TaskRunner used for scheduling upload tasks. |
116 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 117 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
117 | 118 |
118 // The upload job that is re-created on every system log upload. | 119 // The upload job that is re-created on every system log upload. |
119 scoped_ptr<UploadJob> upload_job_; | 120 std::unique_ptr<UploadJob> upload_job_; |
120 | 121 |
121 // The Delegate is used to load system logs and create UploadJobs. | 122 // The Delegate is used to load system logs and create UploadJobs. |
122 scoped_ptr<Delegate> syslog_delegate_; | 123 std::unique_ptr<Delegate> syslog_delegate_; |
123 | 124 |
124 // True if system log upload is enabled. Kept cached in this object because | 125 // True if system log upload is enabled. Kept cached in this object because |
125 // CrosSettings can switch to an unstrusted state temporarily, and we want to | 126 // CrosSettings can switch to an unstrusted state temporarily, and we want to |
126 // use the last-known trusted values. | 127 // use the last-known trusted values. |
127 bool upload_enabled_; | 128 bool upload_enabled_; |
128 | 129 |
129 // Observer to changes in system log upload settings. | 130 // Observer to changes in system log upload settings. |
130 scoped_ptr<chromeos::CrosSettings::ObserverSubscription> | 131 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> |
131 upload_enabled_observer_; | 132 upload_enabled_observer_; |
132 | 133 |
133 base::ThreadChecker thread_checker_; | 134 base::ThreadChecker thread_checker_; |
134 | 135 |
135 // Note: This should remain the last member so it'll be destroyed and | 136 // Note: This should remain the last member so it'll be destroyed and |
136 // invalidate the weak pointers before any other members are destroyed. | 137 // invalidate the weak pointers before any other members are destroyed. |
137 base::WeakPtrFactory<SystemLogUploader> weak_factory_; | 138 base::WeakPtrFactory<SystemLogUploader> weak_factory_; |
138 | 139 |
139 DISALLOW_COPY_AND_ASSIGN(SystemLogUploader); | 140 DISALLOW_COPY_AND_ASSIGN(SystemLogUploader); |
140 }; | 141 }; |
141 | 142 |
142 } // namespace policy | 143 } // namespace policy |
143 | 144 |
144 #endif // CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_ | 145 #endif // CHROME_BROWSER_CHROMEOS_POLICY_SYSTEM_LOG_UPLOADER_H_ |
OLD | NEW |