Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/chromeos/system_logs/debug_log_writer.cc

Issue 2081153002: No dbus::FileDescriptor in DebugDaemonClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/log_private/log_private_apitest_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/chromeos/system_logs/debug_log_writer.h" 5 #include "chrome/browser/chromeos/system_logs/debug_log_writer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 base::Bind(callback, file_path, false)); 55 base::Bind(callback, file_path, false));
56 DCHECK(posted); 56 DCHECK(posted);
57 return; 57 return;
58 } 58 }
59 if (!callback.is_null()) 59 if (!callback.is_null())
60 callback.Run(file_path, true); 60 callback.Run(file_path, true);
61 } 61 }
62 62
63 // Stores into |file_path| debug logs in the .tgz format. Calls 63 // Stores into |file_path| debug logs in the .tgz format. Calls
64 // |callback| upon completion. 64 // |callback| upon completion.
65 void WriteDebugLogToFile(base::File* file, 65 void WriteDebugLogToFile(std::unique_ptr<base::File> file,
66 const std::string& sequence_token_name, 66 const std::string& sequence_token_name,
67 const base::FilePath& file_path, 67 const base::FilePath& file_path,
68 bool should_compress, 68 bool should_compress,
69 const DebugLogWriter::StoreLogsCallback& callback) { 69 const DebugLogWriter::StoreLogsCallback& callback) {
70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
71 if (!file->IsValid()) { 71 if (!file->IsValid()) {
72 LOG(ERROR) << "Can't create debug log file: " << file_path.AsUTF8Unsafe() 72 LOG(ERROR) << "Can't create debug log file: " << file_path.AsUTF8Unsafe()
73 << ", " 73 << ", "
74 << "error: " << file->error_details(); 74 << "error: " << file->error_details();
75 return; 75 return;
76 } 76 }
77 scoped_refptr<base::TaskRunner> task_runner =
78 GetSequencedTaskRunner(sequence_token_name);
79 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->DumpDebugLogs( 77 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->DumpDebugLogs(
80 should_compress, std::move(*file), task_runner, 78 should_compress, file->GetPlatformFile(),
81 base::Bind(&WriteDebugLogToFileCompleted, file_path, sequence_token_name, 79 base::Bind(&WriteDebugLogToFileCompleted, file_path, sequence_token_name,
82 callback)); 80 callback));
81
82 // Close the file on an IO-allowed thread.
83 GetSequencedTaskRunner(sequence_token_name)
84 ->PostTask(FROM_HERE,
85 base::Bind(&base::DeletePointer<base::File>, file.release()));
83 } 86 }
84 87
85 // Runs command with its parameters as defined in |argv|. 88 // Runs command with its parameters as defined in |argv|.
86 // Upon completion, it will report command run outcome via |callback| on the 89 // Upon completion, it will report command run outcome via |callback| on the
87 // same thread from where it was initially called from. 90 // same thread from where it was initially called from.
88 void RunCommand(const std::vector<std::string>& argv, 91 void RunCommand(const std::vector<std::string>& argv,
89 const CommandCompletionCallback& callback) { 92 const CommandCompletionCallback& callback) {
90 base::Process process = base::LaunchProcess(argv, base::LaunchOptions()); 93 base::Process process = base::LaunchProcess(argv, base::LaunchOptions());
91 if (!process.IsValid()) { 94 if (!process.IsValid()) {
92 LOG(ERROR) << "Failed to execute command " << argv[0]; 95 LOG(ERROR) << "Failed to execute command " << argv[0];
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 196
194 content::BrowserThread::PostBlockingPoolTask( 197 content::BrowserThread::PostBlockingPoolTask(
195 FROM_HERE, 198 FROM_HERE,
196 base::Bind(&AddUserLogsToArchive, 199 base::Bind(&AddUserLogsToArchive,
197 user_log_dir, 200 user_log_dir,
198 tar_file_path, 201 tar_file_path,
199 compressed_output_path, 202 compressed_output_path,
200 callback)); 203 callback));
201 } 204 }
202 205
203 void IntializeLogFile(base::File* file, 206 void InitializeLogFile(base::File* file,
204 const base::FilePath& file_path, 207 const base::FilePath& file_path,
205 uint32_t flags) { 208 uint32_t flags) {
206 base::FilePath dir = file_path.DirName(); 209 base::FilePath dir = file_path.DirName();
207 if (!base::DirectoryExists(dir)) { 210 if (!base::DirectoryExists(dir)) {
208 if (!base::CreateDirectory(dir)) { 211 if (!base::CreateDirectory(dir)) {
209 LOG(ERROR) << "Can not create " << dir.value(); 212 LOG(ERROR) << "Can not create " << dir.value();
210 return; 213 return;
211 } 214 }
212 } 215 }
213 216
214 file->Initialize(file_path, flags); 217 file->Initialize(file_path, flags);
215 } 218 }
216 219
217 // Starts logs retrieval process. The output will be stored in file with name 220 // Starts logs retrieval process. The output will be stored in file with name
218 // derived from |file_name_template|. 221 // derived from |file_name_template|.
219 void StartLogRetrieval(const base::FilePath& file_name_template, 222 void StartLogRetrieval(const base::FilePath& file_name_template,
220 bool should_compress, 223 bool should_compress,
221 const std::string& sequence_token_name, 224 const std::string& sequence_token_name,
222 const DebugLogWriter::StoreLogsCallback& callback) { 225 const DebugLogWriter::StoreLogsCallback& callback) {
223 base::FilePath file_path = 226 base::FilePath file_path =
224 logging::GenerateTimestampedName(file_name_template, base::Time::Now()); 227 logging::GenerateTimestampedName(file_name_template, base::Time::Now());
225 228
226 int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE; 229 int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE;
227 base::File* file = new base::File; 230 std::unique_ptr<base::File> file(new base::File);
228 GetSequencedTaskRunner(sequence_token_name)->PostTaskAndReply( 231 base::File* file_ptr = file.get();
229 FROM_HERE, 232 GetSequencedTaskRunner(sequence_token_name)
230 base::Bind(&IntializeLogFile, base::Unretained(file), file_path, flags), 233 ->PostTaskAndReply(
231 base::Bind(&WriteDebugLogToFile, 234 FROM_HERE, base::Bind(&InitializeLogFile, base::Unretained(file_ptr),
232 base::Owned(file), 235 file_path, flags),
233 sequence_token_name, 236 base::Bind(&WriteDebugLogToFile, base::Passed(&file),
234 file_path, 237 sequence_token_name, file_path, should_compress,
235 should_compress, 238 callback));
236 callback));
237 } 239 }
238 240
239 const char kDefaultSequenceName[] = "DebugLogWriter"; 241 const char kDefaultSequenceName[] = "DebugLogWriter";
240 242
241 } // namespace 243 } // namespace
242 244
243 // static. 245 // static.
244 void DebugLogWriter::StoreLogs(const base::FilePath& fileshelf, 246 void DebugLogWriter::StoreLogs(const base::FilePath& fileshelf,
245 bool should_compress, 247 bool should_compress,
246 const StoreLogsCallback& callback) { 248 const StoreLogsCallback& callback) {
(...skipping 18 matching lines...) Expand all
265 fileshelf.Append(FILE_PATH_LITERAL("combined-logs.tar")); 267 fileshelf.Append(FILE_PATH_LITERAL("combined-logs.tar"));
266 268
267 // Get system logs from /var/log first, then add user-specific stuff. 269 // Get system logs from /var/log first, then add user-specific stuff.
268 StartLogRetrieval(file_path, 270 StartLogRetrieval(file_path,
269 false, 271 false,
270 sequence_token_name, 272 sequence_token_name,
271 base::Bind(&OnSystemLogsAdded, callback)); 273 base::Bind(&OnSystemLogsAdded, callback));
272 } 274 }
273 275
274 } // namespace chromeos 276 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/log_private/log_private_apitest_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698