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

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

Issue 12605010: Add new option to open history page to show more other devices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | 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 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
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_DEVICES) {
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
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_DEVICES) {
194 // We show all "other devices" on the history page.
195 chrome::ExecuteCommandWithDisposition(browser_, IDC_SHOW_HISTORY,
196 ui::DispositionFromEventFlags(event_flags));
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 if (!associator) 267 if (!associator)
261 return; 268 return;
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
277 bool show_more = false;
270 const size_t kMaxSessionsToShow = 3; 278 const size_t kMaxSessionsToShow = 3;
271 size_t num_sessions_added = 0; 279 size_t num_sessions_added = 0;
272 for (size_t i = 0; 280 size_t i = 0;
273 i < sessions.size() && num_sessions_added < kMaxSessionsToShow; 281 for (; i < sessions.size() && num_sessions_added < kMaxSessionsToShow; ++i) {
274 ++i) {
275 const browser_sync::SyncedSession* session = sessions[i]; 282 const browser_sync::SyncedSession* session = sessions[i];
276 const std::string& session_tag = session->session_tag; 283 const std::string& session_tag = session->session_tag;
277 284
278 // Get windows of session. 285 // Get windows of session.
279 std::vector<const SessionWindow*> windows; 286 std::vector<const SessionWindow*> windows;
280 if (!associator->GetForeignSession(session_tag, &windows) || 287 if (!associator->GetForeignSession(session_tag, &windows) ||
281 windows.empty()) { 288 windows.empty()) {
282 continue; 289 continue;
283 } 290 }
284 291
(...skipping 27 matching lines...) Expand all
312 AddItem(kDisabledCommandId, UTF8ToUTF16(session->session_name)); 319 AddItem(kDisabledCommandId, UTF8ToUTF16(session->session_name));
313 AddDeviceFavicon(GetItemCount() - 1, session->device_type); 320 AddDeviceFavicon(GetItemCount() - 1, session->device_type);
314 321
315 // Build tab menu items from sorted session tabs. 322 // Build tab menu items from sorted session tabs.
316 const size_t kMaxTabsPerSessionToShow = 4; 323 const size_t kMaxTabsPerSessionToShow = 4;
317 for (size_t k = 0; 324 for (size_t k = 0;
318 k < std::min(tabs_in_session.size(), kMaxTabsPerSessionToShow); 325 k < std::min(tabs_in_session.size(), kMaxTabsPerSessionToShow);
319 ++k) { 326 ++k) {
320 BuildForeignTabItem(session_tag, *tabs_in_session[k]); 327 BuildForeignTabItem(session_tag, *tabs_in_session[k]);
321 } // for all tabs in one session 328 } // for all tabs in one session
329 if (tabs_in_session.size() > kMaxTabsPerSessionToShow)
330 show_more = true;
322 331
323 ++num_sessions_added; 332 ++num_sessions_added;
324 } // for all sessions 333 } // for all sessions
Alexei Svitkine (slow) 2013/03/19 13:48:21 Nit: Add a blank line after this.
MAD 2013/03/19 14:26:14 Done.
334 if (show_more || i < sessions.size()) {
Alexei Svitkine (slow) 2013/03/19 13:48:21 Shouldn't this be checking |num_sessions_added| ra
MAD 2013/03/19 14:26:14 This is what I was doing initially, but I changed
335 AddSeparator(ui::NORMAL_SEPARATOR);
336 AddItemWithStringId(IDC_RECENT_TABS_MORE_DEVICES,
337 IDS_RECENT_TABS_MORE_DEVICES);
338 }
325 } 339 }
326 340
327 void RecentTabsSubMenuModel::BuildForeignTabItem( 341 void RecentTabsSubMenuModel::BuildForeignTabItem(
328 const std::string& session_tag, 342 const std::string& session_tag,
329 const SessionTab& tab) { 343 const SessionTab& tab) {
330 const TabNavigation& current_navigation = 344 const TabNavigation& current_navigation =
331 tab.navigations.at(tab.normalized_navigation_index()); 345 tab.navigations.at(tab.normalized_navigation_index());
332 NavigationItem item(session_tag, tab.tab_id.id(), 346 NavigationItem item(session_tag, tab.tab_id.id(),
333 current_navigation.virtual_url()); 347 current_navigation.virtual_url());
334 int command_id = ModelIndexToCommandId(model_.size()); 348 int command_id = ModelIndexToCommandId(model_.size());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 RecentTabsSubMenuModel::GetModelAssociator() { 438 RecentTabsSubMenuModel::GetModelAssociator() {
425 if (!associator_) { 439 if (!associator_) {
426 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> 440 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()->
427 GetForProfile(browser_->profile()); 441 GetForProfile(browser_->profile());
428 // Only return the associator if it exists and it is done syncing sessions. 442 // Only return the associator if it exists and it is done syncing sessions.
429 if (service && service->ShouldPushChanges()) 443 if (service && service->ShouldPushChanges())
430 associator_ = service->GetSessionModelAssociator(); 444 associator_ = service->GetSessionModelAssociator();
431 } 445 }
432 return associator_; 446 return associator_;
433 } 447 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698