OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/dial/dial_api.h" | 5 #include "chrome/browser/extensions/api/dial/dial_api.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "chrome/browser/extensions/api/dial/dial_api_factory.h" | 10 #include "chrome/browser/extensions/api/dial/dial_api_factory.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 // How often to poll for devices. | 25 // How often to poll for devices. |
26 const int kDialRefreshIntervalSecs = 120; | 26 const int kDialRefreshIntervalSecs = 120; |
27 | 27 |
28 // We prune a device if it does not respond after this time. | 28 // We prune a device if it does not respond after this time. |
29 const int kDialExpirationSecs = 240; | 29 const int kDialExpirationSecs = 240; |
30 | 30 |
31 // The maximum number of devices retained at once in the registry. | 31 // The maximum number of devices retained at once in the registry. |
32 const size_t kDialMaxDevices = 256; | 32 const size_t kDialMaxDevices = 256; |
33 | 33 |
34 // | |
35 const char kCastDefaultDeviceType[] = "_privet._tcp.local"; | |
mark a. foltz
2013/08/19 18:25:26
_googlecast._tcp
| |
36 | |
34 } // namespace | 37 } // namespace |
35 | 38 |
36 namespace extensions { | 39 namespace extensions { |
37 | 40 |
38 DialAPI::DialAPI(Profile* profile) | 41 DialAPI::DialAPI(Profile* profile) |
39 : RefcountedBrowserContextKeyedService(BrowserThread::IO), | 42 : RefcountedBrowserContextKeyedService(BrowserThread::IO), |
40 profile_(profile) { | 43 profile_(profile) { |
41 ExtensionSystem::Get(profile)->event_router()->RegisterObserver( | 44 ExtensionSystem::Get(profile)->event_router()->RegisterObserver( |
42 this, extensions::event_names::kOnDialDeviceList); | 45 this, extensions::event_names::kOnDialDeviceList); |
43 } | 46 } |
44 | 47 |
45 DialAPI::~DialAPI() {} | 48 DialAPI::~DialAPI() {} |
46 | 49 |
47 DialRegistry* DialAPI::dial_registry() { | 50 DialRegistry* DialAPI::dial_registry() { |
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
49 if (!dial_registry_.get()) { | 52 if (!dial_registry_.get()) { |
50 dial_registry_.reset(new DialRegistry(this, | 53 dial_registry_.reset(new DialRegistry(this, |
51 TimeDelta::FromSeconds(kDialRefreshIntervalSecs), | 54 TimeDelta::FromSeconds(kDialRefreshIntervalSecs), |
52 TimeDelta::FromSeconds(kDialExpirationSecs), | 55 TimeDelta::FromSeconds(kDialExpirationSecs), |
53 kDialMaxDevices)); | 56 kDialMaxDevices)); |
54 } | 57 } |
55 return dial_registry_.get(); | 58 return dial_registry_.get(); |
56 } | 59 } |
57 | 60 |
61 MDNSService* DialAPI::mdns_service() { | |
62 // TODO(justinlin): Any creation/access thread constraints? | |
mark a. foltz
2013/08/19 18:25:26
I think this should be fine, the host side of the
| |
63 // DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
64 if (!mdns_service_.get()) { | |
65 mdns_service_.reset(new MDNSService(kCastDefaultDeviceType)); | |
66 } | |
67 return mdns_service_.get(); | |
68 } | |
69 | |
58 void DialAPI::OnListenerAdded(const EventListenerInfo& details) { | 70 void DialAPI::OnListenerAdded(const EventListenerInfo& details) { |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
60 BrowserThread::PostTask( | 72 BrowserThread::PostTask( |
61 BrowserThread::IO, FROM_HERE, | 73 BrowserThread::IO, FROM_HERE, |
62 base::Bind(&DialAPI::NotifyListenerAddedOnIOThread, this)); | 74 base::Bind(&DialAPI::NotifyListenerAddedOnIOThread, this)); |
63 } | 75 } |
64 | 76 |
65 void DialAPI::OnListenerRemoved(const EventListenerInfo& details) { | 77 void DialAPI::OnListenerRemoved(const EventListenerInfo& details) { |
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
67 BrowserThread::PostTask( | 79 BrowserThread::PostTask( |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 | 176 |
165 bool DialDiscoverNowFunction::Respond() { | 177 bool DialDiscoverNowFunction::Respond() { |
166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
167 if (!result_) | 179 if (!result_) |
168 error_ = kDialServiceError; | 180 error_ = kDialServiceError; |
169 | 181 |
170 SetResult(new base::FundamentalValue(result_)); | 182 SetResult(new base::FundamentalValue(result_)); |
171 return true; | 183 return true; |
172 } | 184 } |
173 | 185 |
186 | |
187 DialGetNetworkServicesFunction::DialGetNetworkServicesFunction() | |
188 : dial_(NULL), result_(false) { | |
189 } | |
190 | |
191 bool DialGetNetworkServicesFunction::Prepare() { | |
192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
193 DCHECK(profile()); | |
194 dial_ = DialAPIFactory::GetInstance()->GetForProfile(profile()).get(); | |
195 return true; | |
196 } | |
197 | |
198 void DialGetNetworkServicesFunction::Work() { | |
199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
mark a. foltz
2013/08/19 18:25:26
I think this should be okay to be a synchronous fu
| |
200 // TODO(justinlin): Should instead instantiate a NetworkServicesRegistry, | |
201 // which calls into MDNSService. | |
202 result_ = dial_->mdns_service()->Start(); | |
203 } | |
204 | |
205 bool DialGetNetworkServicesFunction::Respond() { | |
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
207 if (!result_) | |
208 error_ = kDialServiceError; | |
209 | |
210 SetResult(new base::FundamentalValue(result_)); | |
211 return true; | |
212 } | |
213 | |
174 } // namespace api | 214 } // namespace api |
175 | 215 |
176 } // namespace extensions | 216 } // namespace extensions |
OLD | NEW |