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

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

Issue 329853010: Additional methods for chrome.logPrivate API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: all works Created 6 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
Zachary Kuznia 2014/06/25 00:05:53 nit: no (c)
zel 2014/06/27 19:31:00 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/system_logs/debug_log_writer.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/file_util.h"
10 #include "base/files/file.h"
11 #include "chrome/common/logging_chrome.h"
12 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/debug_daemon_client.h"
14 #include "content/public/browser/browser_thread.h"
15
16 namespace chromeos {
17
18 namespace {
19
20 // Called upon completion of |WriteDebugLogToFile|. Closes file
21 // descriptor, deletes log file in the case of failure and calls
22 // |callback|.
23 void WriteDebugLogToFileCompleted(
24 const DebugLogWriter::StoreDebugLogsCallback& callback,
25 const base::FilePath& file_path,
26 bool succeeded) {
27 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
28 if (!succeeded) {
29 bool posted = content::BrowserThread::PostBlockingPoolTaskAndReply(
30 FROM_HERE,
31 base::Bind(base::IgnoreResult(&base::DeleteFile), file_path, false),
32 base::Bind(callback, file_path, false));
33 DCHECK(posted);
34 return;
35 }
36 callback.Run(file_path, true);
37 }
38
39 // Stores into |file_path| debug logs in the .tgz format. Calls
40 // |callback| upon completion.
41 void WriteDebugLogToFile(
42 const DebugLogWriter::StoreDebugLogsCallback& callback,
43 base::File* file,
44 const base::FilePath& file_path) {
45 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
46 if (!file->IsValid()) {
47 LOG(ERROR) <<
Zachary Kuznia 2014/06/25 00:05:53 I think we currently prefer VLOG(1)
zel 2014/06/27 19:31:00 VLOG(1) gets recorded nowhere. This is really an e
48 "Can't create debug log file: " << file_path.AsUTF8Unsafe() << ", " <<
49 "error: " << file->error_details();
50 return;
51 }
52 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->GetDebugLogs(
53 file->Pass(),
54 base::Bind(&WriteDebugLogToFileCompleted, callback, file_path));
55 }
56
57 } // namespace
58
59 // static.
60 void DebugLogWriter::StoreLogs(
61 const base::FilePath& fileshelf,
62 const StoreDebugLogsCallback& callback) {
63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
64 DCHECK(!callback.is_null());
65
66 const base::FilePath::CharType kLogFileName[] =
67 FILE_PATH_LITERAL("debug-log.tgz");
68
69 base::FilePath file_path = fileshelf.Append(kLogFileName);
70 file_path = logging::GenerateTimestampedName(file_path, base::Time::Now());
71
72 int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE;
xiaowenx 2014/06/25 05:30:44 Two spaces here after "=", intentional?
zel 2014/06/27 19:31:00 Done.
73 base::File* file = new base::File;
Zachary Kuznia 2014/06/25 00:05:53 Is there a reason not to make this a scoped_ptr?
74 bool posted = content::BrowserThread::PostBlockingPoolTaskAndReply(
75 FROM_HERE,
76 base::Bind(&base::File::Initialize,
77 base::Unretained(file), file_path, flags),
78 base::Bind(&WriteDebugLogToFile, callback, base::Owned(file), file_path));
79 DCHECK(posted);
80 }
81
82 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698