Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h" | |
| 6 | |
| 7 #include "base/utf_string_conversions.h" | |
| 8 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | |
| 9 #include "chrome/browser/prefs/pref_service.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | |
| 12 #include "chrome/common/pref_names.h" | |
| 13 | |
| 14 ContentSettingMediaMenuModel::ContentSettingMediaMenuModel( | |
| 15 Profile* profile, | |
| 16 content::MediaStreamType type, | |
| 17 ContentSettingBubbleModel* bubble_model, | |
| 18 const MenuLabelChangedCallback& callback) | |
| 19 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | |
| 20 profile_(profile), | |
|
Peter Kasting
2013/02/06 22:11:18
You shouldn't be taking a Profile* when you depend
no longer working on chromium
2013/02/07 16:25:19
Done.
| |
| 21 type_(type), | |
| 22 media_bubble_model_(bubble_model), | |
| 23 callback_(callback) { | |
| 24 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM, | |
| 25 media_bubble_model_->content_type()); | |
| 26 BuildMenu(); | |
| 27 } | |
| 28 | |
| 29 ContentSettingMediaMenuModel::~ContentSettingMediaMenuModel() { | |
| 30 } | |
| 31 | |
| 32 bool ContentSettingMediaMenuModel::IsCommandIdChecked(int command_id) const { | |
| 33 return false; | |
| 34 } | |
| 35 | |
| 36 bool ContentSettingMediaMenuModel::IsCommandIdEnabled(int command_id) const { | |
| 37 return true; | |
| 38 } | |
| 39 | |
| 40 bool ContentSettingMediaMenuModel::GetAcceleratorForCommandId( | |
| 41 int command_id, | |
| 42 ui::Accelerator* accelerator) { | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 void ContentSettingMediaMenuModel::ExecuteCommand(int command_id) { | |
| 47 CommandMap::const_iterator it = commands_.find(command_id); | |
| 48 DCHECK(it != commands_.end()); | |
| 49 media_bubble_model_->OnMediaMenuClicked(type_, it->second.id); | |
| 50 | |
| 51 if (!callback_.is_null()) | |
| 52 callback_.Run(type_, it->second.name); | |
| 53 } | |
| 54 | |
| 55 void ContentSettingMediaMenuModel::BuildMenu() { | |
| 56 PrefService* prefs = profile_->GetPrefs(); | |
| 57 MediaCaptureDevicesDispatcher* dispatcher = | |
| 58 MediaCaptureDevicesDispatcher::GetInstance(); | |
| 59 content::MediaStreamDevices devices; | |
| 60 std::string default_device; | |
| 61 if (type_ == content::MEDIA_DEVICE_AUDIO_CAPTURE) { | |
| 62 devices = dispatcher->GetAudioCaptureDevices(); | |
| 63 default_device = prefs->GetString(prefs::kDefaultAudioCaptureDevice); | |
| 64 } else if (type_ == content::MEDIA_DEVICE_VIDEO_CAPTURE) { | |
| 65 devices = dispatcher->GetVideoCaptureDevices(); | |
| 66 default_device = prefs->GetString(prefs::kDefaultVideoCaptureDevice); | |
| 67 } else { | |
| 68 NOTREACHED(); | |
|
Peter Kasting
2013/02/06 22:11:18
Nit: Simpler:
if (type_ == content::MEDIA_DEVIC
no longer working on chromium
2013/02/07 16:25:19
Done.
no longer working on chromium
2013/02/07 16:25:19
Done, I moved the DCHECK to the constructor.
| |
| 69 } | |
| 70 | |
| 71 for (size_t i = 0; i < devices.size(); ++i) { | |
| 72 int command_id = commands_.size(); | |
|
Peter Kasting
2013/02/06 22:11:18
Nit: Inline into next statement
no longer working on chromium
2013/02/07 16:25:19
Done.
| |
| 73 commands_.insert(std::make_pair(command_id, devices[i])); | |
| 74 AddItem(i, UTF8ToUTF16(devices[i].name)); | |
| 75 } | |
| 76 } | |
| OLD | NEW |