OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
11 // this, enable the following flag to read the webapp's source files | 11 // this, enable the following flag to read the webapp's source files |
12 // directly off disk, so all you have to do is refresh the page to | 12 // directly off disk, so all you have to do is refresh the page to |
13 // test the modifications. | 13 // test the modifications. |
14 //#define USE_SOURCE_FILES_DIRECTLY | 14 //#define USE_SOURCE_FILES_DIRECTLY |
15 | 15 |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/memory/scoped_ptr.h" |
17 #include "base/tracked_objects.h" | 18 #include "base/tracked_objects.h" |
| 19 #include "base/values.h" |
18 #include "chrome/browser/metrics/tracking_synchronizer.h" | 20 #include "chrome/browser/metrics/tracking_synchronizer.h" |
19 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 22 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
21 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
22 #include "content/browser/trace_controller.h" | 24 #include "content/browser/trace_controller.h" |
23 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
25 #include "content/public/browser/web_ui.h" | 27 #include "content/public/browser/web_ui.h" |
26 #include "content/public/browser/web_ui_message_handler.h" | 28 #include "content/public/browser/web_ui_message_handler.h" |
27 #include "grit/browser_resources.h" | 29 #include "grit/browser_resources.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 void OnResetData(const ListValue* list); | 123 void OnResetData(const ListValue* list); |
122 | 124 |
123 private: | 125 private: |
124 DISALLOW_COPY_AND_ASSIGN(ProfilerMessageHandler); | 126 DISALLOW_COPY_AND_ASSIGN(ProfilerMessageHandler); |
125 }; | 127 }; |
126 | 128 |
127 void ProfilerMessageHandler::RegisterMessages() { | 129 void ProfilerMessageHandler::RegisterMessages() { |
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
129 | 131 |
130 web_ui()->RegisterMessageCallback("getData", | 132 web_ui()->RegisterMessageCallback("getData", |
131 base::Bind(&ProfilerMessageHandler::OnGetData,base::Unretained(this))); | 133 base::Bind(&ProfilerMessageHandler::OnGetData, base::Unretained(this))); |
132 web_ui()->RegisterMessageCallback("resetData", | 134 web_ui()->RegisterMessageCallback("resetData", |
133 base::Bind(&ProfilerMessageHandler::OnResetData, | 135 base::Bind(&ProfilerMessageHandler::OnResetData, |
134 base::Unretained(this))); | 136 base::Unretained(this))); |
135 } | 137 } |
136 | 138 |
137 void ProfilerMessageHandler::OnGetData(const ListValue* list) { | 139 void ProfilerMessageHandler::OnGetData(const ListValue* list) { |
138 ProfilerUI* profiler_ui = static_cast<ProfilerUI*>(web_ui()->GetController()); | 140 ProfilerUI* profiler_ui = static_cast<ProfilerUI*>(web_ui()->GetController()); |
139 profiler_ui->GetData(); | 141 profiler_ui->GetData(); |
140 } | 142 } |
141 | 143 |
142 void ProfilerMessageHandler::OnResetData(const ListValue* list) { | 144 void ProfilerMessageHandler::OnResetData(const ListValue* list) { |
143 tracked_objects::ThreadData::ResetAllThreadData(); | 145 tracked_objects::ThreadData::ResetAllThreadData(); |
144 } | 146 } |
145 | 147 |
146 } // namespace | 148 } // namespace |
147 | 149 |
148 ProfilerUI::ProfilerUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 150 ProfilerUI::ProfilerUI(content::WebUI* web_ui) |
149 ui_weak_ptr_factory_.reset(new base::WeakPtrFactory<ProfilerUI>(this)); | 151 : WebUIController(web_ui), |
150 ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr(); | 152 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
151 | |
152 web_ui->AddMessageHandler(new ProfilerMessageHandler()); | 153 web_ui->AddMessageHandler(new ProfilerMessageHandler()); |
153 | 154 |
154 // Set up the chrome://profiler/ source. | 155 // Set up the chrome://profiler/ source. |
155 Profile::FromWebUI(web_ui)-> | 156 Profile::FromWebUI(web_ui)-> |
156 GetChromeURLDataManager()->AddDataSource(CreateProfilerHTMLSource()); | 157 GetChromeURLDataManager()->AddDataSource(CreateProfilerHTMLSource()); |
157 } | 158 } |
158 | 159 |
159 ProfilerUI::~ProfilerUI() { | 160 ProfilerUI::~ProfilerUI() { |
160 } | 161 } |
161 | 162 |
162 void ProfilerUI::GetData() { | 163 void ProfilerUI::GetData() { |
163 TrackingSynchronizer::FetchProfilerDataAsynchronously(ui_weak_ptr_); | 164 TrackingSynchronizer::FetchProfilerDataAsynchronously( |
| 165 weak_ptr_factory_.GetWeakPtr()); |
164 } | 166 } |
165 | 167 |
166 void ProfilerUI::ReceivedData(base::Value* value) { | 168 void ProfilerUI::ReceivedProfilerData( |
| 169 const content::SerializedProfilerData& data) { |
167 // Send the data to the renderer. | 170 // Send the data to the renderer. |
168 scoped_ptr<Value> data_values(value); | 171 DictionaryValue data_values; |
169 web_ui()->CallJavascriptFunction( | 172 data.ToValue(&data_values); |
170 "g_browserBridge.receivedData", *data_values.get()); | 173 web_ui()->CallJavascriptFunction("g_browserBridge.receivedData", data_values); |
171 } | 174 } |
172 | |
OLD | NEW |