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

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

Issue 8390018: Change GpuDataManager to use Observer notifications rather than callbacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Review fixes Created 9 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/ui/webui/gpu_internals_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/flash_ui.h" 5 #include "chrome/browser/ui/webui/flash_ui.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/callback_old.h"
14 #include "base/i18n/time_formatting.h" 13 #include "base/i18n/time_formatting.h"
15 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
16 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
17 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
18 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
19 #include "base/timer.h" 18 #include "base/timer.h"
20 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
21 #include "base/values.h" 20 #include "base/values.h"
22 #include "chrome/browser/crash_upload_list.h" 21 #include "chrome/browser/crash_upload_list.h"
23 #include "chrome/browser/plugin_prefs.h" 22 #include "chrome/browser/plugin_prefs.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 const int kTimeout = 8 * 1000; // 8 seconds. 58 const int kTimeout = 8 * 1000; // 8 seconds.
60 59
61 //////////////////////////////////////////////////////////////////////////////// 60 ////////////////////////////////////////////////////////////////////////////////
62 // 61 //
63 // FlashDOMHandler 62 // FlashDOMHandler
64 // 63 //
65 //////////////////////////////////////////////////////////////////////////////// 64 ////////////////////////////////////////////////////////////////////////////////
66 65
67 // The handler for JavaScript messages for the about:flags page. 66 // The handler for JavaScript messages for the about:flags page.
68 class FlashDOMHandler : public WebUIMessageHandler, 67 class FlashDOMHandler : public WebUIMessageHandler,
69 public CrashUploadList::Delegate { 68 public CrashUploadList::Delegate,
69 public GpuDataManager::Observer {
70 public: 70 public:
71 FlashDOMHandler(); 71 FlashDOMHandler();
72 virtual ~FlashDOMHandler() {} 72 virtual ~FlashDOMHandler();
73 73
74 // WebUIMessageHandler implementation. 74 // WebUIMessageHandler implementation.
75 virtual void RegisterMessages() OVERRIDE; 75 virtual void RegisterMessages() OVERRIDE;
76 76
77 // CrashUploadList::Delegate implementation. 77 // CrashUploadList::Delegate implementation.
78 virtual void OnCrashListAvailable() OVERRIDE; 78 virtual void OnCrashListAvailable() OVERRIDE;
79 79
80 // GpuDataManager::Observer implementation.
81 virtual void OnGpuInfoUpdate() OVERRIDE;
82
80 // Callback for the "requestFlashInfo" message. 83 // Callback for the "requestFlashInfo" message.
81 void HandleRequestFlashInfo(const ListValue* args); 84 void HandleRequestFlashInfo(const ListValue* args);
82 85
83 // Callback for the GPU information update.
84 void OnGpuInfoUpdate();
85
86 // Callback for the Flash plugin information. 86 // Callback for the Flash plugin information.
87 void OnGotPlugins(const std::vector<webkit::WebPluginInfo>& plugins); 87 void OnGotPlugins(const std::vector<webkit::WebPluginInfo>& plugins);
88 88
89 private: 89 private:
90 // Called when we think we might have enough information to return data back 90 // Called when we think we might have enough information to return data back
91 // to the page. 91 // to the page.
92 void MaybeRespondToPage(); 92 void MaybeRespondToPage();
93 93
94 // In certain cases we might not get called back from the GPU process so we 94 // In certain cases we might not get called back from the GPU process so we
95 // set an upper limit on the time we wait. This function gets called when the 95 // set an upper limit on the time we wait. This function gets called when the
96 // time has passed. This actually doesn't prevent the rest of the information 96 // time has passed. This actually doesn't prevent the rest of the information
97 // to appear later, the page will just reflow when more information becomes 97 // to appear later, the page will just reflow when more information becomes
98 // available. 98 // available.
99 void OnTimeout(); 99 void OnTimeout();
100 100
101 // A timer to keep track of when the data fetching times out. 101 // A timer to keep track of when the data fetching times out.
102 base::OneShotTimer<FlashDOMHandler> timeout_; 102 base::OneShotTimer<FlashDOMHandler> timeout_;
103 103
104 // GPU variables. 104 // GPU variables.
105 GpuDataManager* gpu_data_manager_; 105 GpuDataManager* gpu_data_manager_;
106 Callback0::Type* gpu_info_update_callback_;
107 106
108 // Crash list. 107 // Crash list.
109 scoped_refptr<CrashUploadList> upload_list_; 108 scoped_refptr<CrashUploadList> upload_list_;
110 109
111 // Factory for the creating refs in callbacks. 110 // Factory for the creating refs in callbacks.
112 base::WeakPtrFactory<FlashDOMHandler> weak_ptr_factory_; 111 base::WeakPtrFactory<FlashDOMHandler> weak_ptr_factory_;
113 112
114 // Whether the list of all crashes is available. 113 // Whether the list of all crashes is available.
115 bool crash_list_available_; 114 bool crash_list_available_;
116 // Whether the page has requested data. 115 // Whether the page has requested data.
(...skipping 11 matching lines...) Expand all
128 crash_list_available_(false), 127 crash_list_available_(false),
129 page_has_requested_data_(false), 128 page_has_requested_data_(false),
130 has_gpu_info_(false), 129 has_gpu_info_(false),
131 has_plugin_info_(false) { 130 has_plugin_info_(false) {
132 // Request Crash data asynchronously. 131 // Request Crash data asynchronously.
133 upload_list_ = CrashUploadList::Create(this); 132 upload_list_ = CrashUploadList::Create(this);
134 upload_list_->LoadCrashListAsynchronously(); 133 upload_list_->LoadCrashListAsynchronously();
135 134
136 // Watch for changes in GPUInfo. 135 // Watch for changes in GPUInfo.
137 gpu_data_manager_ = GpuDataManager::GetInstance(); 136 gpu_data_manager_ = GpuDataManager::GetInstance();
138 gpu_info_update_callback_ = 137 gpu_data_manager_->AddObserver(this);
139 NewCallback(this, &FlashDOMHandler::OnGpuInfoUpdate);
140 gpu_data_manager_->AddGpuInfoUpdateCallback(gpu_info_update_callback_);
141 138
142 // Tell GpuDataManager it should have full GpuInfo. If the 139 // Tell GpuDataManager it should have full GpuInfo. If the
143 // GPU process has not run yet, this will trigger its launch. 140 // GPU process has not run yet, this will trigger its launch.
144 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); 141 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded();
145 142
146 // GPU access might not be allowed at all, which will cause us not to get a 143 // GPU access might not be allowed at all, which will cause us not to get a
147 // call back. 144 // call back.
148 if (!gpu_data_manager_->GpuAccessAllowed()) 145 if (!gpu_data_manager_->GpuAccessAllowed())
149 OnGpuInfoUpdate(); 146 OnGpuInfoUpdate();
150 147
151 PluginService::GetInstance()->GetPlugins(base::Bind( 148 PluginService::GetInstance()->GetPlugins(base::Bind(
152 &FlashDOMHandler::OnGotPlugins, weak_ptr_factory_.GetWeakPtr())); 149 &FlashDOMHandler::OnGotPlugins, weak_ptr_factory_.GetWeakPtr()));
153 150
154 // And lastly, we fire off a timer to make sure we never get stuck at the 151 // And lastly, we fire off a timer to make sure we never get stuck at the
155 // "Loading..." message. 152 // "Loading..." message.
156 timeout_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kTimeout), 153 timeout_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kTimeout),
157 this, &FlashDOMHandler::OnTimeout); 154 this, &FlashDOMHandler::OnTimeout);
158 } 155 }
159 156
157 FlashDOMHandler::~FlashDOMHandler() {
158 gpu_data_manager_->RemoveObserver(this);
159 }
160
160 void FlashDOMHandler::RegisterMessages() { 161 void FlashDOMHandler::RegisterMessages() {
161 web_ui_->RegisterMessageCallback("requestFlashInfo", 162 web_ui_->RegisterMessageCallback("requestFlashInfo",
162 base::Bind(&FlashDOMHandler::HandleRequestFlashInfo, 163 base::Bind(&FlashDOMHandler::HandleRequestFlashInfo,
163 base::Unretained(this))); 164 base::Unretained(this)));
164 } 165 }
165 166
166 void FlashDOMHandler::OnCrashListAvailable() { 167 void FlashDOMHandler::OnCrashListAvailable() {
167 crash_list_available_ = true; 168 crash_list_available_ = true;
168 MaybeRespondToPage(); 169 MaybeRespondToPage();
169 } 170 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // Set up the about:flash source. 369 // Set up the about:flash source.
369 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); 370 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
370 profile->GetChromeURLDataManager()->AddDataSource(CreateFlashUIHTMLSource()); 371 profile->GetChromeURLDataManager()->AddDataSource(CreateFlashUIHTMLSource());
371 } 372 }
372 373
373 // static 374 // static
374 RefCountedMemory* FlashUI::GetFaviconResourceBytes() { 375 RefCountedMemory* FlashUI::GetFaviconResourceBytes() {
375 // Use the default icon for now. 376 // Use the default icon for now.
376 return NULL; 377 return NULL;
377 } 378 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/gpu_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698