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

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

Issue 16650002: Add UMA tracking to "Recently Closed" submenu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Histogram recent tabs submenu usage. Created 7 years, 6 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 | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | 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/metrics/histogram.h"
8 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
9 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/favicon/favicon_service_factory.h" 12 #include "chrome/browser/favicon/favicon_service_factory.h"
12 #include "chrome/browser/favicon/favicon_types.h" 13 #include "chrome/browser/favicon/favicon_types.h"
13 #include "chrome/browser/prefs/scoped_user_pref_update.h" 14 #include "chrome/browser/prefs/scoped_user_pref_update.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/sessions/session_restore.h" 16 #include "chrome/browser/sessions/session_restore.h"
16 #include "chrome/browser/sessions/tab_restore_service.h" 17 #include "chrome/browser/sessions/tab_restore_service.h"
17 #include "chrome/browser/sessions/tab_restore_service_delegate.h" 18 #include "chrome/browser/sessions/tab_restore_service_delegate.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 106
106 // Convert |command_id| of menu item to index in window model. 107 // Convert |command_id| of menu item to index in window model.
107 int CommandIdToWindowModelIndex(int command_id) { 108 int CommandIdToWindowModelIndex(int command_id) {
108 DCHECK_GE(command_id, kFirstWindowCommandId); 109 DCHECK_GE(command_id, kFirstWindowCommandId);
109 DCHECK_LT(command_id, RecentTabsSubMenuModel::kRecentlyClosedHeaderCommandId); 110 DCHECK_LT(command_id, RecentTabsSubMenuModel::kRecentlyClosedHeaderCommandId);
110 return command_id - kFirstWindowCommandId; 111 return command_id - kFirstWindowCommandId;
111 } 112 }
112 113
113 } // namepace 114 } // namepace
114 115
116 enum RecentTabAction {
117 LOCAL_SESSION_TAB = 0,
118 OTHER_DEVICE_TAB,
119 RESTORE_WINDOW,
120 SHOW_MORE,
121 LIMIT_RECENT_TAB_ACTION
122 };
123
115 // An element in |RecentTabsSubMenuModel::tab_navigation_items_| that stores 124 // An element in |RecentTabsSubMenuModel::tab_navigation_items_| that stores
116 // the navigation information of a local or foreign tab required to restore the 125 // the navigation information of a local or foreign tab required to restore the
117 // tab. 126 // tab.
118 struct RecentTabsSubMenuModel::TabNavigationItem { 127 struct RecentTabsSubMenuModel::TabNavigationItem {
119 TabNavigationItem() : tab_id(-1) {} 128 TabNavigationItem() : tab_id(-1) {}
120 129
121 TabNavigationItem(const std::string& session_tag, 130 TabNavigationItem(const std::string& session_tag,
122 const SessionID::id_type& tab_id, 131 const SessionID::id_type& tab_id,
123 const GURL& url) 132 const GURL& url)
124 : session_tag(session_tag), 133 : session_tag(session_tag),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 if (command_id == kRecentlyClosedHeaderCommandId && 200 if (command_id == kRecentlyClosedHeaderCommandId &&
192 reopen_closed_tab_accelerator_.key_code() != ui::VKEY_UNKNOWN) { 201 reopen_closed_tab_accelerator_.key_code() != ui::VKEY_UNKNOWN) {
193 *accelerator = reopen_closed_tab_accelerator_; 202 *accelerator = reopen_closed_tab_accelerator_;
194 return true; 203 return true;
195 } 204 }
196 return false; 205 return false;
197 } 206 }
198 207
199 void RecentTabsSubMenuModel::ExecuteCommand(int command_id, int event_flags) { 208 void RecentTabsSubMenuModel::ExecuteCommand(int command_id, int event_flags) {
200 if (command_id == IDC_SHOW_HISTORY) { 209 if (command_id == IDC_SHOW_HISTORY) {
210 UMA_HISTOGRAM_ENUMERATION("WrenchMenu.RecentTabsSubMenu", SHOW_MORE,
211 LIMIT_RECENT_TAB_ACTION);
201 // We show all "other devices" on the history page. 212 // We show all "other devices" on the history page.
202 chrome::ExecuteCommandWithDisposition(browser_, IDC_SHOW_HISTORY, 213 chrome::ExecuteCommandWithDisposition(browser_, IDC_SHOW_HISTORY,
203 ui::DispositionFromEventFlags(event_flags)); 214 ui::DispositionFromEventFlags(event_flags));
204 return; 215 return;
205 } 216 }
206 217
207 DCHECK_NE(kOtherDeviceHeaderCommandId, command_id); 218 DCHECK_NE(kOtherDeviceHeaderCommandId, command_id);
208 DCHECK_NE(IDC_RECENT_TABS_NO_DEVICE_TABS, command_id); 219 DCHECK_NE(IDC_RECENT_TABS_NO_DEVICE_TABS, command_id);
209 220
210 WindowOpenDisposition disposition = 221 WindowOpenDisposition disposition =
211 ui::DispositionFromEventFlags(event_flags); 222 ui::DispositionFromEventFlags(event_flags);
212 if (disposition == CURRENT_TAB) // Force to open a new foreground tab. 223 if (disposition == CURRENT_TAB) // Force to open a new foreground tab.
213 disposition = NEW_FOREGROUND_TAB; 224 disposition = NEW_FOREGROUND_TAB;
214 225
215 TabRestoreService* service = 226 TabRestoreService* service =
216 TabRestoreServiceFactory::GetForProfile(browser_->profile()); 227 TabRestoreServiceFactory::GetForProfile(browser_->profile());
217 TabRestoreServiceDelegate* delegate = 228 TabRestoreServiceDelegate* delegate =
218 TabRestoreServiceDelegate::FindDelegateForWebContents( 229 TabRestoreServiceDelegate::FindDelegateForWebContents(
219 browser_->tab_strip_model()->GetActiveWebContents()); 230 browser_->tab_strip_model()->GetActiveWebContents());
220 if (IsTabModelCommandId(command_id)) { 231 if (IsTabModelCommandId(command_id)) {
221 int model_idx = CommandIdToTabModelIndex(command_id); 232 int model_idx = CommandIdToTabModelIndex(command_id);
222 DCHECK(model_idx >= 0 && 233 DCHECK(model_idx >= 0 &&
223 model_idx < static_cast<int>(tab_navigation_items_.size())); 234 model_idx < static_cast<int>(tab_navigation_items_.size()));
224 const TabNavigationItem& item = tab_navigation_items_[model_idx]; 235 const TabNavigationItem& item = tab_navigation_items_[model_idx];
225 DCHECK(item.tab_id > -1 && item.url.is_valid()); 236 DCHECK(item.tab_id > -1 && item.url.is_valid());
226 237
227 if (item.session_tag.empty()) { // Restore tab of local session. 238 if (item.session_tag.empty()) { // Restore tab of local session.
228 if (service && delegate) { 239 if (service && delegate) {
240 UMA_HISTOGRAM_ENUMERATION("WrenchMenu.RecentTabsSubMenu",
241 LOCAL_SESSION_TAB, LIMIT_RECENT_TAB_ACTION);
229 service->RestoreEntryById(delegate, item.tab_id, 242 service->RestoreEntryById(delegate, item.tab_id,
230 browser_->host_desktop_type(), disposition); 243 browser_->host_desktop_type(), disposition);
231 } 244 }
232 } else { // Restore tab of foreign session. 245 } else { // Restore tab of foreign session.
233 browser_sync::SessionModelAssociator* associator = GetModelAssociator(); 246 browser_sync::SessionModelAssociator* associator = GetModelAssociator();
234 if (!associator) 247 if (!associator)
235 return; 248 return;
236 const SessionTab* tab; 249 const SessionTab* tab;
237 if (!associator->GetForeignTab(item.session_tag, item.tab_id, &tab)) 250 if (!associator->GetForeignTab(item.session_tag, item.tab_id, &tab))
238 return; 251 return;
239 if (tab->navigations.empty()) 252 if (tab->navigations.empty())
240 return; 253 return;
254 UMA_HISTOGRAM_ENUMERATION("WrenchMenu.RecentTabsSubMenu",
255 OTHER_DEVICE_TAB, LIMIT_RECENT_TAB_ACTION);
241 SessionRestore::RestoreForeignSessionTab( 256 SessionRestore::RestoreForeignSessionTab(
242 browser_->tab_strip_model()->GetActiveWebContents(), 257 browser_->tab_strip_model()->GetActiveWebContents(),
243 *tab, disposition); 258 *tab, disposition);
244 } 259 }
245 } else { 260 } else {
246 DCHECK(IsWindowModelCommandId(command_id)); 261 DCHECK(IsWindowModelCommandId(command_id));
247 if (service && delegate) { 262 if (service && delegate) {
248 int model_idx = CommandIdToWindowModelIndex(command_id); 263 int model_idx = CommandIdToWindowModelIndex(command_id);
249 DCHECK(model_idx >= 0 && 264 DCHECK(model_idx >= 0 &&
250 model_idx < static_cast<int>(window_items_.size())); 265 model_idx < static_cast<int>(window_items_.size()));
266 UMA_HISTOGRAM_ENUMERATION("WrenchMenu.RecentTabsSubMenu", RESTORE_WINDOW,
267 LIMIT_RECENT_TAB_ACTION);
251 service->RestoreEntryById(delegate, window_items_[model_idx], 268 service->RestoreEntryById(delegate, window_items_[model_idx],
252 browser_->host_desktop_type(), disposition); 269 browser_->host_desktop_type(), disposition);
253 } 270 }
254 } 271 }
255 } 272 }
256 273
257 int RecentTabsSubMenuModel::GetMaxWidthForItemAtIndex(int item_index) const { 274 int RecentTabsSubMenuModel::GetMaxWidthForItemAtIndex(int item_index) const {
258 int command_id = GetCommandIdAt(item_index); 275 int command_id = GetCommandIdAt(item_index);
259 if (command_id == IDC_RECENT_TABS_NO_DEVICE_TABS || 276 if (command_id == IDC_RECENT_TABS_NO_DEVICE_TABS ||
260 command_id == kRecentlyClosedHeaderCommandId) { 277 command_id == kRecentlyClosedHeaderCommandId) {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 RecentTabsSubMenuModel::GetModelAssociator() { 537 RecentTabsSubMenuModel::GetModelAssociator() {
521 if (!associator_) { 538 if (!associator_) {
522 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> 539 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()->
523 GetForProfile(browser_->profile()); 540 GetForProfile(browser_->profile());
524 // Only return the associator if it exists and it is done syncing sessions. 541 // Only return the associator if it exists and it is done syncing sessions.
525 if (service && service->ShouldPushChanges()) 542 if (service && service->ShouldPushChanges())
526 associator_ = service->GetSessionModelAssociator(); 543 associator_ = service->GetSessionModelAssociator();
527 } 544 }
528 return associator_; 545 return associator_;
529 } 546 }
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698