1 // Copyright 2018 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/media/unified_autoplay_config.h"
6 
7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/pref_names.h"
10 #include "components/content_settings/core/browser/host_content_settings_map.h"
11 #include "components/pref_registry/pref_registry_syncable.h"
12 #include "components/prefs/pref_service.h"
13 
14 // static
RegisterProfilePrefs(user_prefs::PrefRegistrySyncable * registry)15 void UnifiedAutoplayConfig::RegisterProfilePrefs(
16     user_prefs::PrefRegistrySyncable* registry) {
17   registry->RegisterBooleanPref(prefs::kBlockAutoplayEnabled, true);
18 }
19 
20 // static
ShouldBlockAutoplay(Profile * profile)21 bool UnifiedAutoplayConfig::ShouldBlockAutoplay(Profile* profile) {
22   return !IsBlockAutoplayUserModifiable(profile) ||
23          profile->GetPrefs()->GetBoolean(prefs::kBlockAutoplayEnabled);
24 }
25 
26 // static
IsBlockAutoplayUserModifiable(Profile * profile)27 bool UnifiedAutoplayConfig::IsBlockAutoplayUserModifiable(Profile* profile) {
28   HostContentSettingsMap* settings_map =
29       HostContentSettingsMapFactory::GetForProfile(profile);
30   return settings_map->GetDefaultContentSetting(
31              ContentSettingsType::SOUND, nullptr) != CONTENT_SETTING_BLOCK;
32 }
33