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

Side by Side Diff: chrome/browser/extensions/api/dial/dial_api.h

Issue 2750453002: Add DiscoveryNetworkMonitor implementation (Closed)
Patch Set: Respond to mfoltz' comments, add chrome.dial API back with tests Created 3 years, 8 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
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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "chrome/browser/extensions/api/dial/dial_device_data.h" 11 #include "chrome/browser/extensions/api/dial/dial_device_data.h"
12 #include "chrome/browser/extensions/api/dial/dial_registry.h" 12 #include "chrome/browser/extensions/api/dial/dial_registry.h"
13 #include "chrome/browser/media/router/discovery/discovery_network_monitor.h"
13 #include "chrome/common/extensions/api/dial.h" 14 #include "chrome/common/extensions/api/dial.h"
14 #include "components/keyed_service/core/refcounted_keyed_service.h" 15 #include "components/keyed_service/core/refcounted_keyed_service.h"
15 #include "extensions/browser/api/async_api_function.h" 16 #include "extensions/browser/api/async_api_function.h"
16 #include "extensions/browser/event_router.h" 17 #include "extensions/browser/event_router.h"
17 18
18 namespace extensions { 19 namespace extensions {
19 20
20 namespace api { 21 namespace api {
21 namespace dial { 22 namespace dial {
22 class DeviceDescriptionFetcher; 23 class DeviceDescriptionFetcher;
(...skipping 16 matching lines...) Expand all
39 // here. This would also allow a straightforward GetDeviceList implementation 40 // here. This would also allow a straightforward GetDeviceList implementation
40 // (crbug.com/576817), cleanup some long-tail crashes (crbug.com/640011) that 41 // (crbug.com/576817), cleanup some long-tail crashes (crbug.com/640011) that
41 // are likely due to lifetime issues, and simplify unit tests 42 // are likely due to lifetime issues, and simplify unit tests
42 // (crbug.com/661457). 43 // (crbug.com/661457).
43 // 44 //
44 // Also, DialRegistry should be an interface that can be mocked and injected for 45 // Also, DialRegistry should be an interface that can be mocked and injected for
45 // tests; this would allow us to remove code that injects test data into the 46 // tests; this would allow us to remove code that injects test data into the
46 // real DialRegsitry. 47 // real DialRegsitry.
47 class DialAPI : public RefcountedKeyedService, 48 class DialAPI : public RefcountedKeyedService,
48 public EventRouter::Observer, 49 public EventRouter::Observer,
49 public api::dial::DialRegistry::Observer { 50 public api::dial::DialRegistry::Observer,
51 public DiscoveryNetworkMonitor::Observer {
mark a. foltz 2017/04/26 22:25:11 I'd put the extensions API changes in a separate p
btolsch 2017/05/03 22:03:09 Done.
50 public: 52 public:
51 explicit DialAPI(Profile* profile); 53 explicit DialAPI(Profile* profile);
52 54
53 // The DialRegistry for the API. This must always be used only from the IO 55 // The DialRegistry for the API. This must always be used only from the IO
54 // thread. 56 // thread.
55 api::dial::DialRegistry* dial_registry(); 57 api::dial::DialRegistry* dial_registry();
56 58
57 // Called by the DialRegistry on the IO thread so that the DialAPI dispatches 59 // Called by the DialRegistry on the IO thread so that the DialAPI dispatches
58 // the event to listeners on the UI thread. 60 // the event to listeners on the UI thread.
59 void SendEventOnUIThread(const api::dial::DialRegistry::DeviceList& devices); 61 void SendEventOnUIThread(const api::dial::DialRegistry::DeviceList& devices);
(...skipping 14 matching lines...) Expand all
74 76
75 // EventRouter::Observer: 77 // EventRouter::Observer:
76 void OnListenerAdded(const EventListenerInfo& details) override; 78 void OnListenerAdded(const EventListenerInfo& details) override;
77 void OnListenerRemoved(const EventListenerInfo& details) override; 79 void OnListenerRemoved(const EventListenerInfo& details) override;
78 80
79 // DialRegistry::Observer: 81 // DialRegistry::Observer:
80 void OnDialDeviceEvent( 82 void OnDialDeviceEvent(
81 const api::dial::DialRegistry::DeviceList& devices) override; 83 const api::dial::DialRegistry::DeviceList& devices) override;
82 void OnDialError(api::dial::DialRegistry::DialErrorCode type) override; 84 void OnDialError(api::dial::DialRegistry::DialErrorCode type) override;
83 85
86 // DiscoveryNetworkMonitor::Observer:
87 void OnNetworksChanged(const DiscoveryNetworkMonitor& manager) override;
88
89 void SendNetworkIdChangedOnUIThread(const std::string& network_id);
90
91 void NetworkIdListenerAddedOnIOThread();
92 void NetworkIdListenerRemovedOnIOThread();
93
84 // Methods to notify the DialRegistry on the correct thread of new/removed 94 // Methods to notify the DialRegistry on the correct thread of new/removed
85 // listeners. 95 // listeners.
86 void NotifyListenerAddedOnIOThread(); 96 void NotifyListenerAddedOnIOThread();
87 void NotifyListenerRemovedOnIOThread(); 97 void NotifyListenerRemovedOnIOThread();
88 98
89 Profile* profile_; 99 Profile* profile_;
90 100
91 // Created lazily on first access on the IO thread. 101 // Created lazily on first access on the IO thread.
92 std::unique_ptr<api::dial::DialRegistry> dial_registry_; 102 std::unique_ptr<api::dial::DialRegistry> dial_registry_;
93 103
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 160
151 std::unique_ptr<api::dial::FetchDeviceDescription::Params> params_; 161 std::unique_ptr<api::dial::FetchDeviceDescription::Params> params_;
152 std::unique_ptr<api::dial::DeviceDescriptionFetcher> 162 std::unique_ptr<api::dial::DeviceDescriptionFetcher>
153 device_description_fetcher_; 163 device_description_fetcher_;
154 164
155 DialAPI* dial_; 165 DialAPI* dial_;
156 166
157 DISALLOW_COPY_AND_ASSIGN(DialFetchDeviceDescriptionFunction); 167 DISALLOW_COPY_AND_ASSIGN(DialFetchDeviceDescriptionFunction);
158 }; 168 };
159 169
170 class DialGetNetworkIdFunction : public AsyncExtensionFunction {
171 public:
172 DialGetNetworkIdFunction();
173
174 protected:
175 ~DialGetNetworkIdFunction() override;
176
177 // AsyncExtensionFunction:
178 bool RunAsync() override;
179
180 private:
181 DECLARE_EXTENSION_FUNCTION("dial.getNetworkId", DIAL_GETNETWORKID)
182
183 void GetNetworkIdOnIOThread();
184 void NetworkInfoReadyCallback();
mark a. foltz 2017/04/26 22:25:11 OnNetworkInfoReady
btolsch 2017/05/03 22:03:09 Done.
185
186 DISALLOW_COPY_AND_ASSIGN(DialGetNetworkIdFunction);
187 };
188
160 } // namespace extensions 189 } // namespace extensions
161 190
162 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ 191 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/dial/dial_api.cc » ('j') | chrome/browser/extensions/api/dial/dial_api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698