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

Side by Side Diff: chrome/browser/ui/hung_plugin_tab_helper.cc

Issue 338353003: Revert of Change HungPluginTabHelper to listen for infobar changes through Observer style. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | « chrome/browser/ui/hung_plugin_tab_helper.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/hung_plugin_tab_helper.h" 5 #include "chrome/browser/ui/hung_plugin_tab_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/process/process.h" 10 #include "base/process/process.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/infobars/infobar_service.h" 14 #include "chrome/browser/infobars/infobar_service.h"
14 #include "chrome/common/chrome_version_info.h" 15 #include "chrome/common/chrome_version_info.h"
15 #include "components/infobars/core/confirm_infobar_delegate.h" 16 #include "components/infobars/core/confirm_infobar_delegate.h"
16 #include "components/infobars/core/infobar.h" 17 #include "components/infobars/core/infobar.h"
17 #include "content/public/browser/browser_child_process_host_iterator.h" 18 #include "content/public/browser/browser_child_process_host_iterator.h"
18 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/child_process_data.h" 20 #include "content/public/browser/child_process_data.h"
21 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/plugin_service.h" 23 #include "content/public/browser/plugin_service.h"
21 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
22 #include "content/public/common/process_type.h" 25 #include "content/public/common/process_type.h"
23 #include "content/public/common/result_codes.h" 26 #include "content/public/common/result_codes.h"
24 #include "grit/chromium_strings.h" 27 #include "grit/chromium_strings.h"
25 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
26 #include "grit/locale_settings.h" 29 #include "grit/locale_settings.h"
27 #include "grit/theme_resources.h" 30 #include "grit/theme_resources.h"
28 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
29 32
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 254
252 HungPluginTabHelper::PluginState::~PluginState() { 255 HungPluginTabHelper::PluginState::~PluginState() {
253 } 256 }
254 257
255 258
256 // HungPluginTabHelper -------------------------------------------------------- 259 // HungPluginTabHelper --------------------------------------------------------
257 260
258 DEFINE_WEB_CONTENTS_USER_DATA_KEY(HungPluginTabHelper); 261 DEFINE_WEB_CONTENTS_USER_DATA_KEY(HungPluginTabHelper);
259 262
260 HungPluginTabHelper::HungPluginTabHelper(content::WebContents* contents) 263 HungPluginTabHelper::HungPluginTabHelper(content::WebContents* contents)
261 : content::WebContentsObserver(contents), 264 : content::WebContentsObserver(contents) {
262 number_of_infobars_(0) { 265 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
266 content::NotificationService::AllSources());
263 } 267 }
264 268
265 HungPluginTabHelper::~HungPluginTabHelper() { 269 HungPluginTabHelper::~HungPluginTabHelper() {
266 // If we're getting shut down before the InfoBarService, we need to unregister
267 // as an observer.
268 if (number_of_infobars_ != 0)
269 InfoBarService::FromWebContents(web_contents())->RemoveObserver(this);
270 } 270 }
271 271
272 void HungPluginTabHelper::PluginCrashed(const base::FilePath& plugin_path, 272 void HungPluginTabHelper::PluginCrashed(const base::FilePath& plugin_path,
273 base::ProcessId plugin_pid) { 273 base::ProcessId plugin_pid) {
274 // TODO(brettw) ideally this would take the child process ID. When we do this 274 // TODO(brettw) ideally this would take the child process ID. When we do this
275 // for NaCl plugins, we'll want to know exactly which process it was since 275 // for NaCl plugins, we'll want to know exactly which process it was since
276 // the path won't be useful. 276 // the path won't be useful.
277 InfoBarService* infobar_service = 277 InfoBarService* infobar_service =
278 InfoBarService::FromWebContents(web_contents()); 278 InfoBarService::FromWebContents(web_contents());
279 if (!infobar_service) 279 if (!infobar_service)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 314
315 base::string16 plugin_name = 315 base::string16 plugin_name =
316 content::PluginService::GetInstance()->GetPluginDisplayNameByPath( 316 content::PluginService::GetInstance()->GetPluginDisplayNameByPath(
317 plugin_path); 317 plugin_path);
318 318
319 linked_ptr<PluginState> state(new PluginState(plugin_path, plugin_name)); 319 linked_ptr<PluginState> state(new PluginState(plugin_path, plugin_name));
320 hung_plugins_[plugin_child_id] = state; 320 hung_plugins_[plugin_child_id] = state;
321 ShowBar(plugin_child_id, state.get()); 321 ShowBar(plugin_child_id, state.get());
322 } 322 }
323 323
324 void HungPluginTabHelper::OnInfoBarRemoved(infobars::InfoBar* infobar, 324 void HungPluginTabHelper::Observe(
325 bool animate) { 325 int type,
326 const content::NotificationSource& source,
327 const content::NotificationDetails& details) {
328 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
329 infobars::InfoBar* infobar =
330 content::Details<infobars::InfoBar::RemovedDetails>(details)->first;
326 for (PluginStateMap::iterator i = hung_plugins_.begin(); 331 for (PluginStateMap::iterator i = hung_plugins_.begin();
327 i != hung_plugins_.end(); ++i) { 332 i != hung_plugins_.end(); ++i) {
328 PluginState* state = i->second.get(); 333 PluginState* state = i->second.get();
329 if (state->infobar == infobar) { 334 if (state->infobar == infobar) {
330 --number_of_infobars_;
331 if (number_of_infobars_ == 0)
332 InfoBarService::FromWebContents(web_contents())->RemoveObserver(this);
333
334 state->infobar = NULL; 335 state->infobar = NULL;
335 336
336 // Schedule the timer to re-show the infobar if the plugin continues to be 337 // Schedule the timer to re-show the infobar if the plugin continues to be
337 // hung. 338 // hung.
338 state->timer.Start(FROM_HERE, state->next_reshow_delay, 339 state->timer.Start(FROM_HERE, state->next_reshow_delay,
339 base::Bind(&HungPluginTabHelper::OnReshowTimer, 340 base::Bind(&HungPluginTabHelper::OnReshowTimer,
340 base::Unretained(this), 341 base::Unretained(this),
341 i->first)); 342 i->first));
342 343
343 // Next time we do this, delay it twice as long to avoid being annoying. 344 // Next time we do this, delay it twice as long to avoid being annoying.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 405
405 void HungPluginTabHelper::ShowBar(int child_id, PluginState* state) { 406 void HungPluginTabHelper::ShowBar(int child_id, PluginState* state) {
406 InfoBarService* infobar_service = 407 InfoBarService* infobar_service =
407 InfoBarService::FromWebContents(web_contents()); 408 InfoBarService::FromWebContents(web_contents());
408 if (!infobar_service) 409 if (!infobar_service)
409 return; 410 return;
410 411
411 DCHECK(!state->infobar); 412 DCHECK(!state->infobar);
412 state->infobar = HungPluginInfoBarDelegate::Create(infobar_service, this, 413 state->infobar = HungPluginInfoBarDelegate::Create(infobar_service, this,
413 child_id, state->name); 414 child_id, state->name);
414
415 if (state->infobar) {
416 ++number_of_infobars_;
417 if (number_of_infobars_ == 1)
418 infobar_service->AddObserver(this);
419 }
420 } 415 }
421 416
422 void HungPluginTabHelper::CloseBar(PluginState* state) { 417 void HungPluginTabHelper::CloseBar(PluginState* state) {
423 InfoBarService* infobar_service = 418 InfoBarService* infobar_service =
424 InfoBarService::FromWebContents(web_contents()); 419 InfoBarService::FromWebContents(web_contents());
425 if (infobar_service && state->infobar) { 420 if (infobar_service && state->infobar) {
426 infobar_service->RemoveInfoBar(state->infobar); 421 infobar_service->RemoveInfoBar(state->infobar);
427 state->infobar = NULL; 422 state->infobar = NULL;
428 } 423 }
429 } 424 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/hung_plugin_tab_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698