2016-12-03 11:12:48 +00:00
|
|
|
// Copyright 2013 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2018-10-19 18:51:43 +00:00
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/media/media_device_id_salt.h"
|
2016-12-03 11:12:48 +00:00
|
|
|
|
|
|
|
#include "components/prefs/pref_registry_simple.h"
|
|
|
|
#include "components/prefs/pref_service.h"
|
2017-08-04 21:15:28 +00:00
|
|
|
#include "content/public/browser/browser_context.h"
|
2016-12-03 11:12:48 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
|
|
|
|
using content::BrowserThread;
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2016-12-03 11:12:48 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-10-24 10:49:10 +00:00
|
|
|
const char kMediaDeviceIdSalt[] = "electron.media.device_id_salt";
|
2016-12-03 11:12:48 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
MediaDeviceIDSalt::MediaDeviceIDSalt(PrefService* pref_service) {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
|
|
|
|
media_device_id_salt_.Init(kMediaDeviceIdSalt, pref_service);
|
|
|
|
if (media_device_id_salt_.GetValue().empty()) {
|
|
|
|
media_device_id_salt_.SetValue(
|
2017-08-04 21:15:28 +00:00
|
|
|
content::BrowserContext::CreateRandomMediaDeviceIDSalt());
|
2016-12-03 11:12:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaDeviceIDSalt::~MediaDeviceIDSalt() {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
media_device_id_salt_.Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string MediaDeviceIDSalt::GetSalt() {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
return media_device_id_salt_.GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void MediaDeviceIDSalt::RegisterPrefs(PrefRegistrySimple* registry) {
|
|
|
|
registry->RegisterStringPref(kMediaDeviceIdSalt, std::string());
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void MediaDeviceIDSalt::Reset(PrefService* pref_service) {
|
|
|
|
pref_service->SetString(
|
|
|
|
kMediaDeviceIdSalt,
|
2017-08-04 21:15:28 +00:00
|
|
|
content::BrowserContext::CreateRandomMediaDeviceIDSalt());
|
2016-12-03 11:12:48 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|