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

Side by Side Diff: chrome/browser/ui/bookmarks/bookmark_context_menu_controller.cc

Issue 2771233002: Remove the wrapper functions content::RecordAction et al (Closed)
Patch Set: Rebased Created 3 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
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/bookmarks/bookmark_context_menu_controller.h" 5 #include "chrome/browser/ui/bookmarks/bookmark_context_menu_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/metrics/user_metrics.h"
11 #include "chrome/app/chrome_command_ids.h" 12 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
13 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" 14 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
14 #include "chrome/browser/prefs/incognito_mode_prefs.h" 15 #include "chrome/browser/prefs/incognito_mode_prefs.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" 17 #include "chrome/browser/ui/bookmarks/bookmark_editor.h"
17 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" 18 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
18 #include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" 19 #include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h"
19 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/chrome_pages.h" 21 #include "chrome/browser/ui/chrome_pages.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/browser/undo/bookmark_undo_service_factory.h" 23 #include "chrome/browser/undo/bookmark_undo_service_factory.h"
23 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
24 #include "chrome/grit/generated_resources.h" 25 #include "chrome/grit/generated_resources.h"
25 #include "components/bookmarks/browser/bookmark_client.h" 26 #include "components/bookmarks/browser/bookmark_client.h"
26 #include "components/bookmarks/browser/bookmark_model.h" 27 #include "components/bookmarks/browser/bookmark_model.h"
27 #include "components/bookmarks/browser/bookmark_utils.h" 28 #include "components/bookmarks/browser/bookmark_utils.h"
28 #include "components/bookmarks/common/bookmark_pref_names.h" 29 #include "components/bookmarks/common/bookmark_pref_names.h"
29 #include "components/bookmarks/managed/managed_bookmark_service.h" 30 #include "components/bookmarks/managed/managed_bookmark_service.h"
30 #include "components/prefs/pref_service.h" 31 #include "components/prefs/pref_service.h"
31 #include "components/strings/grit/components_strings.h" 32 #include "components/strings/grit/components_strings.h"
32 #include "components/undo/bookmark_undo_service.h" 33 #include "components/undo/bookmark_undo_service.h"
33 #include "content/public/browser/page_navigator.h" 34 #include "content/public/browser/page_navigator.h"
34 #include "content/public/browser/user_metrics.h"
35 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
36 36
37 using base::UserMetricsAction; 37 using base::UserMetricsAction;
38 using bookmarks::BookmarkNode; 38 using bookmarks::BookmarkNode;
39 using content::PageNavigator; 39 using content::PageNavigator;
40 40
41 BookmarkContextMenuController::BookmarkContextMenuController( 41 BookmarkContextMenuController::BookmarkContextMenuController(
42 gfx::NativeWindow parent_window, 42 gfx::NativeWindow parent_window,
43 BookmarkContextMenuControllerDelegate* delegate, 43 BookmarkContextMenuControllerDelegate* delegate,
44 Browser* browser, 44 Browser* browser,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 base::WeakPtr<BookmarkContextMenuController> ref(weak_factory_.GetWeakPtr()); 140 base::WeakPtr<BookmarkContextMenuController> ref(weak_factory_.GetWeakPtr());
141 141
142 switch (id) { 142 switch (id) {
143 case IDC_BOOKMARK_BAR_OPEN_ALL: 143 case IDC_BOOKMARK_BAR_OPEN_ALL:
144 case IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO: 144 case IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO:
145 case IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW: { 145 case IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW: {
146 WindowOpenDisposition initial_disposition; 146 WindowOpenDisposition initial_disposition;
147 if (id == IDC_BOOKMARK_BAR_OPEN_ALL) { 147 if (id == IDC_BOOKMARK_BAR_OPEN_ALL) {
148 initial_disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB; 148 initial_disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB;
149 content::RecordAction( 149 base::RecordAction(
150 UserMetricsAction("BookmarkBar_ContextMenu_OpenAll")); 150 UserMetricsAction("BookmarkBar_ContextMenu_OpenAll"));
151 } else if (id == IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW) { 151 } else if (id == IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW) {
152 initial_disposition = WindowOpenDisposition::NEW_WINDOW; 152 initial_disposition = WindowOpenDisposition::NEW_WINDOW;
153 content::RecordAction( 153 base::RecordAction(
154 UserMetricsAction("BookmarkBar_ContextMenu_OpenAllInNewWindow")); 154 UserMetricsAction("BookmarkBar_ContextMenu_OpenAllInNewWindow"));
155 } else { 155 } else {
156 initial_disposition = WindowOpenDisposition::OFF_THE_RECORD; 156 initial_disposition = WindowOpenDisposition::OFF_THE_RECORD;
157 content::RecordAction( 157 base::RecordAction(
158 UserMetricsAction("BookmarkBar_ContextMenu_OpenAllIncognito")); 158 UserMetricsAction("BookmarkBar_ContextMenu_OpenAllIncognito"));
159 } 159 }
160 chrome::OpenAll(parent_window_, navigator_, selection_, 160 chrome::OpenAll(parent_window_, navigator_, selection_,
161 initial_disposition, profile_); 161 initial_disposition, profile_);
162 break; 162 break;
163 } 163 }
164 164
165 case IDC_BOOKMARK_BAR_RENAME_FOLDER: 165 case IDC_BOOKMARK_BAR_RENAME_FOLDER:
166 case IDC_BOOKMARK_BAR_EDIT: 166 case IDC_BOOKMARK_BAR_EDIT:
167 content::RecordAction( 167 base::RecordAction(UserMetricsAction("BookmarkBar_ContextMenu_Edit"));
168 UserMetricsAction("BookmarkBar_ContextMenu_Edit"));
169 168
170 if (selection_.size() != 1) { 169 if (selection_.size() != 1) {
171 NOTREACHED(); 170 NOTREACHED();
172 break; 171 break;
173 } 172 }
174 173
175 BookmarkEditor::Show( 174 BookmarkEditor::Show(
176 parent_window_, 175 parent_window_,
177 profile_, 176 profile_,
178 BookmarkEditor::EditDetails::EditNode(selection_[0]), 177 BookmarkEditor::EditDetails::EditNode(selection_[0]),
179 selection_[0]->is_url() ? BookmarkEditor::SHOW_TREE : 178 selection_[0]->is_url() ? BookmarkEditor::SHOW_TREE :
180 BookmarkEditor::NO_TREE); 179 BookmarkEditor::NO_TREE);
181 break; 180 break;
182 181
183 case IDC_BOOKMARK_BAR_UNDO: { 182 case IDC_BOOKMARK_BAR_UNDO: {
184 content::RecordAction( 183 base::RecordAction(UserMetricsAction("BookmarkBar_ContextMenu_Undo"));
185 UserMetricsAction("BookmarkBar_ContextMenu_Undo"));
186 BookmarkUndoServiceFactory::GetForProfile(profile_)->undo_manager()-> 184 BookmarkUndoServiceFactory::GetForProfile(profile_)->undo_manager()->
187 Undo(); 185 Undo();
188 break; 186 break;
189 } 187 }
190 188
191 case IDC_BOOKMARK_BAR_REDO: { 189 case IDC_BOOKMARK_BAR_REDO: {
192 content::RecordAction( 190 base::RecordAction(UserMetricsAction("BookmarkBar_ContextMenu_Redo"));
193 UserMetricsAction("BookmarkBar_ContextMenu_Redo"));
194 BookmarkUndoServiceFactory::GetForProfile(profile_)->undo_manager()-> 191 BookmarkUndoServiceFactory::GetForProfile(profile_)->undo_manager()->
195 Redo(); 192 Redo();
196 break; 193 break;
197 } 194 }
198 195
199 case IDC_BOOKMARK_BAR_REMOVE: { 196 case IDC_BOOKMARK_BAR_REMOVE: {
200 content::RecordAction( 197 base::RecordAction(UserMetricsAction("BookmarkBar_ContextMenu_Remove"));
201 UserMetricsAction("BookmarkBar_ContextMenu_Remove"));
202 198
203 for (size_t i = 0; i < selection_.size(); ++i) { 199 for (size_t i = 0; i < selection_.size(); ++i) {
204 int index = selection_[i]->parent()->GetIndexOf(selection_[i]); 200 int index = selection_[i]->parent()->GetIndexOf(selection_[i]);
205 if (index > -1) 201 if (index > -1)
206 model_->Remove(selection_[i]); 202 model_->Remove(selection_[i]);
207 } 203 }
208 selection_.clear(); 204 selection_.clear();
209 break; 205 break;
210 } 206 }
211 207
212 case IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK: { 208 case IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK: {
213 content::RecordAction( 209 base::RecordAction(UserMetricsAction("BookmarkBar_ContextMenu_Add"));
214 UserMetricsAction("BookmarkBar_ContextMenu_Add"));
215 210
216 int index; 211 int index;
217 const BookmarkNode* parent = 212 const BookmarkNode* parent =
218 bookmarks::GetParentForNewNodes(parent_, selection_, &index); 213 bookmarks::GetParentForNewNodes(parent_, selection_, &index);
219 GURL url; 214 GURL url;
220 base::string16 title; 215 base::string16 title;
221 chrome::GetURLAndTitleToBookmark( 216 chrome::GetURLAndTitleToBookmark(
222 browser_->tab_strip_model()->GetActiveWebContents(), 217 browser_->tab_strip_model()->GetActiveWebContents(),
223 &url, &title); 218 &url, &title);
224 BookmarkEditor::Show(parent_window_, 219 BookmarkEditor::Show(parent_window_,
225 profile_, 220 profile_,
226 BookmarkEditor::EditDetails::AddNodeInFolder( 221 BookmarkEditor::EditDetails::AddNodeInFolder(
227 parent, index, url, title), 222 parent, index, url, title),
228 BookmarkEditor::SHOW_TREE); 223 BookmarkEditor::SHOW_TREE);
229 break; 224 break;
230 } 225 }
231 226
232 case IDC_BOOKMARK_BAR_NEW_FOLDER: { 227 case IDC_BOOKMARK_BAR_NEW_FOLDER: {
233 content::RecordAction( 228 base::RecordAction(
234 UserMetricsAction("BookmarkBar_ContextMenu_NewFolder")); 229 UserMetricsAction("BookmarkBar_ContextMenu_NewFolder"));
235 230
236 int index; 231 int index;
237 const BookmarkNode* parent = 232 const BookmarkNode* parent =
238 bookmarks::GetParentForNewNodes(parent_, selection_, &index); 233 bookmarks::GetParentForNewNodes(parent_, selection_, &index);
239 BookmarkEditor::Show( 234 BookmarkEditor::Show(
240 parent_window_, 235 parent_window_,
241 profile_, 236 profile_,
242 BookmarkEditor::EditDetails::AddFolder(parent, index), 237 BookmarkEditor::EditDetails::AddFolder(parent, index),
243 BookmarkEditor::SHOW_TREE); 238 BookmarkEditor::SHOW_TREE);
(...skipping 15 matching lines...) Expand all
259 case IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS: { 254 case IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS: {
260 PrefService* prefs = profile_->GetPrefs(); 255 PrefService* prefs = profile_->GetPrefs();
261 prefs->SetBoolean( 256 prefs->SetBoolean(
262 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar, 257 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar,
263 !prefs->GetBoolean( 258 !prefs->GetBoolean(
264 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar)); 259 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar));
265 break; 260 break;
266 } 261 }
267 262
268 case IDC_BOOKMARK_MANAGER: { 263 case IDC_BOOKMARK_MANAGER: {
269 content::RecordAction(UserMetricsAction("ShowBookmarkManager")); 264 base::RecordAction(UserMetricsAction("ShowBookmarkManager"));
270 if (selection_.size() != 1) 265 if (selection_.size() != 1)
271 chrome::ShowBookmarkManager(browser_); 266 chrome::ShowBookmarkManager(browser_);
272 else if (selection_[0]->is_folder()) 267 else if (selection_[0]->is_folder())
273 chrome::ShowBookmarkManagerForNode(browser_, selection_[0]->id()); 268 chrome::ShowBookmarkManagerForNode(browser_, selection_[0]->id());
274 else if (parent_) 269 else if (parent_)
275 chrome::ShowBookmarkManagerForNode(browser_, parent_->id()); 270 chrome::ShowBookmarkManagerForNode(browser_, parent_->id());
276 else 271 else
277 chrome::ShowBookmarkManager(browser_); 272 chrome::ShowBookmarkManager(browser_);
278 break; 273 break;
279 } 274 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 return !managed->managed_node()->empty(); 424 return !managed->managed_node()->empty();
430 } 425 }
431 426
432 return true; 427 return true;
433 } 428 }
434 429
435 void BookmarkContextMenuController::BookmarkModelChanged() { 430 void BookmarkContextMenuController::BookmarkModelChanged() {
436 if (delegate_) 431 if (delegate_)
437 delegate_->CloseMenu(); 432 delegate_->CloseMenu();
438 } 433 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698