Index: chrome/browser/ui/webui/gpu_internals_ui.cc |
diff --git a/chrome/browser/ui/webui/gpu_internals_ui.cc b/chrome/browser/ui/webui/gpu_internals_ui.cc |
index 8088c55ffbe313b4d3e6fd75333302d6c0cd93b5..78bf5008a6c88ef5411f9aeb6f1532cc2acb86c0 100644 |
--- a/chrome/browser/ui/webui/gpu_internals_ui.cc |
+++ b/chrome/browser/ui/webui/gpu_internals_ui.cc |
@@ -4,49 +4,21 @@ |
#include "chrome/browser/ui/webui/gpu_internals_ui.h" |
-#include <algorithm> |
-#include <string> |
-#include <utility> |
-#include <vector> |
- |
#include "base/command_line.h" |
-#include "base/file_util.h" |
-#include "base/memory/singleton.h" |
-#include "base/message_loop.h" |
-#include "base/path_service.h" |
-#include "base/scoped_ptr.h" |
-#include "base/stringprintf.h" |
#include "base/string_number_conversions.h" |
-#include "base/string_piece.h" |
-#include "base/utf_string_conversions.h" |
+#include "base/stringprintf.h" |
#include "base/values.h" |
-#include "chrome/browser/browser_process.h" |
-#include "chrome/browser/io_thread.h" |
-#include "chrome/browser/net/chrome_net_log.h" |
-#include "chrome/browser/net/connection_tester.h" |
-#include "chrome/browser/net/passive_log_collector.h" |
-#include "chrome/browser/net/url_fixer_upper.h" |
#include "chrome/browser/profiles/profile.h" |
-#include "chrome/browser/ui/shell_dialogs.h" |
-#include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
-#include "chrome/common/chrome_paths.h" |
#include "chrome/common/chrome_version_info.h" |
-#include "chrome/common/jstemplate_builder.h" |
#include "chrome/common/url_constants.h" |
#include "content/browser/browser_thread.h" |
#include "content/browser/gpu/gpu_data_manager.h" |
-#include "content/browser/gpu/gpu_process_host.h" |
-#include "content/browser/renderer_host/render_view_host.h" |
#include "content/browser/tab_contents/tab_contents.h" |
-#include "content/browser/tab_contents/tab_contents_view.h" |
-#include "content/browser/trace_controller.h" |
+#include "content/browser/webui/web_ui.h" |
#include "grit/browser_resources.h" |
#include "grit/generated_resources.h" |
-#include "net/base/escape.h" |
-#include "net/url_request/url_request_context_getter.h" |
#include "ui/base/l10n/l10n_util.h" |
-#include "ui/base/resource/resource_bundle.h" |
namespace { |
@@ -65,9 +37,7 @@ ChromeWebUIDataSource* CreateGpuHTMLSource() { |
// this class's methods are expected to run on the UI thread. |
class GpuMessageHandler |
: public WebUIMessageHandler, |
- public SelectFileDialog::Listener, |
- public base::SupportsWeakPtr<GpuMessageHandler>, |
- public TraceSubscriber { |
+ public base::SupportsWeakPtr<GpuMessageHandler> { |
public: |
GpuMessageHandler(); |
virtual ~GpuMessageHandler(); |
@@ -77,33 +47,15 @@ class GpuMessageHandler |
virtual void RegisterMessages() OVERRIDE; |
// Messages |
- void OnBeginTracing(const ListValue* list); |
- void OnEndTracingAsync(const ListValue* list); |
void OnBrowserBridgeInitialized(const ListValue* list); |
void OnCallAsync(const ListValue* list); |
- void OnBeginRequestBufferPercentFull(const ListValue* list); |
- void OnLoadTraceFile(const ListValue* list); |
- void OnSaveTraceFile(const ListValue* list); |
// Submessages dispatched from OnCallAsync |
Value* OnRequestClientInfo(const ListValue* list); |
Value* OnRequestLogMessages(const ListValue* list); |
- // SelectFileDialog::Listener implementation |
- virtual void FileSelected(const FilePath& path, |
- int index, |
- void* params) OVERRIDE; |
- virtual void FileSelectionCanceled(void* params) OVERRIDE; |
- |
// Callbacks. |
void OnGpuInfoUpdate(); |
- void LoadTraceFileComplete(std::string* file_contents); |
- void SaveTraceFileComplete(); |
- |
- // TraceSubscriber implementation. |
- virtual void OnEndTracingComplete() OVERRIDE; |
- virtual void OnTraceDataCollected(const std::string& json_events) OVERRIDE; |
- virtual void OnTraceBufferPercentFullReply(float percent_full) OVERRIDE; |
// Executes the javascript function |function_name| in the renderer, passing |
// it the argument |value|. |
@@ -117,33 +69,6 @@ class GpuMessageHandler |
GpuDataManager* gpu_data_manager_; |
Callback0::Type* gpu_info_update_callback_; |
- |
- scoped_refptr<SelectFileDialog> select_trace_file_dialog_; |
- SelectFileDialog::Type select_trace_file_dialog_type_; |
- scoped_ptr<std::string> trace_data_to_save_; |
- |
- bool trace_enabled_; |
-}; |
- |
-class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> { |
- public: |
- explicit TaskProxy(const base::WeakPtr<GpuMessageHandler>& handler) |
- : handler_(handler) {} |
- void LoadTraceFileCompleteProxy(std::string* file_contents) { |
- if (handler_) |
- handler_->LoadTraceFileComplete(file_contents); |
- delete file_contents; |
- } |
- |
- void SaveTraceFileCompleteProxy() { |
- if (handler_) |
- handler_->SaveTraceFileComplete(); |
- } |
- |
- private: |
- base::WeakPtr<GpuMessageHandler> handler_; |
- friend class base::RefCountedThreadSafe<TaskProxy>; |
- DISALLOW_COPY_AND_ASSIGN(TaskProxy); |
}; |
//////////////////////////////////////////////////////////////////////////////// |
@@ -153,9 +78,7 @@ class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> { |
//////////////////////////////////////////////////////////////////////////////// |
GpuMessageHandler::GpuMessageHandler() |
- : gpu_info_update_callback_(NULL), |
- select_trace_file_dialog_type_(SelectFileDialog::SELECT_NONE), |
- trace_enabled_(false) { |
+ : gpu_info_update_callback_(NULL) { |
gpu_data_manager_ = GpuDataManager::GetInstance(); |
DCHECK(gpu_data_manager_); |
} |
@@ -165,12 +88,6 @@ GpuMessageHandler::~GpuMessageHandler() { |
gpu_data_manager_->RemoveGpuInfoUpdateCallback(gpu_info_update_callback_); |
delete gpu_info_update_callback_; |
} |
- |
- if (select_trace_file_dialog_) |
- select_trace_file_dialog_->ListenerDestroyed(); |
- |
- // If we are the current subscriber, this will result in ending tracing. |
- TraceController::GetInstance()->CancelSubscriber(this); |
} |
WebUIMessageHandler* GpuMessageHandler::Attach(WebUI* web_ui) { |
@@ -184,26 +101,11 @@ void GpuMessageHandler::RegisterMessages() { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
web_ui_->RegisterMessageCallback( |
- "beginTracing", |
- NewCallback(this, &GpuMessageHandler::OnBeginTracing)); |
- web_ui_->RegisterMessageCallback( |
- "endTracingAsync", |
- NewCallback(this, &GpuMessageHandler::OnEndTracingAsync)); |
- web_ui_->RegisterMessageCallback( |
"browserBridgeInitialized", |
NewCallback(this, &GpuMessageHandler::OnBrowserBridgeInitialized)); |
web_ui_->RegisterMessageCallback( |
"callAsync", |
NewCallback(this, &GpuMessageHandler::OnCallAsync)); |
- web_ui_->RegisterMessageCallback( |
- "beginRequestBufferPercentFull", |
- NewCallback(this, &GpuMessageHandler::OnBeginRequestBufferPercentFull)); |
- web_ui_->RegisterMessageCallback( |
- "loadTraceFile", |
- NewCallback(this, &GpuMessageHandler::OnLoadTraceFile)); |
- web_ui_->RegisterMessageCallback( |
- "saveTraceFile", |
- NewCallback(this, &GpuMessageHandler::OnSaveTraceFile)); |
} |
void GpuMessageHandler::OnCallAsync(const ListValue* args) { |
@@ -253,139 +155,6 @@ void GpuMessageHandler::OnCallAsync(const ListValue* args) { |
} |
} |
-void GpuMessageHandler::OnBeginRequestBufferPercentFull(const ListValue* list) { |
- TraceController::GetInstance()->GetTraceBufferPercentFullAsync(this); |
-} |
- |
-class ReadTraceFileTask : public Task { |
- public: |
- ReadTraceFileTask(TaskProxy* proxy, const FilePath& path) |
- : proxy_(proxy) |
- , path_(path) {} |
- |
- virtual void Run() { |
- std::string* file_contents = new std::string(); |
- if (!file_util::ReadFileToString(path_, file_contents)) { |
- delete file_contents; |
- return; |
- } |
- BrowserThread::PostTask( |
- BrowserThread::UI, FROM_HERE, |
- NewRunnableMethod(proxy_.get(), |
- &TaskProxy::LoadTraceFileCompleteProxy, |
- file_contents)); |
- } |
- |
- private: |
- scoped_refptr<TaskProxy> proxy_; |
- |
- // Path of the file to open. |
- const FilePath path_; |
-}; |
- |
-class WriteTraceFileTask : public Task { |
- public: |
- WriteTraceFileTask(TaskProxy* proxy, |
- const FilePath& path, |
- std::string* contents) |
- : proxy_(proxy) |
- , path_(path) |
- , contents_(contents) {} |
- |
- virtual void Run() { |
- if (!file_util::WriteFile(path_, contents_->c_str(), contents_->size())) |
- return; |
- BrowserThread::PostTask( |
- BrowserThread::UI, FROM_HERE, |
- NewRunnableMethod(proxy_.get(), |
- &TaskProxy::SaveTraceFileCompleteProxy)); |
- } |
- |
- private: |
- scoped_refptr<TaskProxy> proxy_; |
- |
- // Path of the file to save. |
- const FilePath path_; |
- |
- // What to save |
- scoped_ptr<std::string> contents_; |
-}; |
- |
-void GpuMessageHandler::FileSelected( |
- const FilePath& path, int index, void* params) { |
- if (select_trace_file_dialog_type_ == SelectFileDialog::SELECT_OPEN_FILE) |
- BrowserThread::PostTask( |
- BrowserThread::FILE, FROM_HERE, |
- new ReadTraceFileTask(new TaskProxy(AsWeakPtr()), path)); |
- else |
- BrowserThread::PostTask( |
- BrowserThread::FILE, FROM_HERE, |
- new WriteTraceFileTask(new TaskProxy(AsWeakPtr()), path, |
- trace_data_to_save_.release())); |
- select_trace_file_dialog_.release(); |
-} |
- |
-void GpuMessageHandler::FileSelectionCanceled(void* params) { |
- select_trace_file_dialog_.release(); |
- if (select_trace_file_dialog_type_ == SelectFileDialog::SELECT_OPEN_FILE) |
- web_ui_->CallJavascriptFunction("tracingController.onLoadTraceFileCanceled"); |
- else |
- web_ui_->CallJavascriptFunction("tracingController.onSaveTraceFileCanceled"); |
-} |
- |
-void GpuMessageHandler::OnLoadTraceFile(const ListValue* list) { |
- // Only allow a single dialog at a time. |
- if (select_trace_file_dialog_.get()) |
- return; |
- select_trace_file_dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; |
- select_trace_file_dialog_ = SelectFileDialog::Create(this); |
- select_trace_file_dialog_->SelectFile( |
- SelectFileDialog::SELECT_OPEN_FILE, |
- string16(), |
- FilePath(), |
- NULL, 0, FILE_PATH_LITERAL(""), web_ui_->tab_contents(), |
- web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); |
-} |
- |
-void GpuMessageHandler::LoadTraceFileComplete(std::string* file_contents) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- std::wstring javascript; |
- javascript += L"tracingController.onLoadTraceFileComplete("; |
- javascript += UTF8ToWide(*file_contents); |
- javascript += L");"; |
- |
- web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(), |
- WideToUTF16Hack(javascript)); |
-} |
- |
-void GpuMessageHandler::OnSaveTraceFile(const ListValue* list) { |
- // Only allow a single dialog at a time. |
- if (select_trace_file_dialog_.get()) |
- return; |
- |
- DCHECK(list->GetSize() == 1); |
- |
- std::string* trace_data = new std::string(); |
- bool ok = list->GetString(0, trace_data); |
- DCHECK(ok); |
- trace_data_to_save_.reset(trace_data); |
- |
- select_trace_file_dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE; |
- select_trace_file_dialog_ = SelectFileDialog::Create(this); |
- select_trace_file_dialog_->SelectFile( |
- SelectFileDialog::SELECT_SAVEAS_FILE, |
- string16(), |
- FilePath(), |
- NULL, 0, FILE_PATH_LITERAL(""), web_ui_->tab_contents(), |
- web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); |
-} |
- |
-void GpuMessageHandler::SaveTraceFileComplete() { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- std::wstring javascript; |
- web_ui_->CallJavascriptFunction("tracingController.onSaveTraceFileComplete"); |
-} |
- |
void GpuMessageHandler::OnBrowserBridgeInitialized(const ListValue* args) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
@@ -543,54 +312,6 @@ void GpuMessageHandler::OnGpuInfoUpdate() { |
delete gpu_info_val; |
} |
-void GpuMessageHandler::OnBeginTracing(const ListValue* args) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- trace_enabled_ = true; |
- // TODO(jbates) This may fail, but that's OK for current use cases. |
- // Ex: Multiple about:gpu traces can not trace simultaneously. |
- // TODO(nduca) send feedback to javascript about whether or not BeginTracing |
- // was successful. |
- TraceController::GetInstance()->BeginTracing(this); |
-} |
- |
-void GpuMessageHandler::OnEndTracingAsync(const ListValue* list) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- |
- // TODO(nduca): fix javascript code to make sure trace_enabled_ is always true |
- // here. triggered a false condition by just clicking stop |
- // trace a few times when it was going slow, and maybe switching |
- // between tabs. |
- if (trace_enabled_ && |
- !TraceController::GetInstance()->EndTracingAsync(this)) { |
- // Set to false now, since it turns out we never were the trace subscriber. |
- OnEndTracingComplete(); |
- } |
-} |
- |
-void GpuMessageHandler::OnEndTracingComplete() { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- trace_enabled_ = false; |
- web_ui_->CallJavascriptFunction("tracingController.onEndTracingComplete"); |
-} |
- |
-void GpuMessageHandler::OnTraceDataCollected(const std::string& json_events) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- std::wstring javascript; |
- javascript += L"tracingController.onTraceDataCollected("; |
- javascript += UTF8ToWide(json_events); |
- javascript += L");"; |
- |
- web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(), |
- WideToUTF16Hack(javascript)); |
-} |
- |
-void GpuMessageHandler::OnTraceBufferPercentFullReply(float percent_full) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- web_ui_->CallJavascriptFunction( |
- "tracingController.onRequestBufferPercentFullComplete", |
- *scoped_ptr<Value>(Value::CreateDoubleValue(percent_full))); |
-} |
- |
} // namespace |