[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / download / download_shelf_context_menu_view.cc
blob570f3e3bea9589a89c61a2e10691a1994c36cf57
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h"
7 #include "base/i18n/rtl.h"
8 #include "base/logging.h"
9 #include "chrome/browser/download/download_item_model.h"
10 #include "content/public/browser/download_item.h"
11 #include "content/public/browser/page_navigator.h"
12 #include "ui/gfx/point.h"
13 #include "ui/views/controls/menu/menu_runner.h"
15 DownloadShelfContextMenuView::DownloadShelfContextMenuView(
16 content::DownloadItem* download_item,
17 content::PageNavigator* navigator)
18 : DownloadShelfContextMenu(download_item, navigator) {
21 DownloadShelfContextMenuView::~DownloadShelfContextMenuView() {}
23 void DownloadShelfContextMenuView::Run(views::Widget* parent_widget,
24 const gfx::Rect& rect,
25 ui::MenuSourceType source_type) {
26 ui::MenuModel* menu_model = GetMenuModel();
27 // Run() should not be getting called if the DownloadItem was destroyed.
28 DCHECK(menu_model);
30 menu_runner_.reset(new views::MenuRunner(menu_model));
32 // The menu's alignment is determined based on the UI layout.
33 views::MenuAnchorPosition position;
34 if (base::i18n::IsRTL())
35 position = views::MENU_ANCHOR_TOPRIGHT;
36 else
37 position = views::MENU_ANCHOR_TOPLEFT;
39 // The return value of RunMenuAt indicates whether the MenuRunner was deleted
40 // while running the menu, which indicates that the containing view may have
41 // been deleted. We ignore the return value because our caller already assumes
42 // that the view could be deleted by the time we return from here.
43 if (menu_runner_->RunMenuAt(
44 parent_widget,
45 NULL,
46 rect,
47 position,
48 source_type,
49 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) ==
50 views::MenuRunner::MENU_DELETED) {
51 return;
53 close_time_ = base::TimeTicks::Now();