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/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 30 matching lines...) Expand all Loading... |
41 return false; | 41 return false; |
42 | 42 |
43 if (command_id != IDC_RESTORE_TAB) | 43 if (command_id != IDC_RESTORE_TAB) |
44 return true; | 44 return true; |
45 | 45 |
46 // chrome::IsCommandEnabled(IDC_RESTORE_TAB) returns true if TabRestoreService | 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 | 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 | 48 // a good way to dynamically update the menu when TabRestoreService finishes |
49 // loading. | 49 // loading. |
50 // TODO(sky): add a way to update menu. | 50 // TODO(sky): add a way to update menu. |
51 TabRestoreService* trs = | 51 sessions::TabRestoreService* trs = |
52 TabRestoreServiceFactory::GetForProfile(browser_->profile()); | 52 TabRestoreServiceFactory::GetForProfile(browser_->profile()); |
53 if (!trs->IsLoaded()) { | 53 if (!trs->IsLoaded()) { |
54 trs->LoadTabsFromLastSession(); | 54 trs->LoadTabsFromLastSession(); |
55 return false; | 55 return false; |
56 } | 56 } |
57 return true; | 57 return true; |
58 } | 58 } |
59 | 59 |
60 bool SystemMenuModelDelegate::GetAcceleratorForCommandId(int command_id, | 60 bool SystemMenuModelDelegate::GetAcceleratorForCommandId(int command_id, |
61 ui::Accelerator* accelerator) { | 61 ui::Accelerator* accelerator) { |
62 return provider_->GetAcceleratorForCommandId(command_id, accelerator); | 62 return provider_->GetAcceleratorForCommandId(command_id, accelerator); |
63 } | 63 } |
64 | 64 |
65 bool SystemMenuModelDelegate::IsItemForCommandIdDynamic(int command_id) const { | 65 bool SystemMenuModelDelegate::IsItemForCommandIdDynamic(int command_id) const { |
66 return command_id == IDC_RESTORE_TAB; | 66 return command_id == IDC_RESTORE_TAB; |
67 } | 67 } |
68 | 68 |
69 base::string16 SystemMenuModelDelegate::GetLabelForCommandId( | 69 base::string16 SystemMenuModelDelegate::GetLabelForCommandId( |
70 int command_id) const { | 70 int command_id) const { |
71 DCHECK_EQ(command_id, IDC_RESTORE_TAB); | 71 DCHECK_EQ(command_id, IDC_RESTORE_TAB); |
72 | 72 |
73 int string_id = IDS_RESTORE_TAB; | 73 int string_id = IDS_RESTORE_TAB; |
74 if (IsCommandIdEnabled(command_id)) { | 74 if (IsCommandIdEnabled(command_id)) { |
75 TabRestoreService* trs = | 75 sessions::TabRestoreService* trs = |
76 TabRestoreServiceFactory::GetForProfile(browser_->profile()); | 76 TabRestoreServiceFactory::GetForProfile(browser_->profile()); |
77 trs->LoadTabsFromLastSession(); | 77 trs->LoadTabsFromLastSession(); |
78 if (trs && !trs->entries().empty() && | 78 if (trs && !trs->entries().empty() && |
79 trs->entries().front()->type == TabRestoreService::WINDOW) | 79 trs->entries().front()->type == sessions::TabRestoreService::WINDOW) |
80 string_id = IDS_RESTORE_WINDOW; | 80 string_id = IDS_RESTORE_WINDOW; |
81 } | 81 } |
82 return l10n_util::GetStringUTF16(string_id); | 82 return l10n_util::GetStringUTF16(string_id); |
83 } | 83 } |
84 | 84 |
85 void SystemMenuModelDelegate::ExecuteCommand(int command_id, int event_flags) { | 85 void SystemMenuModelDelegate::ExecuteCommand(int command_id, int event_flags) { |
86 chrome::ExecuteCommand(browser_, command_id); | 86 chrome::ExecuteCommand(browser_, command_id); |
87 } | 87 } |
OLD | NEW |