Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/recent_tabs_sub_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 bool RecentTabsSubMenuModel::IsCommandIdChecked(int command_id) const { | 142 bool RecentTabsSubMenuModel::IsCommandIdChecked(int command_id) const { |
| 143 return false; | 143 return false; |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool RecentTabsSubMenuModel::IsCommandIdEnabled(int command_id) const { | 146 bool RecentTabsSubMenuModel::IsCommandIdEnabled(int command_id) const { |
| 147 if (command_id == IDC_RESTORE_TAB) | 147 if (command_id == IDC_RESTORE_TAB) |
| 148 return chrome::IsCommandEnabled(browser_, command_id); | 148 return chrome::IsCommandEnabled(browser_, command_id); |
| 149 if (command_id == kDisabledCommandId || | 149 if (command_id == kDisabledCommandId || |
| 150 command_id == IDC_RECENT_TABS_NO_DEVICE_TABS) { | 150 command_id == IDC_RECENT_TABS_NO_DEVICE_TABS) { |
| 151 return false; | 151 return false; |
| 152 } else if (command_id == IDC_RECENT_TABS_MORE) { | |
|
sky
2013/03/22 03:55:56
nit: no else for returns (see style guide), just a
MAD
2013/03/22 14:17:41
Ho, yes, sorry, I keep forgetting about that one..
| |
| 153 return true; | |
| 152 } | 154 } |
| 153 int model_index = CommandIdToModelIndex(command_id); | 155 int model_index = CommandIdToModelIndex(command_id); |
| 154 return model_index >= 0 && model_index < static_cast<int>(model_.size()); | 156 return model_index >= 0 && model_index < static_cast<int>(model_.size()); |
| 155 } | 157 } |
| 156 | 158 |
| 157 bool RecentTabsSubMenuModel::GetAcceleratorForCommandId( | 159 bool RecentTabsSubMenuModel::GetAcceleratorForCommandId( |
| 158 int command_id, ui::Accelerator* accelerator) { | 160 int command_id, ui::Accelerator* accelerator) { |
| 159 if (command_id == IDC_RESTORE_TAB && | 161 if (command_id == IDC_RESTORE_TAB && |
| 160 reopen_closed_tab_accelerator_.key_code() != ui::VKEY_UNKNOWN) { | 162 reopen_closed_tab_accelerator_.key_code() != ui::VKEY_UNKNOWN) { |
| 161 *accelerator = reopen_closed_tab_accelerator_; | 163 *accelerator = reopen_closed_tab_accelerator_; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 181 } | 183 } |
| 182 } | 184 } |
| 183 return l10n_util::GetStringUTF16(string_id); | 185 return l10n_util::GetStringUTF16(string_id); |
| 184 } | 186 } |
| 185 | 187 |
| 186 void RecentTabsSubMenuModel::ExecuteCommand(int command_id, int event_flags) { | 188 void RecentTabsSubMenuModel::ExecuteCommand(int command_id, int event_flags) { |
| 187 if (command_id == IDC_RESTORE_TAB) { | 189 if (command_id == IDC_RESTORE_TAB) { |
| 188 chrome::ExecuteCommandWithDisposition(browser_, command_id, | 190 chrome::ExecuteCommandWithDisposition(browser_, command_id, |
| 189 ui::DispositionFromEventFlags(event_flags)); | 191 ui::DispositionFromEventFlags(event_flags)); |
| 190 return; | 192 return; |
| 193 } else if (command_id == IDC_RECENT_TABS_MORE) { | |
|
sky
2013/03/22 03:55:56
same comment as 152.
MAD
2013/03/22 14:17:41
Done.
| |
| 194 // We show all "other devices" on the history page. | |
| 195 chrome::ExecuteCommandWithDisposition(browser_, IDC_SHOW_HISTORY, | |
| 196 ui::DispositionFromEventFlags(event_flags)); | |
|
sky
2013/03/22 03:55:56
Does this do something more than just show history
MAD
2013/03/22 14:17:41
No, why?
| |
| 197 return; | |
| 191 } | 198 } |
| 192 | 199 |
| 193 DCHECK_NE(kDisabledCommandId, command_id); | 200 DCHECK_NE(kDisabledCommandId, command_id); |
| 194 DCHECK_NE(IDC_RECENT_TABS_NO_DEVICE_TABS, command_id); | 201 DCHECK_NE(IDC_RECENT_TABS_NO_DEVICE_TABS, command_id); |
| 195 | 202 |
| 196 int model_idx = CommandIdToModelIndex(command_id); | 203 int model_idx = CommandIdToModelIndex(command_id); |
| 197 DCHECK(model_idx >= 0 && model_idx < static_cast<int>(model_.size())); | 204 DCHECK(model_idx >= 0 && model_idx < static_cast<int>(model_.size())); |
| 198 const NavigationItem& item = model_[model_idx]; | 205 const NavigationItem& item = model_[model_idx]; |
| 199 DCHECK(item.tab_id > -1 && item.url.is_valid()); | 206 DCHECK(item.tab_id > -1 && item.url.is_valid()); |
| 200 | 207 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 | 269 |
| 263 std::vector<const browser_sync::SyncedSession*> sessions; | 270 std::vector<const browser_sync::SyncedSession*> sessions; |
| 264 if (!associator->GetAllForeignSessions(&sessions)) | 271 if (!associator->GetAllForeignSessions(&sessions)) |
| 265 return; | 272 return; |
| 266 | 273 |
| 267 // Sort sessions from most recent to least recent. | 274 // Sort sessions from most recent to least recent. |
| 268 std::sort(sessions.begin(), sessions.end(), SortSessionsByRecency); | 275 std::sort(sessions.begin(), sessions.end(), SortSessionsByRecency); |
| 269 | 276 |
| 270 const size_t kMaxSessionsToShow = 3; | 277 const size_t kMaxSessionsToShow = 3; |
| 271 size_t num_sessions_added = 0; | 278 size_t num_sessions_added = 0; |
| 272 for (size_t i = 0; | 279 size_t i = 0; |
|
sky
2013/03/22 03:55:56
Why are you moving i outside the loop?
MAD
2013/03/22 14:17:41
Oups, sorry about that... I should have brought it
| |
| 273 i < sessions.size() && num_sessions_added < kMaxSessionsToShow; | 280 for (; i < sessions.size() && num_sessions_added < kMaxSessionsToShow; ++i) { |
| 274 ++i) { | |
| 275 const browser_sync::SyncedSession* session = sessions[i]; | 281 const browser_sync::SyncedSession* session = sessions[i]; |
| 276 const std::string& session_tag = session->session_tag; | 282 const std::string& session_tag = session->session_tag; |
| 277 | 283 |
| 278 // Get windows of session. | 284 // Get windows of session. |
| 279 std::vector<const SessionWindow*> windows; | 285 std::vector<const SessionWindow*> windows; |
| 280 if (!associator->GetForeignSession(session_tag, &windows) || | 286 if (!associator->GetForeignSession(session_tag, &windows) || |
| 281 windows.empty()) { | 287 windows.empty()) { |
| 282 continue; | 288 continue; |
| 283 } | 289 } |
| 284 | 290 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 315 // Build tab menu items from sorted session tabs. | 321 // Build tab menu items from sorted session tabs. |
| 316 const size_t kMaxTabsPerSessionToShow = 4; | 322 const size_t kMaxTabsPerSessionToShow = 4; |
| 317 for (size_t k = 0; | 323 for (size_t k = 0; |
| 318 k < std::min(tabs_in_session.size(), kMaxTabsPerSessionToShow); | 324 k < std::min(tabs_in_session.size(), kMaxTabsPerSessionToShow); |
| 319 ++k) { | 325 ++k) { |
| 320 BuildForeignTabItem(session_tag, *tabs_in_session[k]); | 326 BuildForeignTabItem(session_tag, *tabs_in_session[k]); |
| 321 } // for all tabs in one session | 327 } // for all tabs in one session |
| 322 | 328 |
| 323 ++num_sessions_added; | 329 ++num_sessions_added; |
| 324 } // for all sessions | 330 } // for all sessions |
| 331 | |
| 332 AddSeparator(ui::NORMAL_SEPARATOR); | |
|
sky
2013/03/22 03:55:56
Is it possible to get here and nothing has been ad
MAD
2013/03/22 14:17:41
Added a comment... Thanks!
| |
| 333 AddItemWithStringId(IDC_RECENT_TABS_MORE, IDS_RECENT_TABS_MORE); | |
| 325 } | 334 } |
| 326 | 335 |
| 327 void RecentTabsSubMenuModel::BuildForeignTabItem( | 336 void RecentTabsSubMenuModel::BuildForeignTabItem( |
| 328 const std::string& session_tag, | 337 const std::string& session_tag, |
| 329 const SessionTab& tab) { | 338 const SessionTab& tab) { |
| 330 const TabNavigation& current_navigation = | 339 const TabNavigation& current_navigation = |
| 331 tab.navigations.at(tab.normalized_navigation_index()); | 340 tab.navigations.at(tab.normalized_navigation_index()); |
| 332 NavigationItem item(session_tag, tab.tab_id.id(), | 341 NavigationItem item(session_tag, tab.tab_id.id(), |
| 333 current_navigation.virtual_url()); | 342 current_navigation.virtual_url()); |
| 334 int command_id = ModelIndexToCommandId(model_.size()); | 343 int command_id = ModelIndexToCommandId(model_.size()); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 RecentTabsSubMenuModel::GetModelAssociator() { | 433 RecentTabsSubMenuModel::GetModelAssociator() { |
| 425 if (!associator_) { | 434 if (!associator_) { |
| 426 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> | 435 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> |
| 427 GetForProfile(browser_->profile()); | 436 GetForProfile(browser_->profile()); |
| 428 // Only return the associator if it exists and it is done syncing sessions. | 437 // Only return the associator if it exists and it is done syncing sessions. |
| 429 if (service && service->ShouldPushChanges()) | 438 if (service && service->ShouldPushChanges()) |
| 430 associator_ = service->GetSessionModelAssociator(); | 439 associator_ = service->GetSessionModelAssociator(); |
| 431 } | 440 } |
| 432 return associator_; | 441 return associator_; |
| 433 } | 442 } |
| OLD | NEW |