ExtensionSyncService: listen for relevant changes instead of being explicitly called...
[chromium-blink-merge.git] / chrome / browser / ui / content_settings / content_setting_media_menu_model.cc
blob98b0cabbdf1f8c3d3a19f898f772a4a2e2f51523
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/content_settings/content_setting_media_menu_model.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
9 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
11 ContentSettingMediaMenuModel::ContentSettingMediaMenuModel(
12 content::MediaStreamType type,
13 ContentSettingBubbleModel* bubble_model,
14 const MenuLabelChangedCallback& callback)
15 : ui::SimpleMenuModel(this),
16 type_(type),
17 media_bubble_model_(bubble_model),
18 callback_(callback) {
19 DCHECK(type_ == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
20 type_ == content::MEDIA_DEVICE_VIDEO_CAPTURE);
21 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM,
22 media_bubble_model_->content_type());
23 MediaCaptureDevicesDispatcher* dispatcher =
24 MediaCaptureDevicesDispatcher::GetInstance();
25 const content::MediaStreamDevices& devices =
26 (type_ == content::MEDIA_DEVICE_AUDIO_CAPTURE) ?
27 dispatcher->GetAudioCaptureDevices() :
28 dispatcher->GetVideoCaptureDevices();
30 for (size_t i = 0; i < devices.size(); ++i) {
31 commands_.insert(std::make_pair(commands_.size(), devices[i]));
32 AddItem(i, base::UTF8ToUTF16(devices[i].name));
36 ContentSettingMediaMenuModel::~ContentSettingMediaMenuModel() {
39 bool ContentSettingMediaMenuModel::IsCommandIdChecked(int command_id) const {
40 return false;
43 bool ContentSettingMediaMenuModel::IsCommandIdEnabled(int command_id) const {
44 return true;
47 bool ContentSettingMediaMenuModel::GetAcceleratorForCommandId(
48 int command_id,
49 ui::Accelerator* accelerator) {
50 return false;
53 void ContentSettingMediaMenuModel::ExecuteCommand(int command_id,
54 int event_flags) {
55 CommandMap::const_iterator it = commands_.find(command_id);
56 DCHECK(it != commands_.end());
57 media_bubble_model_->OnMediaMenuClicked(type_, it->second.id);
59 if (!callback_.is_null())
60 callback_.Run(type_, it->second.name);