persist media device id salt across sessions
This commit is contained in:
parent
ba6f1f5443
commit
dbf4e52e05
6 changed files with 120 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "browser/browser_context.h"
|
||||
|
||||
#include "browser/media/media_device_id_salt.h"
|
||||
#include "browser/brightray_paths.h"
|
||||
#include "browser/browser_client.h"
|
||||
#include "browser/inspectable_web_contents_impl.h"
|
||||
|
@ -56,6 +57,13 @@ class BrowserContext::ResourceContext : public content::ResourceContext {
|
|||
return getter_->GetURLRequestContext();
|
||||
}
|
||||
|
||||
std::string GetMediaDeviceIDSalt() override {
|
||||
auto media_device_id_salt_ = getter_->GetMediaDeviceIDSalt();
|
||||
if (media_device_id_salt_)
|
||||
return media_device_id_salt_->GetSalt();
|
||||
return content::ResourceContext::GetMediaDeviceIDSalt();
|
||||
}
|
||||
|
||||
URLRequestContextGetter* getter_;
|
||||
};
|
||||
|
||||
|
@ -114,6 +122,7 @@ void BrowserContext::InitPrefs() {
|
|||
|
||||
void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) {
|
||||
InspectableWebContentsImpl::RegisterPrefs(registry);
|
||||
MediaDeviceIDSalt::RegisterPrefs(registry);
|
||||
}
|
||||
|
||||
URLRequestContextGetter* BrowserContext::GetRequestContext() {
|
||||
|
@ -143,6 +152,14 @@ net::NetworkDelegate* BrowserContext::CreateNetworkDelegate() {
|
|||
return new NetworkDelegate;
|
||||
}
|
||||
|
||||
MediaDeviceIDSalt* BrowserContext::GetMediaDeviceIDSalt() {
|
||||
if (IsOffTheRecord())
|
||||
return nullptr;
|
||||
if (!media_device_id_salt_.get())
|
||||
media_device_id_salt_.reset(new MediaDeviceIDSalt(prefs_.get()));
|
||||
return media_device_id_salt_.get();
|
||||
}
|
||||
|
||||
base::FilePath BrowserContext::GetPath() const {
|
||||
return path_;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ class SpecialStoragePolicy;
|
|||
|
||||
namespace brightray {
|
||||
|
||||
class MediaDeviceIDSalt;
|
||||
class PermissionManager;
|
||||
|
||||
class BrowserContext : public base::RefCounted<BrowserContext>,
|
||||
|
@ -87,6 +88,7 @@ class BrowserContext : public base::RefCounted<BrowserContext>,
|
|||
|
||||
// URLRequestContextGetter::Delegate:
|
||||
net::NetworkDelegate* CreateNetworkDelegate() override;
|
||||
MediaDeviceIDSalt* GetMediaDeviceIDSalt() override;
|
||||
|
||||
base::FilePath GetPath() const override;
|
||||
|
||||
|
@ -128,6 +130,7 @@ class BrowserContext : public base::RefCounted<BrowserContext>,
|
|||
scoped_refptr<storage::SpecialStoragePolicy> storage_policy_;
|
||||
std::unique_ptr<PrefService> prefs_;
|
||||
std::unique_ptr<PermissionManager> permission_manager_;
|
||||
std::unique_ptr<MediaDeviceIDSalt> media_device_id_salt_;
|
||||
|
||||
base::WeakPtrFactory<BrowserContext> weak_factory_;
|
||||
|
||||
|
|
53
brightray/browser/media/media_device_id_salt.cc
Normal file
53
brightray/browser/media/media_device_id_salt.cc
Normal file
|
@ -0,0 +1,53 @@
|
|||
// 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.
|
||||
#include "browser/media/media_device_id_salt.h"
|
||||
|
||||
#include "components/prefs/pref_registry_simple.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/resource_context.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace brightray {
|
||||
|
||||
namespace {
|
||||
|
||||
const char kMediaDeviceIdSalt[] = "brightray.media.device_id_salt";
|
||||
|
||||
} // 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(
|
||||
content::ResourceContext::CreateRandomMediaDeviceIDSalt());
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
content::ResourceContext::CreateRandomMediaDeviceIDSalt());
|
||||
}
|
||||
|
||||
} // namespace brightray
|
40
brightray/browser/media/media_device_id_salt.h
Normal file
40
brightray/browser/media/media_device_id_salt.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
// 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.
|
||||
|
||||
#ifndef BRIGHTRAY_BROWSER_MEDIA_MEDIA_DEVICE_ID_SALT_H_
|
||||
#define BRIGHTRAY_BROWSER_MEDIA_MEDIA_DEVICE_ID_SALT_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "components/prefs/pref_member.h"
|
||||
|
||||
class PrefRegistrySimple;
|
||||
class PrefService;
|
||||
|
||||
namespace brightray {
|
||||
|
||||
// MediaDeviceIDSalt is responsible for creating and retrieving a salt string
|
||||
// that is used for creating MediaSource IDs that can be cached by a web
|
||||
// service. If the cache is cleared, the MediaSourceIds are invalidated.
|
||||
class MediaDeviceIDSalt {
|
||||
public:
|
||||
explicit MediaDeviceIDSalt(PrefService* pref_service);
|
||||
~MediaDeviceIDSalt();
|
||||
|
||||
std::string GetSalt();
|
||||
|
||||
static void RegisterPrefs(PrefRegistrySimple* pref_registry);
|
||||
static void Reset(PrefService* pref_service);
|
||||
|
||||
private:
|
||||
StringPrefMember media_device_id_salt_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(MediaDeviceIDSalt);
|
||||
};
|
||||
|
||||
} // namespace brightray
|
||||
|
||||
#endif // BRIGHTRAY_BROWSER_MEDIA_MEDIA_DEVICE_ID_SALT_H_
|
|
@ -31,6 +31,7 @@ class URLRequestJobFactory;
|
|||
namespace brightray {
|
||||
|
||||
class DevToolsNetworkControllerHandle;
|
||||
class MediaDeviceIDSalt;
|
||||
class NetLog;
|
||||
|
||||
class URLRequestContextGetter : public net::URLRequestContextGetter {
|
||||
|
@ -57,6 +58,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
|
|||
GetRequireCTDelegate() {
|
||||
return nullptr;
|
||||
}
|
||||
virtual MediaDeviceIDSalt* GetMediaDeviceIDSalt() { return nullptr; }
|
||||
};
|
||||
|
||||
URLRequestContextGetter(
|
||||
|
@ -77,6 +79,9 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
|
|||
|
||||
net::HostResolver* host_resolver();
|
||||
net::URLRequestJobFactory* job_factory() const { return job_factory_; }
|
||||
MediaDeviceIDSalt* GetMediaDeviceIDSalt() const {
|
||||
return delegate_->GetMediaDeviceIDSalt();
|
||||
}
|
||||
|
||||
private:
|
||||
Delegate* delegate_;
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
'browser/mac/notification_presenter_mac.mm',
|
||||
'browser/media/media_capture_devices_dispatcher.cc',
|
||||
'browser/media/media_capture_devices_dispatcher.h',
|
||||
'browser/media/media_device_id_salt.cc',
|
||||
'browser/media/media_device_id_salt.h',
|
||||
'browser/media/media_stream_devices_controller.cc',
|
||||
'browser/media/media_stream_devices_controller.h',
|
||||
'browser/net/devtools_network_conditions.cc',
|
||||
|
|
Loading…
Reference in a new issue