OLD | NEW |
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 "chrome/browser/ui/webui/profiler_ui.h" | 5 #include "chrome/browser/ui/webui/profiler_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 // When testing the javacript code, it is cumbersome to have to keep | 9 // When testing the javacript code, it is cumbersome to have to keep |
10 // re-building the resouces package and reloading the browser. To solve | 10 // re-building the resouces package and reloading the browser. To solve |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // this class's methods are expected to run on the UI thread. | 114 // this class's methods are expected to run on the UI thread. |
115 class ProfilerMessageHandler : public WebUIMessageHandler { | 115 class ProfilerMessageHandler : public WebUIMessageHandler { |
116 public: | 116 public: |
117 ProfilerMessageHandler() {} | 117 ProfilerMessageHandler() {} |
118 | 118 |
119 // WebUIMessageHandler implementation. | 119 // WebUIMessageHandler implementation. |
120 void RegisterMessages() override; | 120 void RegisterMessages() override; |
121 | 121 |
122 // Messages. | 122 // Messages. |
123 void OnGetData(const base::ListValue* list); | 123 void OnGetData(const base::ListValue* list); |
124 void OnResetData(const base::ListValue* list); | |
125 | 124 |
126 private: | 125 private: |
127 DISALLOW_COPY_AND_ASSIGN(ProfilerMessageHandler); | 126 DISALLOW_COPY_AND_ASSIGN(ProfilerMessageHandler); |
128 }; | 127 }; |
129 | 128 |
130 void ProfilerMessageHandler::RegisterMessages() { | 129 void ProfilerMessageHandler::RegisterMessages() { |
131 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 130 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
132 | 131 |
133 web_ui()->RegisterMessageCallback("getData", | 132 web_ui()->RegisterMessageCallback("getData", |
134 base::Bind(&ProfilerMessageHandler::OnGetData, base::Unretained(this))); | 133 base::Bind(&ProfilerMessageHandler::OnGetData, base::Unretained(this))); |
135 web_ui()->RegisterMessageCallback("resetData", | |
136 base::Bind(&ProfilerMessageHandler::OnResetData, | |
137 base::Unretained(this))); | |
138 } | 134 } |
139 | 135 |
140 void ProfilerMessageHandler::OnGetData(const base::ListValue* list) { | 136 void ProfilerMessageHandler::OnGetData(const base::ListValue* list) { |
141 ProfilerUI* profiler_ui = static_cast<ProfilerUI*>(web_ui()->GetController()); | 137 ProfilerUI* profiler_ui = static_cast<ProfilerUI*>(web_ui()->GetController()); |
142 profiler_ui->GetData(); | 138 profiler_ui->GetData(); |
143 } | 139 } |
144 | 140 |
145 void ProfilerMessageHandler::OnResetData(const base::ListValue* list) { | |
146 tracked_objects::ThreadData::ResetAllThreadData(); | |
147 } | |
148 | |
149 } // namespace | 141 } // namespace |
150 | 142 |
151 ProfilerUI::ProfilerUI(content::WebUI* web_ui) | 143 ProfilerUI::ProfilerUI(content::WebUI* web_ui) |
152 : WebUIController(web_ui), | 144 : WebUIController(web_ui), |
153 weak_ptr_factory_(this) { | 145 weak_ptr_factory_(this) { |
154 web_ui->AddMessageHandler(new ProfilerMessageHandler()); | 146 web_ui->AddMessageHandler(new ProfilerMessageHandler()); |
155 | 147 |
156 // Set up the chrome://profiler/ source. | 148 // Set up the chrome://profiler/ source. |
157 Profile* profile = Profile::FromWebUI(web_ui); | 149 Profile* profile = Profile::FromWebUI(web_ui); |
158 #if defined(USE_SOURCE_FILES_DIRECTLY) | 150 #if defined(USE_SOURCE_FILES_DIRECTLY) |
(...skipping 16 matching lines...) Expand all Loading... |
175 int process_type) { | 167 int process_type) { |
176 // Serialize the data to JSON. | 168 // Serialize the data to JSON. |
177 base::DictionaryValue json_data; | 169 base::DictionaryValue json_data; |
178 task_profiler::TaskProfilerDataSerializer::ToValue(profiler_data, | 170 task_profiler::TaskProfilerDataSerializer::ToValue(profiler_data, |
179 process_type, | 171 process_type, |
180 &json_data); | 172 &json_data); |
181 | 173 |
182 // Send the data to the renderer. | 174 // Send the data to the renderer. |
183 web_ui()->CallJavascriptFunction("g_browserBridge.receivedData", json_data); | 175 web_ui()->CallJavascriptFunction("g_browserBridge.receivedData", json_data); |
184 } | 176 } |
OLD | NEW |