Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / slow_trace_ui.cc
blob208a816ea99315b7c1a4023a6399217672e295e9
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"
7 #include "base/bind.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/feedback/tracing_manager.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/url_constants.h"
14 #include "content/public/browser/url_data_source.h"
15 #include "content/public/browser/web_ui.h"
16 #include "grit/theme_resources.h"
17 #include "ui/base/resource/resource_bundle.h"
19 namespace chromeos {
21 ////////////////////////////////////////////////////////////////////////////////
23 // SlowTraceSource
25 ////////////////////////////////////////////////////////////////////////////////
27 SlowTraceSource::SlowTraceSource() {
30 std::string SlowTraceSource::GetSource() const {
31 return chrome::kChromeUISlowTraceHost;
34 void SlowTraceSource::StartDataRequest(
35 const std::string& path,
36 int render_process_id,
37 int render_frame_id,
38 const content::URLDataSource::GotDataCallback& callback) {
39 int trace_id = 0;
40 size_t pos = path.find('#');
41 TracingManager* manager = TracingManager::Get();
42 if (!manager ||
43 pos == std::string::npos ||
44 !base::StringToInt(path.substr(pos + 1), &trace_id)) {
45 callback.Run(NULL);
46 return;
48 manager->GetTraceData(trace_id,
49 base::Bind(&SlowTraceSource::OnGetTraceData,
50 base::Unretained(this),
51 callback));
54 std::string SlowTraceSource::GetMimeType(const std::string& path) const {
55 return "application/zip";
58 SlowTraceSource::~SlowTraceSource() {}
60 void SlowTraceSource::OnGetTraceData(
61 const content::URLDataSource::GotDataCallback& callback,
62 scoped_refptr<base::RefCountedString> trace_data) {
63 callback.Run(trace_data);
66 ////////////////////////////////////////////////////////////////////////////////
68 // SlowTraceController
70 ////////////////////////////////////////////////////////////////////////////////
72 SlowTraceController::SlowTraceController(content::WebUI* web_ui)
73 : WebUIController(web_ui) {
74 SlowTraceSource* html_source = new SlowTraceSource();
76 // Set up the chrome://slow_trace/ source.
77 Profile* profile = Profile::FromWebUI(web_ui);
78 content::URLDataSource::Add(profile, html_source);
81 } // namespace chromeos