Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: chrome/browser/ui/webui/profiler_ui.cc

Issue 9224002: Make WebUI objects not derive from WebUI. WebUI objects own the controller. This is the ownership... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync to head to clear linux_chromeos browsertest failures Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/tracked_objects.h" 17 #include "base/tracked_objects.h"
18 #include "chrome/browser/metrics/tracking_synchronizer.h" 18 #include "chrome/browser/metrics/tracking_synchronizer.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 20 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
21 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
22 #include "content/browser/trace_controller.h" 22 #include "content/browser/trace_controller.h"
23 #include "content/browser/webui/web_ui.h"
23 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_ui_message_handler.h" 26 #include "content/public/browser/web_ui_message_handler.h"
26 #include "grit/browser_resources.h" 27 #include "grit/browser_resources.h"
27 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
28 29
29 #ifdef USE_SOURCE_FILES_DIRECTLY 30 #ifdef USE_SOURCE_FILES_DIRECTLY
30 #include "base/base_paths.h" 31 #include "base/base_paths.h"
31 #include "base/file_util.h" 32 #include "base/file_util.h"
32 #include "base/memory/ref_counted_memory.h" 33 #include "base/memory/ref_counted_memory.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 ProfilerUI* profiler_ui = reinterpret_cast<ProfilerUI*>(web_ui()); 138 ProfilerUI* profiler_ui = reinterpret_cast<ProfilerUI*>(web_ui());
138 profiler_ui->GetData(); 139 profiler_ui->GetData();
139 } 140 }
140 141
141 void ProfilerMessageHandler::OnResetData(const ListValue* list) { 142 void ProfilerMessageHandler::OnResetData(const ListValue* list) {
142 tracked_objects::ThreadData::ResetAllThreadData(); 143 tracked_objects::ThreadData::ResetAllThreadData();
143 } 144 }
144 145
145 } // namespace 146 } // namespace
146 147
147 ProfilerUI::ProfilerUI(WebContents* contents) : WebUI(contents, this) { 148 ProfilerUI::ProfilerUI(WebUI* web_ui) : WebUIController(web_ui) {
148 ui_weak_ptr_factory_.reset(new base::WeakPtrFactory<ProfilerUI>(this)); 149 ui_weak_ptr_factory_.reset(new base::WeakPtrFactory<ProfilerUI>(this));
149 ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr(); 150 ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr();
150 151
151 AddMessageHandler(new ProfilerMessageHandler()); 152 web_ui->AddMessageHandler(new ProfilerMessageHandler());
152 153
153 // Set up the chrome://profiler/ source. 154 // Set up the chrome://profiler/ source.
154 Profile::FromBrowserContext(contents->GetBrowserContext())-> 155 Profile::FromBrowserContext(web_ui->web_contents()->GetBrowserContext())->
155 GetChromeURLDataManager()->AddDataSource(CreateProfilerHTMLSource()); 156 GetChromeURLDataManager()->AddDataSource(CreateProfilerHTMLSource());
156 } 157 }
157 158
158 ProfilerUI::~ProfilerUI() { 159 ProfilerUI::~ProfilerUI() {
159 } 160 }
160 161
161 void ProfilerUI::GetData() { 162 void ProfilerUI::GetData() {
162 TrackingSynchronizer::FetchProfilerDataAsynchronously(ui_weak_ptr_); 163 TrackingSynchronizer::FetchProfilerDataAsynchronously(ui_weak_ptr_);
163 } 164 }
164 165
165 void ProfilerUI::ReceivedData(base::Value* value) { 166 void ProfilerUI::ReceivedData(base::Value* value) {
166 // Send the data to the renderer. 167 // Send the data to the renderer.
167 scoped_ptr<Value> data_values(value); 168 scoped_ptr<Value> data_values(value);
168 CallJavascriptFunction("g_browserBridge.receivedData", *data_values.get()); 169 web_ui()->CallJavascriptFunction(
170 "g_browserBridge.receivedData", *data_values.get());
169 } 171 }
170 172
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698