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

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

Issue 117323008: Return error on JSON request failures (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/tracing/tracing_ui.h" 5 #include "content/browser/tracing/tracing_ui.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 114
115 void BeginReadingRecordingResult( 115 void BeginReadingRecordingResult(
116 const WebUIDataSource::GotDataCallback& callback, 116 const WebUIDataSource::GotDataCallback& callback,
117 const base::FilePath& path) { 117 const base::FilePath& path) {
118 BrowserThread::PostTask( 118 BrowserThread::PostTask(
119 BrowserThread::FILE, FROM_HERE, 119 BrowserThread::FILE, FROM_HERE,
120 base::Bind(ReadRecordingResult, callback, path)); 120 base::Bind(ReadRecordingResult, callback, path));
121 } 121 }
122 122
123 bool OnBeginRequest(const std::string& path, 123 bool OnBeginJSONRequest(const std::string& path,
124 const WebUIDataSource::GotDataCallback& callback) { 124 const WebUIDataSource::GotDataCallback& callback) {
125 if (path == "json/categories") { 125 if (path == "json/categories") {
126 TracingController::GetInstance()->GetCategories( 126 return TracingController::GetInstance()->GetCategories(
127 base::Bind(OnGotCategories, callback)); 127 base::Bind(OnGotCategories, callback));
128 return true;
129 } 128 }
130 const char* beginRecordingPath = "json/begin_recording?"; 129 const char* beginRecordingPath = "json/begin_recording?";
131 if (path.find(beginRecordingPath) == 0) { 130 if (StartsWithASCII(path, beginRecordingPath, true)) {
132 std::string data = path.substr(strlen(beginRecordingPath)); 131 std::string data = path.substr(strlen(beginRecordingPath));
133 return OnBeginRecording(data, callback); 132 return OnBeginRecording(data, callback);
134 } 133 }
135 if (path == "json/get_buffer_percent_full") { 134 if (path == "json/get_buffer_percent_full") {
136 return TracingController::GetInstance()->GetTraceBufferPercentFull( 135 return TracingController::GetInstance()->GetTraceBufferPercentFull(
137 base::Bind(OnTraceBufferPercentFullResult, callback)); 136 base::Bind(OnTraceBufferPercentFullResult, callback));
138 } 137 }
139 if (path == "json/end_recording") { 138 if (path == "json/end_recording") {
140 return TracingController::GetInstance()->DisableRecording( 139 return TracingController::GetInstance()->DisableRecording(
141 base::FilePath(), base::Bind(BeginReadingRecordingResult, callback)); 140 base::FilePath(), base::Bind(BeginReadingRecordingResult, callback));
142 } 141 }
143 if (StartsWithASCII(path, "json/", true)) 142 LOG(ERROR) << "Unhandled request to " << path;
144 LOG(ERROR) << "Unhandled request to " << path;
145 return false; 143 return false;
146 } 144 }
147 145
146 bool OnBeginRequest(const std::string& path,
147 const WebUIDataSource::GotDataCallback& callback) {
148 if (StartsWithASCII(path, "json/", true)) {
149 if (!OnBeginJSONRequest(path, callback)) {
150 std::string error("##ERROR##");
dsinclair 2014/01/06 15:20:33 Why not make this valid json? {"error": "invalid p
Xianzhu 2014/01/06 17:11:27 I didn't think of this, just randomly selected the
151 callback.Run(base::RefCountedString::TakeString(&error));
152 }
153 return true;
154 }
155 return false;
156 }
157
148 } // namespace 158 } // namespace
149 159
150 160
151 //////////////////////////////////////////////////////////////////////////////// 161 ////////////////////////////////////////////////////////////////////////////////
152 // 162 //
153 // TracingUI 163 // TracingUI
154 // 164 //
155 //////////////////////////////////////////////////////////////////////////////// 165 ////////////////////////////////////////////////////////////////////////////////
156 166
157 TracingUI::TracingUI(WebUI* web_ui) : WebUIController(web_ui) { 167 TracingUI::TracingUI(WebUI* web_ui) : WebUIController(web_ui) {
158 // Set up the chrome://tracing/ source. 168 // Set up the chrome://tracing/ source.
159 BrowserContext* browser_context = 169 BrowserContext* browser_context =
160 web_ui->GetWebContents()->GetBrowserContext(); 170 web_ui->GetWebContents()->GetBrowserContext();
161 171
162 WebUIDataSource* source = WebUIDataSource::Create(kChromeUITracingHost); 172 WebUIDataSource* source = WebUIDataSource::Create(kChromeUITracingHost);
163 source->SetJsonPath("strings.js"); 173 source->SetJsonPath("strings.js");
164 source->SetDefaultResource(IDR_TRACING_HTML); 174 source->SetDefaultResource(IDR_TRACING_HTML);
165 source->AddResourcePath("tracing.js", IDR_TRACING_JS); 175 source->AddResourcePath("tracing.js", IDR_TRACING_JS);
166 source->SetRequestFilter(base::Bind(OnBeginRequest)); 176 source->SetRequestFilter(base::Bind(OnBeginRequest));
167 WebUIDataSource::Add(browser_context, source); 177 WebUIDataSource::Add(browser_context, source);
168 } 178 }
169 179
170 } // namespace content 180 } // 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