Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: chrome/browser/media/router/discovery/dial/dial_registry_factory.cc

Issue 2754703005: [Device Discovery] Make DialRegistry a Singleton (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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/router/discovery/dial/dial_registry_factory.h"
6
7 #include "base/time/time.h"
8 #include "build/build_config.h"
9 #include "chrome/browser/media/router/discovery/dial/dial_registry.h"
10 #include "chrome/browser/profiles/incognito_helpers.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "components/keyed_service/content/browser_context_dependency_manager.h"
13
14 using content::BrowserContext;
15
16 namespace media_router {
17
18 namespace {
19
20 // How often to poll for devices.
21 const int kDialRefreshIntervalSecs = 120;
22
23 // We prune a device if it does not respond after this time.
24 const int kDialExpirationSecs = 240;
25
26 // The maximum number of devices retained at once in the registry.
27 const size_t kDialMaxDevices = 256;
28
29 } // namespace
30
31 // static
32 scoped_refptr<DialRegistry> DialRegistryFactory::GetForBrowserContext(
33 BrowserContext* context) {
34 DCHECK(context);
35 return static_cast<DialRegistry*>(
36 GetInstance()->GetServiceForBrowserContext(context, true).get());
37 }
38
39 // static
40 DialRegistryFactory* DialRegistryFactory::GetInstance() {
41 return base::Singleton<DialRegistryFactory>::get();
42 }
43
44 DialRegistryFactory::DialRegistryFactory()
45 : RefcountedBrowserContextKeyedServiceFactory(
46 "DialRegistry",
47 BrowserContextDependencyManager::GetInstance()) {}
48
49 DialRegistryFactory::~DialRegistryFactory() {}
50
51 content::BrowserContext* DialRegistryFactory::GetBrowserContextToUse(
52 content::BrowserContext* context) const {
53 return chrome::GetBrowserContextRedirectedInIncognito(context);
54 }
55
56 scoped_refptr<RefcountedKeyedService>
57 DialRegistryFactory::BuildServiceInstanceFor(BrowserContext* context) const {
58 return scoped_refptr<DialRegistry>(new DialRegistry(
59 base::TimeDelta::FromSeconds(kDialRefreshIntervalSecs),
60 base::TimeDelta::FromSeconds(kDialExpirationSecs), kDialMaxDevices));
61 }
62
63 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698