1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chromeos/slow_trace_ui.h"
8 #include "base/memory/ref_counted_memory.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/url_constants.h"
13 #include "components/feedback/tracing_manager.h"
14 #include "content/public/browser/url_data_source.h"
15 #include "content/public/browser/web_ui.h"
19 ////////////////////////////////////////////////////////////////////////////////
23 ////////////////////////////////////////////////////////////////////////////////
25 SlowTraceSource::SlowTraceSource() {
28 std::string
SlowTraceSource::GetSource() const {
29 return chrome::kChromeUISlowTraceHost
;
32 void SlowTraceSource::StartDataRequest(
33 const std::string
& path
,
34 int render_process_id
,
36 const content::URLDataSource::GotDataCallback
& callback
) {
38 size_t pos
= path
.find('#');
39 TracingManager
* manager
= TracingManager::Get();
41 pos
== std::string::npos
||
42 !base::StringToInt(path
.substr(pos
+ 1), &trace_id
)) {
46 manager
->GetTraceData(trace_id
,
47 base::Bind(&SlowTraceSource::OnGetTraceData
,
48 base::Unretained(this),
52 std::string
SlowTraceSource::GetMimeType(const std::string
& path
) const {
53 return "application/zip";
56 SlowTraceSource::~SlowTraceSource() {}
58 void SlowTraceSource::OnGetTraceData(
59 const content::URLDataSource::GotDataCallback
& callback
,
60 scoped_refptr
<base::RefCountedString
> trace_data
) {
61 callback
.Run(trace_data
.get());
64 ////////////////////////////////////////////////////////////////////////////////
66 // SlowTraceController
68 ////////////////////////////////////////////////////////////////////////////////
70 SlowTraceController::SlowTraceController(content::WebUI
* web_ui
)
71 : WebUIController(web_ui
) {
72 SlowTraceSource
* html_source
= new SlowTraceSource();
74 // Set up the chrome://slow_trace/ source.
75 Profile
* profile
= Profile::FromWebUI(web_ui
);
76 content::URLDataSource::Add(profile
, html_source
);
79 } // namespace chromeos