diff options
author | csilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-01 23:13:41 +0000 |
---|---|---|
committer | csilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-01 23:13:41 +0000 |
commit | e93318deed7d9fcea3218a163d8eb9acdd678815 (patch) | |
tree | eeb97a244715f7ccb5d1dce8f292cd7c1bdabf8f /chrome | |
parent | 72a9a0fdf6b1d63f449ac45b6ae716920952cbdc (diff) | |
download | chromium_src-e93318deed7d9fcea3218a163d8eb9acdd678815.zip chromium_src-e93318deed7d9fcea3218a163d8eb9acdd678815.tar.gz chromium_src-e93318deed7d9fcea3218a163d8eb9acdd678815.tar.bz2 |
Change GpuDataManager to use Observer notifications rather than callbacks. This eliminates
use of legacy callbacks and generally simplifies the implementation. Also migrate one instance
of NewRunnableMethod to base::Bind().
BUG=98478
Review URL: http://codereview.chromium.org/8390018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108189 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/ui/webui/flash_ui.cc | 21 | ||||
-rw-r--r-- | chrome/browser/ui/webui/gpu_internals_ui.cc | 26 | ||||
-rw-r--r-- | chrome/browser/ui/webui/tracing_ui.cc | 27 |
3 files changed, 27 insertions, 47 deletions
diff --git a/chrome/browser/ui/webui/flash_ui.cc b/chrome/browser/ui/webui/flash_ui.cc index e23de2a7..4f9b238 100644 --- a/chrome/browser/ui/webui/flash_ui.cc +++ b/chrome/browser/ui/webui/flash_ui.cc @@ -10,7 +10,6 @@ #include "base/bind.h" #include "base/bind_helpers.h" -#include "base/callback_old.h" #include "base/i18n/time_formatting.h" #include "base/memory/weak_ptr.h" #include "base/string_number_conversions.h" @@ -66,10 +65,11 @@ const int kTimeout = 8 * 1000; // 8 seconds. // The handler for JavaScript messages for the about:flags page. class FlashDOMHandler : public WebUIMessageHandler, - public CrashUploadList::Delegate { + public CrashUploadList::Delegate, + public GpuDataManager::Observer { public: FlashDOMHandler(); - virtual ~FlashDOMHandler() {} + virtual ~FlashDOMHandler(); // WebUIMessageHandler implementation. virtual void RegisterMessages() OVERRIDE; @@ -77,12 +77,12 @@ class FlashDOMHandler : public WebUIMessageHandler, // CrashUploadList::Delegate implementation. virtual void OnCrashListAvailable() OVERRIDE; + // GpuDataManager::Observer implementation. + virtual void OnGpuInfoUpdate() OVERRIDE; + // Callback for the "requestFlashInfo" message. void HandleRequestFlashInfo(const ListValue* args); - // Callback for the GPU information update. - void OnGpuInfoUpdate(); - // Callback for the Flash plugin information. void OnGotPlugins(const std::vector<webkit::WebPluginInfo>& plugins); @@ -103,7 +103,6 @@ class FlashDOMHandler : public WebUIMessageHandler, // GPU variables. GpuDataManager* gpu_data_manager_; - Callback0::Type* gpu_info_update_callback_; // Crash list. scoped_refptr<CrashUploadList> upload_list_; @@ -135,9 +134,7 @@ FlashDOMHandler::FlashDOMHandler() // Watch for changes in GPUInfo. gpu_data_manager_ = GpuDataManager::GetInstance(); - gpu_info_update_callback_ = - NewCallback(this, &FlashDOMHandler::OnGpuInfoUpdate); - gpu_data_manager_->AddGpuInfoUpdateCallback(gpu_info_update_callback_); + gpu_data_manager_->AddObserver(this); // Tell GpuDataManager it should have full GpuInfo. If the // GPU process has not run yet, this will trigger its launch. @@ -157,6 +154,10 @@ FlashDOMHandler::FlashDOMHandler() this, &FlashDOMHandler::OnTimeout); } +FlashDOMHandler::~FlashDOMHandler() { + gpu_data_manager_->RemoveObserver(this); +} + void FlashDOMHandler::RegisterMessages() { web_ui_->RegisterMessageCallback("requestFlashInfo", base::Bind(&FlashDOMHandler::HandleRequestFlashInfo, diff --git a/chrome/browser/ui/webui/gpu_internals_ui.cc b/chrome/browser/ui/webui/gpu_internals_ui.cc index c68852f..bdadcb7 100644 --- a/chrome/browser/ui/webui/gpu_internals_ui.cc +++ b/chrome/browser/ui/webui/gpu_internals_ui.cc @@ -8,7 +8,6 @@ #include "base/bind.h" #include "base/bind_helpers.h" -#include "base/callback_old.h" #include "base/command_line.h" #include "base/string_number_conversions.h" #include "base/stringprintf.h" @@ -44,7 +43,8 @@ ChromeWebUIDataSource* CreateGpuHTMLSource() { // this class's methods are expected to run on the UI thread. class GpuMessageHandler : public WebUIMessageHandler, - public base::SupportsWeakPtr<GpuMessageHandler> { + public base::SupportsWeakPtr<GpuMessageHandler>, + public GpuDataManager::Observer { public: GpuMessageHandler(); virtual ~GpuMessageHandler(); @@ -53,6 +53,9 @@ class GpuMessageHandler virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; virtual void RegisterMessages() OVERRIDE; + // GpuDataManager::Observer implementation. + virtual void OnGpuInfoUpdate() OVERRIDE; + // Messages void OnBrowserBridgeInitialized(const ListValue* list); void OnCallAsync(const ListValue* list); @@ -61,9 +64,6 @@ class GpuMessageHandler Value* OnRequestClientInfo(const ListValue* list); Value* OnRequestLogMessages(const ListValue* list); - // Callbacks. - void OnGpuInfoUpdate(); - // Executes the javascript function |function_name| in the renderer, passing // it the argument |value|. void CallJavascriptFunction(const std::wstring& function_name, @@ -73,8 +73,6 @@ class GpuMessageHandler // Cache the Singleton for efficiency. GpuDataManager* gpu_data_manager_; - Callback0::Type* gpu_info_update_callback_; - DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); }; @@ -84,17 +82,13 @@ class GpuMessageHandler // //////////////////////////////////////////////////////////////////////////////// -GpuMessageHandler::GpuMessageHandler() - : gpu_info_update_callback_(NULL) { +GpuMessageHandler::GpuMessageHandler() { gpu_data_manager_ = GpuDataManager::GetInstance(); DCHECK(gpu_data_manager_); } GpuMessageHandler::~GpuMessageHandler() { - if (gpu_info_update_callback_) { - gpu_data_manager_->RemoveGpuInfoUpdateCallback(gpu_info_update_callback_); - delete gpu_info_update_callback_; - } + gpu_data_manager_->RemoveObserver(this); } WebUIMessageHandler* GpuMessageHandler::Attach(WebUI* web_ui) { @@ -165,12 +159,8 @@ void GpuMessageHandler::OnCallAsync(const ListValue* args) { void GpuMessageHandler::OnBrowserBridgeInitialized(const ListValue* args) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(!gpu_info_update_callback_); - // Watch for changes in GPUInfo - gpu_info_update_callback_ = - NewCallback(this, &GpuMessageHandler::OnGpuInfoUpdate); - gpu_data_manager_->AddGpuInfoUpdateCallback(gpu_info_update_callback_); + gpu_data_manager_->AddObserver(this); // Tell GpuDataManager it should have full GpuInfo. If the // Gpu process has not run yet, this will trigger its launch. diff --git a/chrome/browser/ui/webui/tracing_ui.cc b/chrome/browser/ui/webui/tracing_ui.cc index efd1562..f314ed9 100644 --- a/chrome/browser/ui/webui/tracing_ui.cc +++ b/chrome/browser/ui/webui/tracing_ui.cc @@ -8,7 +8,6 @@ #include "base/bind.h" #include "base/bind_helpers.h" -#include "base/callback_old.h" #include "base/command_line.h" #include "base/file_util.h" #include "base/memory/scoped_ptr.h" @@ -48,7 +47,8 @@ class TracingMessageHandler : public WebUIMessageHandler, public SelectFileDialog::Listener, public base::SupportsWeakPtr<TracingMessageHandler>, - public TraceSubscriber { + public TraceSubscriber, + public GpuDataManager::Observer { public: TracingMessageHandler(); virtual ~TracingMessageHandler(); @@ -66,6 +66,9 @@ class TracingMessageHandler virtual void OnTraceDataCollected(const std::string& trace_fragment); virtual void OnTraceBufferPercentFullReply(float percent_full); + // GpuDataManager::Observer implementation. + virtual void OnGpuInfoUpdate() OVERRIDE; + // Messages. void OnTracingControllerInitialized(const ListValue* list); void OnBeginTracing(const ListValue* list); @@ -75,9 +78,6 @@ class TracingMessageHandler void OnSaveTraceFile(const ListValue* list); // Callbacks. - void OnGpuInfoUpdate(); - - // Callbacks. void LoadTraceFileComplete(std::string* file_contents); void SaveTraceFileComplete(); @@ -98,9 +98,6 @@ class TracingMessageHandler // Cache the Singleton for efficiency. GpuDataManager* gpu_data_manager_; - // Callback called when the GPU info is updated. - Callback0::Type* gpu_info_update_callback_; - DISALLOW_COPY_AND_ASSIGN(TracingMessageHandler); }; @@ -138,17 +135,13 @@ class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> { TracingMessageHandler::TracingMessageHandler() : select_trace_file_dialog_type_(SelectFileDialog::SELECT_NONE), - trace_enabled_(false), - gpu_info_update_callback_(NULL) { + trace_enabled_(false) { gpu_data_manager_ = GpuDataManager::GetInstance(); DCHECK(gpu_data_manager_); } TracingMessageHandler::~TracingMessageHandler() { - if (gpu_info_update_callback_) { - gpu_data_manager_->RemoveGpuInfoUpdateCallback(gpu_info_update_callback_); - delete gpu_info_update_callback_; - } + gpu_data_manager_->RemoveObserver(this); if (select_trace_file_dialog_) select_trace_file_dialog_->ListenerDestroyed(); @@ -190,12 +183,8 @@ void TracingMessageHandler::OnTracingControllerInitialized( const ListValue* args) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(!gpu_info_update_callback_); - // Watch for changes in GPUInfo - gpu_info_update_callback_ = - NewCallback(this, &TracingMessageHandler::OnGpuInfoUpdate); - gpu_data_manager_->AddGpuInfoUpdateCallback(gpu_info_update_callback_); + gpu_data_manager_->AddObserver(this); // Tell GpuDataManager it should have full GpuInfo. If the // Gpu process has not run yet, this will trigger its launch. |