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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 78 |
78 void DialRegistry::OnListenerRemoved() { | 79 void DialRegistry::OnListenerRemoved() { |
79 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 80 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
80 DCHECK_GT(num_listeners_, 0); | 81 DCHECK_GT(num_listeners_, 0); |
81 if (--num_listeners_ == 0) { | 82 if (--num_listeners_ == 0) { |
82 VLOG(2) << "Listeners removed; stopping periodic discovery."; | 83 VLOG(2) << "Listeners removed; stopping periodic discovery."; |
83 StopPeriodicDiscovery(); | 84 StopPeriodicDiscovery(); |
84 } | 85 } |
85 } | 86 } |
86 | 87 |
| 88 GURL DialRegistry::GetDeviceDescriptionURL(const std::string& label) const { |
| 89 const auto device_it = device_by_label_map_.find(label); |
| 90 if (device_it != device_by_label_map_.end()) |
| 91 return device_it->second->device_description_url(); |
| 92 |
| 93 return GURL(); |
| 94 } |
| 95 |
| 96 void DialRegistry::AddDeviceForTest(const DialDeviceData& device_data) { |
| 97 std::unique_ptr<DialDeviceData> test_data = |
| 98 base::MakeUnique<DialDeviceData>(device_data); |
| 99 device_by_label_map_.insert( |
| 100 std::make_pair(device_data.label(), test_data.get())); |
| 101 device_by_id_map_.insert( |
| 102 std::make_pair(device_data.device_id(), std::move(test_data))); |
| 103 } |
| 104 |
87 bool DialRegistry::ReadyToDiscover() { | 105 bool DialRegistry::ReadyToDiscover() { |
88 if (num_listeners_ == 0) { | 106 if (num_listeners_ == 0) { |
89 dial_api_->OnDialError(DIAL_NO_LISTENERS); | 107 dial_api_->OnDialError(DIAL_NO_LISTENERS); |
90 return false; | 108 return false; |
91 } | 109 } |
92 if (NetworkChangeNotifier::IsOffline()) { | 110 if (NetworkChangeNotifier::IsOffline()) { |
93 dial_api_->OnDialError(DIAL_NETWORK_DISCONNECTED); | 111 dial_api_->OnDialError(DIAL_NETWORK_DISCONNECTED); |
94 return false; | 112 return false; |
95 } | 113 } |
96 if (NetworkChangeNotifier::IsConnectionCellular( | 114 if (NetworkChangeNotifier::IsConnectionCellular( |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 VLOG(2) << "Connection detected, restarting discovery."; | 350 VLOG(2) << "Connection detected, restarting discovery."; |
333 StartPeriodicDiscovery(); | 351 StartPeriodicDiscovery(); |
334 } | 352 } |
335 break; | 353 break; |
336 } | 354 } |
337 } | 355 } |
338 | 356 |
339 } // namespace dial | 357 } // namespace dial |
340 } // namespace api | 358 } // namespace api |
341 } // namespace extensions | 359 } // namespace extensions |
OLD | NEW |