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

Unified Diff: chrome/browser/extensions/api/dial/dial_api.cc

Issue 2754703005: [Device Discovery] Make DialRegistry a Singleton (Closed)
Patch Set: fix mac and windows compile errors 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/dial/dial_api.cc
diff --git a/chrome/browser/extensions/api/dial/dial_api.cc b/chrome/browser/extensions/api/dial/dial_api.cc
index 415ae15dce5e13b6b05ebc49be296b64fb4c74cd..dd07c40724f2f2f52af8ac1fab79147dba3fd747 100644
--- a/chrome/browser/extensions/api/dial/dial_api.cc
+++ b/chrome/browser/extensions/api/dial/dial_api.cc
@@ -13,6 +13,7 @@
#include "base/time/time.h"
#include "chrome/browser/extensions/api/dial/dial_api_factory.h"
#include "chrome/browser/media/router/discovery/dial/device_description_fetcher.h"
+#include "chrome/browser/media/router/discovery/dial/dial_registry.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/dial.h"
#include "content/public/browser/browser_thread.h"
@@ -29,41 +30,34 @@ using media_router::DialRegistry;
namespace extensions {
-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
-
DialAPI::DialAPI(Profile* profile)
: RefcountedKeyedService(
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)),
- profile_(profile) {
+ profile_(profile),
+ dial_registry_(nullptr) {
EventRouter::Get(profile)->RegisterObserver(
this, api::dial::OnDeviceList::kEventName);
}
-DialAPI::~DialAPI() {}
+DialAPI::~DialAPI() {
+ // TODO(zhaobin): Call dial_registry_->UnregisterObserver() instead. In
+ // current implementation, UnregistryObserver() does not StopDiscovery() and
+ // causes crash in ~DialRegistry(). May keep a listener count and
+ // Register/UnregisterObserver as needed.
+ if (dial_registry_)
+ dial_registry_->StopPeriodicDiscovery();
+}
DialRegistry* DialAPI::dial_registry() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (!dial_registry_.get()) {
- dial_registry_.reset(new DialRegistry(
- TimeDelta::FromSeconds(kDialRefreshIntervalSecs),
- TimeDelta::FromSeconds(kDialExpirationSecs), kDialMaxDevices));
+ if (!dial_registry_) {
+ dial_registry_ = media_router::DialRegistry::GetInstance();
dial_registry_->RegisterObserver(this);
if (test_device_data_) {
dial_registry_->AddDeviceForTest(*test_device_data_);
}
}
- return dial_registry_.get();
+ return dial_registry_;
}
void DialAPI::OnListenerAdded(const EventListenerInfo& details) {
« no previous file with comments | « chrome/browser/extensions/api/dial/dial_api.h ('k') | chrome/browser/media/router/discovery/dial/dial_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698