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

Side by Side Diff: content/browser/tracing/tracing_controller_impl.cc

Issue 573963007: DCHECK written counts from fwrite to fix unused return result. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "content/browser/tracing/tracing_controller_impl.h" 4 #include "content/browser/tracing/tracing_controller_impl.h"
5 5
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/json/string_escape.h" 9 #include "base/json/string_escape.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 base::Bind(&FileTraceDataSink::CloseOnFileThread, this)); 62 base::Bind(&FileTraceDataSink::CloseOnFileThread, this));
63 } 63 }
64 64
65 private: 65 private:
66 virtual ~FileTraceDataSink() { DCHECK(file_ == NULL); } 66 virtual ~FileTraceDataSink() { DCHECK(file_ == NULL); }
67 67
68 void AddTraceChunkOnFileThread( 68 void AddTraceChunkOnFileThread(
69 const scoped_refptr<base::RefCountedString> chunk) { 69 const scoped_refptr<base::RefCountedString> chunk) {
70 if (!OpenFileIfNeededOnFileThread()) 70 if (!OpenFileIfNeededOnFileThread())
71 return; 71 return;
72 fwrite(chunk->data().c_str(), strlen(chunk->data().c_str()), 1, file_); 72 size_t written = fwrite(chunk->data().c_str(),
73 strlen(chunk->data().c_str()), 1, file_);
74 DCHECK_EQ(1u, written);
73 } 75 }
74 76
75 bool OpenFileIfNeededOnFileThread() { 77 bool OpenFileIfNeededOnFileThread() {
76 if (file_ != NULL) 78 if (file_ != NULL)
77 return true; 79 return true;
78 file_ = base::OpenFile(file_path_, "w"); 80 file_ = base::OpenFile(file_path_, "w");
79 if (file_ == NULL) { 81 if (file_ == NULL) {
80 LOG(ERROR) << "Failed to open " << file_path_.value(); 82 LOG(ERROR) << "Failed to open " << file_path_.value();
81 return false; 83 return false;
82 } 84 }
83 const char preamble[] = "{\"traceEvents\": ["; 85 const char preamble[] = "{\"traceEvents\": [";
84 fwrite(preamble, strlen(preamble), 1, file_); 86 size_t written = fwrite(preamble, strlen(preamble), 1, file_);
87 DCHECK_EQ(1u, written);
85 return true; 88 return true;
86 } 89 }
87 90
88 void CloseOnFileThread() { 91 void CloseOnFileThread() {
89 if (OpenFileIfNeededOnFileThread()) { 92 if (OpenFileIfNeededOnFileThread()) {
90 fputc(']', file_); 93 fputc(']', file_);
91 if (!system_trace_.empty()) { 94 if (!system_trace_.empty()) {
92 const char systemTraceEvents[] = ",\"systemTraceEvents\": "; 95 const char systemTraceEvents[] = ",\"systemTraceEvents\": ";
93 fwrite(systemTraceEvents, strlen(systemTraceEvents), 1, file_); 96 size_t written = fwrite(systemTraceEvents, strlen(systemTraceEvents),
94 fwrite(system_trace_.c_str(), strlen(system_trace_.c_str()), 1, file_); 97 1, file_);
98 DCHECK_EQ(1u, written);
99 written = fwrite(system_trace_.c_str(),
100 strlen(system_trace_.c_str()), 1, file_);
101 DCHECK_EQ(1u, written);
95 } 102 }
96 fputc('}', file_); 103 fputc('}', file_);
97 base::CloseFile(file_); 104 base::CloseFile(file_);
98 file_ = NULL; 105 file_ = NULL;
99 } 106 }
100 BrowserThread::PostTask( 107 BrowserThread::PostTask(
101 BrowserThread::UI, 108 BrowserThread::UI,
102 FROM_HERE, 109 FROM_HERE,
103 base::Bind(&FileTraceDataSink::FinalizeOnUIThread, this)); 110 base::Bind(&FileTraceDataSink::FinalizeOnUIThread, this));
104 } 111 }
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 is_monitoring_ = is_monitoring; 878 is_monitoring_ = is_monitoring;
872 #if !defined(OS_ANDROID) 879 #if !defined(OS_ANDROID)
873 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); 880 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin();
874 it != tracing_uis_.end(); it++) { 881 it != tracing_uis_.end(); it++) {
875 (*it)->OnMonitoringStateChanged(is_monitoring); 882 (*it)->OnMonitoringStateChanged(is_monitoring);
876 } 883 }
877 #endif 884 #endif
878 } 885 }
879 886
880 } // namespace content 887 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698