Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / slow_trace_ui.cc
blobbdd3968991cbd3071a3059ab1b6cef5b31d7971d
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/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"
17 namespace chromeos {
19 ////////////////////////////////////////////////////////////////////////////////
21 // SlowTraceSource
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,
35 int render_frame_id,
36 const content::URLDataSource::GotDataCallback& callback) {
37 int trace_id = 0;
38 size_t pos = path.find('#');
39 TracingManager* manager = TracingManager::Get();
40 if (!manager ||
41 pos == std::string::npos ||
42 !base::StringToInt(path.substr(pos + 1), &trace_id)) {
43 callback.Run(NULL);
44 return;
46 manager->GetTraceData(trace_id,
47 base::Bind(&SlowTraceSource::OnGetTraceData,
48 base::Unretained(this),
49 callback));
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