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 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chromeos/policy/system_log_uploader.h" | 12 #include "chrome/browser/chromeos/policy/system_log_uploader.h" |
13 #include "chrome/browser/chromeos/policy/upload_job_impl.h" | 13 #include "chrome/browser/chromeos/policy/upload_job_impl.h" |
14 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 14 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
15 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" | 15 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "net/http/http_request_headers.h" | 17 #include "net/http/http_request_headers.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 // Determines the time between log uploads. | |
21 const int64 kDefaultUploadDelayMs = 12 * 60 * 60 * 1000; // 12 hours | |
22 | |
23 // Determines the time, measured from the time of last failed upload, | |
24 // after which the log upload is retried. | |
25 const int64 kErrorUploadDelayMs = 120 * 1000; // 120 seconds | |
26 | |
27 // The maximum number of successive retries. | 20 // The maximum number of successive retries. |
28 const int kMaxNumRetries = 1; | 21 const int kMaxNumRetries = 1; |
29 | 22 |
30 // String constant defining the url we upload system logs to. | 23 // String constant defining the url we upload system logs to. |
31 const char* kSystemLogUploadUrl = | 24 const char* kSystemLogUploadUrl = |
32 "https://m.google.com/devicemanagement/data/api/upload"; | 25 "https://m.google.com/devicemanagement/data/api/upload"; |
33 | 26 |
34 // String constant identifying the header field which stores the file type. | |
35 const char* kFileTypeHeaderName = "File-Type"; | |
36 | |
37 // String constant signalling that the data segment contains log files. | |
38 const char* const kFileTypeLogFile = "log_file"; | |
39 | |
40 // String constant signalling that the segment contains a plain text. | |
41 const char* const kContentTypePlainText = "text/plain"; | |
42 | |
43 // Template string constant for populating the name field. | |
44 const char* const kNameFieldTemplate = "file%d"; | |
45 | |
46 // The file names of the system logs to upload. | 27 // The file names of the system logs to upload. |
47 // Note: do not add anything to this list without checking for PII in the file. | 28 // Note: do not add anything to this list without checking for PII in the file. |
48 const char* const kSystemLogFileNames[] = { | 29 const char* const kSystemLogFileNames[] = { |
49 "/var/log/bios_info.txt", "/var/log/chrome/chrome", | 30 "/var/log/bios_info.txt", "/var/log/chrome/chrome", |
50 "/var/log/eventlog.txt", "/var/log/messages", | 31 "/var/log/eventlog.txt", "/var/log/messages", |
51 "/var/log/net.log", "/var/log/platform_info.txt", | 32 "/var/log/net.log", "/var/log/platform_info.txt", |
52 "/var/log/ui/ui.LATEST", "/var/log/update_engine.log"}; | 33 "/var/log/ui/ui.LATEST", "/var/log/update_engine.log"}; |
53 | 34 |
54 // Reads the system log files as binary files, stores the files as pairs | 35 // Reads the system log files as binary files, stores the files as pairs |
55 // (file name, data) and returns. Called on blocking thread. | 36 // (file name, data) and returns. Called on blocking thread. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 return scoped_ptr<policy::UploadJob>(new policy::UploadJobImpl( | 97 return scoped_ptr<policy::UploadJob>(new policy::UploadJobImpl( |
117 upload_url, robot_account_id, device_oauth2_token_service, | 98 upload_url, robot_account_id, device_oauth2_token_service, |
118 system_request_context, delegate, | 99 system_request_context, delegate, |
119 make_scoped_ptr(new policy::UploadJobImpl::RandomMimeBoundaryGenerator))); | 100 make_scoped_ptr(new policy::UploadJobImpl::RandomMimeBoundaryGenerator))); |
120 } | 101 } |
121 | 102 |
122 } // namespace | 103 } // namespace |
123 | 104 |
124 namespace policy { | 105 namespace policy { |
125 | 106 |
| 107 // Determines the time between log uploads. |
| 108 const int64 SystemLogUploader::kDefaultUploadDelayMs = |
| 109 12 * 60 * 60 * 1000; // 12 hours |
| 110 |
| 111 // Determines the time, measured from the time of last failed upload, |
| 112 // after which the log upload is retried. |
| 113 const int64 SystemLogUploader::kErrorUploadDelayMs = 120 * 1000; // 120 seconds |
| 114 |
| 115 // String constant identifying the header field which stores the file type. |
| 116 const char* const SystemLogUploader::kFileTypeHeaderName = "File-Type"; |
| 117 |
| 118 // String constant signalling that the data segment contains log files. |
| 119 const char* const SystemLogUploader::kFileTypeLogFile = "log_file"; |
| 120 |
| 121 // String constant signalling that the segment contains a plain text. |
| 122 const char* const SystemLogUploader::kContentTypePlainText = "text/plain"; |
| 123 |
| 124 // Template string constant for populating the name field. |
| 125 const char* const SystemLogUploader::kNameFieldTemplate = "file%d"; |
| 126 |
126 SystemLogUploader::SystemLogUploader( | 127 SystemLogUploader::SystemLogUploader( |
127 scoped_ptr<Delegate> syslog_delegate, | 128 scoped_ptr<Delegate> syslog_delegate, |
128 const scoped_refptr<base::SequencedTaskRunner>& task_runner) | 129 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
129 : retry_count_(0), | 130 : retry_count_(0), |
130 upload_frequency_( | 131 upload_frequency_( |
131 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs)), | 132 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs)), |
132 task_runner_(task_runner), | 133 task_runner_(task_runner), |
133 syslog_delegate_(syslog_delegate.Pass()), | 134 syslog_delegate_(syslog_delegate.Pass()), |
134 weak_factory_(this) { | 135 weak_factory_(this) { |
135 if (!syslog_delegate_) | 136 if (!syslog_delegate_) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 base::TimeDelta()); | 212 base::TimeDelta()); |
212 // Ensure that we never have more than one pending delayed task. | 213 // Ensure that we never have more than one pending delayed task. |
213 weak_factory_.InvalidateWeakPtrs(); | 214 weak_factory_.InvalidateWeakPtrs(); |
214 task_runner_->PostDelayedTask(FROM_HERE, | 215 task_runner_->PostDelayedTask(FROM_HERE, |
215 base::Bind(&SystemLogUploader::StartLogUpload, | 216 base::Bind(&SystemLogUploader::StartLogUpload, |
216 weak_factory_.GetWeakPtr()), | 217 weak_factory_.GetWeakPtr()), |
217 delay); | 218 delay); |
218 } | 219 } |
219 | 220 |
220 } // namespace policy | 221 } // namespace policy |
OLD | NEW |