OLD | NEW |
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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 216 } |
217 | 217 |
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 content::HostZoomMap::Observer( |
| 227 HostZoomMap::GetForBrowserContext(browser->profile())), |
226 provider_(provider), | 228 provider_(provider), |
227 browser_(browser), | 229 browser_(browser), |
228 tab_strip_model_(browser_->tab_strip_model()) { | 230 tab_strip_model_(browser_->tab_strip_model()) { |
229 Build(is_new_menu, supports_new_separators); | 231 Build(is_new_menu, supports_new_separators); |
230 UpdateZoomControls(); | 232 UpdateZoomControls(); |
231 | 233 |
232 tab_strip_model_->AddObserver(this); | 234 tab_strip_model_->AddObserver(this); |
233 | 235 |
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, | 236 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
239 content::NotificationService::AllSources()); | 237 content::NotificationService::AllSources()); |
240 } | 238 } |
241 | 239 |
242 WrenchMenuModel::~WrenchMenuModel() { | 240 WrenchMenuModel::~WrenchMenuModel() { |
243 if (tab_strip_model_) | 241 if (tab_strip_model_) |
244 tab_strip_model_->RemoveObserver(this); | 242 tab_strip_model_->RemoveObserver(this); |
245 } | 243 } |
246 | 244 |
247 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { | 245 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 UpdateZoomControls(); | 443 UpdateZoomControls(); |
446 } | 444 } |
447 | 445 |
448 void WrenchMenuModel::TabStripModelDeleted() { | 446 void WrenchMenuModel::TabStripModelDeleted() { |
449 // During views shutdown, the tabstrip model/browser is deleted first, while | 447 // During views shutdown, the tabstrip model/browser is deleted first, while |
450 // it is the opposite in gtk land. | 448 // it is the opposite in gtk land. |
451 tab_strip_model_->RemoveObserver(this); | 449 tab_strip_model_->RemoveObserver(this); |
452 tab_strip_model_ = NULL; | 450 tab_strip_model_ = NULL; |
453 } | 451 } |
454 | 452 |
| 453 void WrenchMenuModel::OnZoomLevelChanged(const std::string& host) { |
| 454 UpdateZoomControls(); |
| 455 } |
| 456 |
455 void WrenchMenuModel::Observe(int type, | 457 void WrenchMenuModel::Observe(int type, |
456 const content::NotificationSource& source, | 458 const content::NotificationSource& source, |
457 const content::NotificationDetails& details) { | 459 const content::NotificationDetails& details) { |
458 switch (type) { | 460 DCHECK(type == content::NOTIFICATION_NAV_ENTRY_COMMITTED); |
459 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: | 461 UpdateZoomControls(); |
460 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: | |
461 UpdateZoomControls(); | |
462 break; | |
463 default: | |
464 NOTREACHED(); | |
465 } | |
466 } | 462 } |
467 | 463 |
468 // For testing. | 464 // For testing. |
469 WrenchMenuModel::WrenchMenuModel() | 465 WrenchMenuModel::WrenchMenuModel() |
470 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | 466 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
471 provider_(NULL), | 467 provider_(NULL), |
472 browser_(NULL), | 468 browser_(NULL), |
473 tab_strip_model_(NULL) { | 469 tab_strip_model_(NULL) { |
474 } | 470 } |
475 | 471 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 // registration framework. | 743 // registration framework. |
748 if (profile->IsSyncAccessible()) { | 744 if (profile->IsSyncAccessible()) { |
749 ProfileSyncService* service = | 745 ProfileSyncService* service = |
750 ProfileSyncServiceFactory::GetForProfile(profile); | 746 ProfileSyncServiceFactory::GetForProfile(profile); |
751 SyncGlobalError* error = service->sync_global_error(); | 747 SyncGlobalError* error = service->sync_global_error(); |
752 if (error && error->HasBadge()) | 748 if (error && error->HasBadge()) |
753 return error; | 749 return error; |
754 } | 750 } |
755 return NULL; | 751 return NULL; |
756 } | 752 } |
OLD | NEW |