[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / status_icons / status_icon_linux_wrapper.cc
blob7e192e1dcbaa445331e2fe8792a236ff1178a1c5
1 // Copyright 2013 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/status_icons/status_icon_linux_wrapper.h"
7 #include "ui/views/linux_ui/linux_ui.h"
9 StatusIconLinuxWrapper::StatusIconLinuxWrapper(
10 views::StatusIconLinux* status_icon)
11 : menu_model_(NULL) {
12 status_icon_.reset(status_icon);
13 status_icon_->set_delegate(this);
16 StatusIconLinuxWrapper::~StatusIconLinuxWrapper() {
17 if (menu_model_)
18 menu_model_->RemoveObserver(this);
21 void StatusIconLinuxWrapper::SetImage(const gfx::ImageSkia& image) {
22 status_icon_->SetImage(image);
25 void StatusIconLinuxWrapper::SetPressedImage(const gfx::ImageSkia& image) {
26 status_icon_->SetPressedImage(image);
29 void StatusIconLinuxWrapper::SetToolTip(const base::string16& tool_tip) {
30 status_icon_->SetToolTip(tool_tip);
33 void StatusIconLinuxWrapper::DisplayBalloon(const gfx::ImageSkia& icon,
34 const base::string16& title,
35 const base::string16& contents) {
36 notification_.DisplayBalloon(icon, title, contents);
39 void StatusIconLinuxWrapper::OnClick() {
40 DispatchClickEvent();
43 bool StatusIconLinuxWrapper::HasClickAction() {
44 return HasObservers();
47 void StatusIconLinuxWrapper::OnMenuStateChanged() {
48 status_icon_->RefreshPlatformContextMenu();
51 StatusIconLinuxWrapper* StatusIconLinuxWrapper::CreateWrappedStatusIcon(
52 const gfx::ImageSkia& image,
53 const base::string16& tool_tip) {
54 const views::LinuxUI* linux_ui = views::LinuxUI::instance();
55 if (linux_ui) {
56 scoped_ptr<views::StatusIconLinux> status_icon =
57 linux_ui->CreateLinuxStatusIcon(image, tool_tip);
58 if (status_icon.get())
59 return new StatusIconLinuxWrapper(status_icon.release());
61 return NULL;
64 void StatusIconLinuxWrapper::UpdatePlatformContextMenu(
65 StatusIconMenuModel* model) {
66 // If a menu already exists, remove ourself from its oberver list.
67 if (menu_model_)
68 menu_model_->RemoveObserver(this);
70 status_icon_->UpdatePlatformContextMenu(model);
71 menu_model_ = model;
73 if (model)
74 model->AddObserver(this);