| Index: chrome/browser/media/router/discovery/dial/dial_registry_factory.cc
|
| diff --git a/chrome/browser/media/router/discovery/dial/dial_registry_factory.cc b/chrome/browser/media/router/discovery/dial/dial_registry_factory.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..42ca92023b9171f3ca0fb8a476344254fc1ff442
|
| --- /dev/null
|
| +++ b/chrome/browser/media/router/discovery/dial/dial_registry_factory.cc
|
| @@ -0,0 +1,63 @@
|
| +// Copyright 2017 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 "chrome/browser/media/router/discovery/dial/dial_registry_factory.h"
|
| +
|
| +#include "base/time/time.h"
|
| +#include "build/build_config.h"
|
| +#include "chrome/browser/media/router/discovery/dial/dial_registry.h"
|
| +#include "chrome/browser/profiles/incognito_helpers.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "components/keyed_service/content/browser_context_dependency_manager.h"
|
| +
|
| +using content::BrowserContext;
|
| +
|
| +namespace media_router {
|
| +
|
| +namespace {
|
| +
|
| +// How often to poll for devices.
|
| +const int kDialRefreshIntervalSecs = 120;
|
| +
|
| +// We prune a device if it does not respond after this time.
|
| +const int kDialExpirationSecs = 240;
|
| +
|
| +// The maximum number of devices retained at once in the registry.
|
| +const size_t kDialMaxDevices = 256;
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +scoped_refptr<DialRegistry> DialRegistryFactory::GetForBrowserContext(
|
| + BrowserContext* context) {
|
| + DCHECK(context);
|
| + return static_cast<DialRegistry*>(
|
| + GetInstance()->GetServiceForBrowserContext(context, true).get());
|
| +}
|
| +
|
| +// static
|
| +DialRegistryFactory* DialRegistryFactory::GetInstance() {
|
| + return base::Singleton<DialRegistryFactory>::get();
|
| +}
|
| +
|
| +DialRegistryFactory::DialRegistryFactory()
|
| + : RefcountedBrowserContextKeyedServiceFactory(
|
| + "DialRegistry",
|
| + BrowserContextDependencyManager::GetInstance()) {}
|
| +
|
| +DialRegistryFactory::~DialRegistryFactory() {}
|
| +
|
| +content::BrowserContext* DialRegistryFactory::GetBrowserContextToUse(
|
| + content::BrowserContext* context) const {
|
| + return chrome::GetBrowserContextRedirectedInIncognito(context);
|
| +}
|
| +
|
| +scoped_refptr<RefcountedKeyedService>
|
| +DialRegistryFactory::BuildServiceInstanceFor(BrowserContext* context) const {
|
| + return scoped_refptr<DialRegistry>(new DialRegistry(
|
| + base::TimeDelta::FromSeconds(kDialRefreshIntervalSecs),
|
| + base::TimeDelta::FromSeconds(kDialExpirationSecs), kDialMaxDevices));
|
| +}
|
| +
|
| +} // namespace media_router
|
|
|