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_registry.h" | 5 #include "chrome/browser/extensions/api/dial/dial_registry.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/extensions/api/dial/dial_api.h" | 16 #include "chrome/browser/extensions/api/dial/dial_api.h" |
16 #include "chrome/browser/extensions/api/dial/dial_device_data.h" | 17 #include "chrome/browser/extensions/api/dial/dial_device_data.h" |
17 #include "chrome/browser/extensions/api/dial/dial_service.h" | 18 #include "chrome/browser/extensions/api/dial/dial_service.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 76 |
76 void DialRegistry::OnListenerRemoved() { | 77 void DialRegistry::OnListenerRemoved() { |
77 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 78 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
78 DCHECK_GT(num_listeners_, 0); | 79 DCHECK_GT(num_listeners_, 0); |
79 if (--num_listeners_ == 0) { | 80 if (--num_listeners_ == 0) { |
80 VLOG(2) << "Listeners removed; stopping periodic discovery."; | 81 VLOG(2) << "Listeners removed; stopping periodic discovery."; |
81 StopPeriodicDiscovery(); | 82 StopPeriodicDiscovery(); |
82 } | 83 } |
83 } | 84 } |
84 | 85 |
| 86 GURL DialRegistry::GetDeviceDescriptionURL(const std::string& label) const { |
| 87 const auto device_it = device_by_label_map_.find(label); |
| 88 if (device_it != device_by_label_map_.end()) |
| 89 return device_it->second->device_description_url(); |
| 90 |
| 91 return GURL(); |
| 92 } |
| 93 |
| 94 void DialRegistry::AddDeviceForTest(const DialDeviceData& device_data) { |
| 95 std::unique_ptr<DialDeviceData> test_data = |
| 96 base::MakeUnique<DialDeviceData>(device_data); |
| 97 device_by_label_map_.insert( |
| 98 std::make_pair(device_data.label(), test_data.get())); |
| 99 device_by_id_map_.insert( |
| 100 std::make_pair(device_data.device_id(), std::move(test_data))); |
| 101 } |
| 102 |
85 bool DialRegistry::ReadyToDiscover() { | 103 bool DialRegistry::ReadyToDiscover() { |
86 if (num_listeners_ == 0) { | 104 if (num_listeners_ == 0) { |
87 dial_api_->OnDialError(DIAL_NO_LISTENERS); | 105 dial_api_->OnDialError(DIAL_NO_LISTENERS); |
88 return false; | 106 return false; |
89 } | 107 } |
90 if (NetworkChangeNotifier::IsOffline()) { | 108 if (NetworkChangeNotifier::IsOffline()) { |
91 dial_api_->OnDialError(DIAL_NETWORK_DISCONNECTED); | 109 dial_api_->OnDialError(DIAL_NETWORK_DISCONNECTED); |
92 return false; | 110 return false; |
93 } | 111 } |
94 if (NetworkChangeNotifier::IsConnectionCellular( | 112 if (NetworkChangeNotifier::IsConnectionCellular( |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 case NetworkChangeNotifier::CONNECTION_BLUETOOTH: | 346 case NetworkChangeNotifier::CONNECTION_BLUETOOTH: |
329 if (!dial_) { | 347 if (!dial_) { |
330 VLOG(2) << "Connection detected, restarting discovery."; | 348 VLOG(2) << "Connection detected, restarting discovery."; |
331 StartPeriodicDiscovery(); | 349 StartPeriodicDiscovery(); |
332 } | 350 } |
333 break; | 351 break; |
334 } | 352 } |
335 } | 353 } |
336 | 354 |
337 } // namespace extensions | 355 } // namespace extensions |
OLD | NEW |