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

Side by Side Diff: chrome/browser/ui/toolbar/wrench_menu_model.cc

Issue 12039058: content: convert zoom notifications to observer usage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 10 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
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/toolbar/wrench_menu_model.h" 5 #include "chrome/browser/ui/toolbar/wrench_menu_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 //////////////////////////////////////////////////////////////////////////////// 218 ////////////////////////////////////////////////////////////////////////////////
219 // WrenchMenuModel 219 // WrenchMenuModel
220 220
221 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, 221 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider,
222 Browser* browser, 222 Browser* browser,
223 bool is_new_menu, 223 bool is_new_menu,
224 bool supports_new_separators) 224 bool supports_new_separators)
225 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), 225 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
226 provider_(provider), 226 provider_(provider),
227 browser_(browser), 227 browser_(browser),
228 tab_strip_model_(browser_->tab_strip_model()) { 228 tab_strip_model_(browser_->tab_strip_model()),
229 zoom_callback_(base::Bind(&WrenchMenuModel::OnZoomLevelChanged,
230 base::Unretained(this))) {
229 Build(is_new_menu, supports_new_separators); 231 Build(is_new_menu, supports_new_separators);
230 UpdateZoomControls(); 232 UpdateZoomControls();
231 233
234 HostZoomMap::GetForBrowserContext(
235 browser->profile())->AddZoomLevelChangedCallback(zoom_callback_);
236
232 tab_strip_model_->AddObserver(this); 237 tab_strip_model_->AddObserver(this);
233 238
234 registrar_.Add(
235 this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
236 content::Source<HostZoomMap>(
237 HostZoomMap::GetForBrowserContext(browser_->profile())));
238 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 239 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
239 content::NotificationService::AllSources()); 240 content::NotificationService::AllSources());
240 } 241 }
241 242
242 WrenchMenuModel::~WrenchMenuModel() { 243 WrenchMenuModel::~WrenchMenuModel() {
243 if (tab_strip_model_) 244 if (tab_strip_model_)
244 tab_strip_model_->RemoveObserver(this); 245 tab_strip_model_->RemoveObserver(this);
246
247 HostZoomMap::GetForBrowserContext(
248 browser()->profile())->RemoveZoomLevelChangedCallback(zoom_callback_);
245 } 249 }
246 250
247 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { 251 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const {
248 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; 252 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS;
249 } 253 }
250 254
251 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { 255 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const {
252 return command_id == IDC_ZOOM_PERCENT_DISPLAY || 256 return command_id == IDC_ZOOM_PERCENT_DISPLAY ||
253 #if defined(OS_MACOSX) 257 #if defined(OS_MACOSX)
254 command_id == IDC_FULLSCREEN || 258 command_id == IDC_FULLSCREEN ||
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 void WrenchMenuModel::TabStripModelDeleted() { 452 void WrenchMenuModel::TabStripModelDeleted() {
449 // During views shutdown, the tabstrip model/browser is deleted first, while 453 // During views shutdown, the tabstrip model/browser is deleted first, while
450 // it is the opposite in gtk land. 454 // it is the opposite in gtk land.
451 tab_strip_model_->RemoveObserver(this); 455 tab_strip_model_->RemoveObserver(this);
452 tab_strip_model_ = NULL; 456 tab_strip_model_ = NULL;
453 } 457 }
454 458
455 void WrenchMenuModel::Observe(int type, 459 void WrenchMenuModel::Observe(int type,
456 const content::NotificationSource& source, 460 const content::NotificationSource& source,
457 const content::NotificationDetails& details) { 461 const content::NotificationDetails& details) {
458 switch (type) { 462 DCHECK(type == content::NOTIFICATION_NAV_ENTRY_COMMITTED);
459 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: 463 UpdateZoomControls();
460 case content::NOTIFICATION_NAV_ENTRY_COMMITTED:
461 UpdateZoomControls();
462 break;
463 default:
464 NOTREACHED();
465 }
466 } 464 }
467 465
468 // For testing. 466 // For testing.
469 WrenchMenuModel::WrenchMenuModel() 467 WrenchMenuModel::WrenchMenuModel()
470 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), 468 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
471 provider_(NULL), 469 provider_(NULL),
472 browser_(NULL), 470 browser_(NULL),
473 tab_strip_model_(NULL) { 471 tab_strip_model_(NULL) {
474 } 472 }
475 473
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 // registration framework. 745 // registration framework.
748 if (profile->IsSyncAccessible()) { 746 if (profile->IsSyncAccessible()) {
749 ProfileSyncService* service = 747 ProfileSyncService* service =
750 ProfileSyncServiceFactory::GetForProfile(profile); 748 ProfileSyncServiceFactory::GetForProfile(profile);
751 SyncGlobalError* error = service->sync_global_error(); 749 SyncGlobalError* error = service->sync_global_error();
752 if (error && error->HasBadge()) 750 if (error && error->HasBadge())
753 return error; 751 return error;
754 } 752 }
755 return NULL; 753 return NULL;
756 } 754 }
755
756 void WrenchMenuModel::OnZoomLevelChanged(const std::string& host) {
757 UpdateZoomControls();
758 }
759
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698