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

Side by Side Diff: chrome/browser/ui/views/frame/system_menu_model_delegate.cc

Issue 488643005: Fixes regression from changes to restore tabs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge 2 trunk Created 6 years, 4 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
« no previous file with comments | « no previous file | 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/views/frame/system_menu_model_delegate.h" 5 #include "chrome/browser/ui/views/frame/system_menu_model_delegate.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/command_updater.h" 9 #include "chrome/browser/command_updater.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 19 matching lines...) Expand all
30 case IDC_USE_SYSTEM_TITLE_BAR: { 30 case IDC_USE_SYSTEM_TITLE_BAR: {
31 PrefService* prefs = browser_->profile()->GetPrefs(); 31 PrefService* prefs = browser_->profile()->GetPrefs();
32 return !prefs->GetBoolean(prefs::kUseCustomChromeFrame); 32 return !prefs->GetBoolean(prefs::kUseCustomChromeFrame);
33 } 33 }
34 default: 34 default:
35 return false; 35 return false;
36 } 36 }
37 } 37 }
38 38
39 bool SystemMenuModelDelegate::IsCommandIdEnabled(int command_id) const { 39 bool SystemMenuModelDelegate::IsCommandIdEnabled(int command_id) const {
40 return chrome::IsCommandEnabled(browser_, command_id); 40 if (!chrome::IsCommandEnabled(browser_, command_id))
41 return false;
42
43 if (command_id != IDC_RESTORE_TAB)
44 return true;
45
46 // chrome::IsCommandEnabled(IDC_RESTORE_TAB) returns true if TabRestoreService
47 // hasn't been loaded yet. Return false if this is the case as we don't have
48 // a good way to dynamically update the menu when TabRestoreService finishes
49 // loading.
50 // TODO(sky): add a way to update menu.
51 TabRestoreService* trs =
52 TabRestoreServiceFactory::GetForProfile(browser_->profile());
53 if (!trs->IsLoaded()) {
54 trs->LoadTabsFromLastSession();
55 return false;
56 }
57 return true;
41 } 58 }
42 59
43 bool SystemMenuModelDelegate::GetAcceleratorForCommandId(int command_id, 60 bool SystemMenuModelDelegate::GetAcceleratorForCommandId(int command_id,
44 ui::Accelerator* accelerator) { 61 ui::Accelerator* accelerator) {
45 return provider_->GetAcceleratorForCommandId(command_id, accelerator); 62 return provider_->GetAcceleratorForCommandId(command_id, accelerator);
46 } 63 }
47 64
48 bool SystemMenuModelDelegate::IsItemForCommandIdDynamic(int command_id) const { 65 bool SystemMenuModelDelegate::IsItemForCommandIdDynamic(int command_id) const {
49 return command_id == IDC_RESTORE_TAB; 66 return command_id == IDC_RESTORE_TAB;
50 } 67 }
51 68
52 base::string16 SystemMenuModelDelegate::GetLabelForCommandId( 69 base::string16 SystemMenuModelDelegate::GetLabelForCommandId(
53 int command_id) const { 70 int command_id) const {
54 DCHECK_EQ(command_id, IDC_RESTORE_TAB); 71 DCHECK_EQ(command_id, IDC_RESTORE_TAB);
55 72
56 int string_id = IDS_RESTORE_TAB; 73 int string_id = IDS_RESTORE_TAB;
57 if (IsCommandIdEnabled(command_id)) { 74 if (IsCommandIdEnabled(command_id)) {
58 TabRestoreService* trs = 75 TabRestoreService* trs =
59 TabRestoreServiceFactory::GetForProfile(browser_->profile()); 76 TabRestoreServiceFactory::GetForProfile(browser_->profile());
60 if (trs && trs->entries().front()->type == TabRestoreService::WINDOW) 77 trs->LoadTabsFromLastSession();
78 if (trs && !trs->entries().empty() &&
79 trs->entries().front()->type == TabRestoreService::WINDOW)
61 string_id = IDS_RESTORE_WINDOW; 80 string_id = IDS_RESTORE_WINDOW;
62 } 81 }
63 return l10n_util::GetStringUTF16(string_id); 82 return l10n_util::GetStringUTF16(string_id);
64 } 83 }
65 84
66 void SystemMenuModelDelegate::ExecuteCommand(int command_id, int event_flags) { 85 void SystemMenuModelDelegate::ExecuteCommand(int command_id, int event_flags) {
67 chrome::ExecuteCommand(browser_, command_id); 86 chrome::ExecuteCommand(browser_, command_id);
68 } 87 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698