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

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_view.cc

Issue 2925973002: Migrate upgrade notifications to observer (Closed)
Patch Set: Add DISALLOW_COPY_AND_ASSIGN Created 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/views/toolbar/toolbar_view.h" 5 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/i18n/number_formatting.h" 10 #include "base/i18n/number_formatting.h"
11 #include "base/metrics/user_metrics.h" 11 #include "base/metrics/user_metrics.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/app/vector_icons/vector_icons.h" 16 #include "chrome/app/vector_icons/vector_icons.h"
17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/command_updater.h" 17 #include "chrome/browser/command_updater.h"
19 #include "chrome/browser/extensions/extension_util.h" 18 #include "chrome/browser/extensions/extension_util.h"
20 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/themes/theme_properties.h" 20 #include "chrome/browser/themes/theme_properties.h"
22 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h" 21 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h"
23 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_command_controller.h" 23 #include "chrome/browser/ui/browser_command_controller.h"
25 #include "chrome/browser/ui/browser_commands.h" 24 #include "chrome/browser/ui/browser_commands.h"
26 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" 25 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
27 #include "chrome/browser/ui/browser_tabstrip.h" 26 #include "chrome/browser/ui/browser_tabstrip.h"
(...skipping 10 matching lines...) Expand all
38 #include "chrome/browser/ui/views/frame/browser_view.h" 37 #include "chrome/browser/ui/views/frame/browser_view.h"
39 #include "chrome/browser/ui/views/location_bar/star_view.h" 38 #include "chrome/browser/ui/views/location_bar/star_view.h"
40 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" 39 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h"
41 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" 40 #include "chrome/browser/ui/views/toolbar/app_menu_button.h"
42 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" 41 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
43 #include "chrome/browser/ui/views/toolbar/home_button.h" 42 #include "chrome/browser/ui/views/toolbar/home_button.h"
44 #include "chrome/browser/ui/views/toolbar/reload_button.h" 43 #include "chrome/browser/ui/views/toolbar/reload_button.h"
45 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" 44 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
46 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" 45 #include "chrome/browser/ui/views/translate/translate_bubble_view.h"
47 #include "chrome/browser/ui/views/translate/translate_icon_view.h" 46 #include "chrome/browser/ui/views/translate/translate_icon_view.h"
47 #include "chrome/browser/upgrade_detector.h"
48 #include "chrome/common/chrome_switches.h" 48 #include "chrome/common/chrome_switches.h"
49 #include "chrome/common/pref_names.h" 49 #include "chrome/common/pref_names.h"
50 #include "chrome/grit/chromium_strings.h" 50 #include "chrome/grit/chromium_strings.h"
51 #include "chrome/grit/generated_resources.h" 51 #include "chrome/grit/generated_resources.h"
52 #include "components/omnibox/browser/omnibox_view.h" 52 #include "components/omnibox/browser/omnibox_view.h"
53 #include "components/prefs/pref_service.h" 53 #include "components/prefs/pref_service.h"
54 #include "components/strings/grit/components_strings.h" 54 #include "components/strings/grit/components_strings.h"
55 #include "content/public/browser/browser_accessibility_state.h" 55 #include "content/public/browser/browser_accessibility_state.h"
56 #include "content/public/browser/notification_service.h"
57 #include "content/public/browser/render_view_host.h" 56 #include "content/public/browser/render_view_host.h"
58 #include "content/public/browser/web_contents.h" 57 #include "content/public/browser/web_contents.h"
59 #include "ui/accessibility/ax_node_data.h" 58 #include "ui/accessibility/ax_node_data.h"
60 #include "ui/base/l10n/l10n_util.h" 59 #include "ui/base/l10n/l10n_util.h"
61 #include "ui/base/material_design/material_design_controller.h" 60 #include "ui/base/material_design/material_design_controller.h"
62 #include "ui/base/theme_provider.h" 61 #include "ui/base/theme_provider.h"
63 #include "ui/base/window_open_disposition.h" 62 #include "ui/base/window_open_disposition.h"
64 #include "ui/compositor/layer.h" 63 #include "ui/compositor/layer.h"
65 #include "ui/gfx/canvas.h" 64 #include "ui/gfx/canvas.h"
66 #include "ui/gfx/image/canvas_image_source.h" 65 #include "ui/gfx/image/canvas_image_source.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 ? DISPLAYMODE_NORMAL 127 ? DISPLAYMODE_NORMAL
129 : DISPLAYMODE_LOCATION) { 128 : DISPLAYMODE_LOCATION) {
130 set_id(VIEW_ID_TOOLBAR); 129 set_id(VIEW_ID_TOOLBAR);
131 130
132 chrome::AddCommandObserver(browser_, IDC_BACK, this); 131 chrome::AddCommandObserver(browser_, IDC_BACK, this);
133 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); 132 chrome::AddCommandObserver(browser_, IDC_FORWARD, this);
134 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); 133 chrome::AddCommandObserver(browser_, IDC_RELOAD, this);
135 chrome::AddCommandObserver(browser_, IDC_HOME, this); 134 chrome::AddCommandObserver(browser_, IDC_HOME, this);
136 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); 135 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this);
137 136
138 if (OutdatedUpgradeBubbleView::IsAvailable()) { 137 UpgradeDetector::GetInstance()->AddObserver(this);
139 registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL,
140 content::NotificationService::AllSources());
141 registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU,
142 content::NotificationService::AllSources());
143 }
144 #if defined(OS_WIN)
145 registrar_.Add(this, chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED,
146 content::NotificationService::AllSources());
147 #endif
148 } 138 }
149 139
150 ToolbarView::~ToolbarView() { 140 ToolbarView::~ToolbarView() {
141 UpgradeDetector::GetInstance()->RemoveObserver(this);
142
151 // NOTE: Don't remove the command observers here. This object gets destroyed 143 // NOTE: Don't remove the command observers here. This object gets destroyed
152 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is 144 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is
153 // already gone. 145 // already gone.
154 } 146 }
155 147
156 void ToolbarView::Init() { 148 void ToolbarView::Init() {
157 location_bar_ = 149 location_bar_ =
158 new LocationBarView(browser_, browser_->profile(), 150 new LocationBarView(browser_, browser_->profile(),
159 browser_->command_controller()->command_updater(), 151 browser_->command_controller()->command_updater(),
160 this, !is_display_mode_normal()); 152 this, !is_display_mode_normal());
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 //////////////////////////////////////////////////////////////////////////////// 436 ////////////////////////////////////////////////////////////////////////////////
445 // ToolbarView, views::Button::ButtonListener implementation: 437 // ToolbarView, views::Button::ButtonListener implementation:
446 438
447 void ToolbarView::ButtonPressed(views::Button* sender, 439 void ToolbarView::ButtonPressed(views::Button* sender,
448 const ui::Event& event) { 440 const ui::Event& event) {
449 chrome::ExecuteCommandWithDisposition( 441 chrome::ExecuteCommandWithDisposition(
450 browser_, sender->tag(), ui::DispositionFromEventFlags(event.flags())); 442 browser_, sender->tag(), ui::DispositionFromEventFlags(event.flags()));
451 } 443 }
452 444
453 //////////////////////////////////////////////////////////////////////////////// 445 ////////////////////////////////////////////////////////////////////////////////
454 // ToolbarView, content::NotificationObserver implementation: 446 // ToolbarView, UpgradeObserver implementation:
447 void ToolbarView::OnOutdatedInstall() {
448 if (OutdatedUpgradeBubbleView::IsAvailable())
449 ShowOutdatedInstallNotification(true);
450 }
455 451
456 void ToolbarView::Observe(int type, 452 void ToolbarView::OnOutdatedInstallNoAutoUpdate() {
457 const content::NotificationSource& source, 453 if (OutdatedUpgradeBubbleView::IsAvailable())
458 const content::NotificationDetails& details) { 454 ShowOutdatedInstallNotification(false);
459 switch (type) { 455 }
460 case chrome::NOTIFICATION_OUTDATED_INSTALL: 456
461 ShowOutdatedInstallNotification(true); 457 void ToolbarView::OnCriticalUpgradeInstalled() {
462 break;
463 case chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU:
464 ShowOutdatedInstallNotification(false);
465 break;
466 #if defined(OS_WIN) 458 #if defined(OS_WIN)
467 case chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED: 459 ShowCriticalNotification();
468 ShowCriticalNotification();
469 break;
470 #endif 460 #endif
471 default:
472 NOTREACHED();
473 }
474 } 461 }
475 462
476 //////////////////////////////////////////////////////////////////////////////// 463 ////////////////////////////////////////////////////////////////////////////////
477 // ToolbarView, ui::AcceleratorProvider implementation: 464 // ToolbarView, ui::AcceleratorProvider implementation:
478 465
479 bool ToolbarView::GetAcceleratorForCommandId(int command_id, 466 bool ToolbarView::GetAcceleratorForCommandId(int command_id,
480 ui::Accelerator* accelerator) const { 467 ui::Accelerator* accelerator) const {
481 return GetWidget()->GetAccelerator(command_id, accelerator); 468 return GetWidget()->GetAccelerator(command_id, accelerator);
482 } 469 }
483 470
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 if (OutdatedUpgradeBubbleView::IsAvailable()) { 744 if (OutdatedUpgradeBubbleView::IsAvailable()) {
758 OutdatedUpgradeBubbleView::ShowBubble(app_menu_button_, browser_, 745 OutdatedUpgradeBubbleView::ShowBubble(app_menu_button_, browser_,
759 auto_update_enabled); 746 auto_update_enabled);
760 } 747 }
761 } 748 }
762 749
763 void ToolbarView::OnShowHomeButtonChanged() { 750 void ToolbarView::OnShowHomeButtonChanged() {
764 Layout(); 751 Layout();
765 SchedulePaint(); 752 SchedulePaint();
766 } 753 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_view.h ('k') | chrome/browser/ui/webui/help/help_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698