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

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

Issue 2754703005: [Device Discovery] Make DialRegistry a Singleton (Closed)
Patch Set: 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 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"
(...skipping 14 matching lines...) Expand all
25 25
26 // Dial API which is a ref-counted KeyedService that manages 26 // Dial API which is a ref-counted KeyedService that manages
27 // the DIAL registry. It takes care of creating the registry on the IO thread 27 // the DIAL registry. It takes care of creating the registry on the IO thread
28 // and is an observer of the registry. It makes sure devices events are sent out 28 // and is an observer of the registry. It makes sure devices events are sent out
29 // to extension listeners on the right thread. 29 // to extension listeners on the right thread.
30 // 30 //
31 // TODO(mfoltz): This should probably inherit from BrowserContextKeyedAPI 31 // TODO(mfoltz): This should probably inherit from BrowserContextKeyedAPI
32 // instead; ShutdownOnUIThread below is a no-op, which is the whole point of 32 // instead; ShutdownOnUIThread below is a no-op, which is the whole point of
33 // RefcountedKeyedService. 33 // RefcountedKeyedService.
34 // 34 //
35 // TODO(mfoltz): The threading model for this API needs to be rethought. At a 35 // TODO(mfoltz): The threading model for this API needs to be rethought. At a
mark a. foltz 2017/03/18 18:04:58 Since the DialRegistry is going to now be shared a
36 // minimum, DialRegistry should move to the UI thread to avoid extra thread hops 36 // minimum, DialRegistry should move to the UI thread to avoid extra thread hops
37 // here. This would also allow a straightforward GetDeviceList implementation 37 // here. This would also allow a straightforward GetDeviceList implementation
38 // (crbug.com/576817), cleanup some long-tail crashes (crbug.com/640011) that 38 // (crbug.com/576817), cleanup some long-tail crashes (crbug.com/640011) that
39 // are likely due to lifetime issues, and simplify unit tests 39 // are likely due to lifetime issues, and simplify unit tests
40 // (crbug.com/661457). 40 // (crbug.com/661457).
41 // 41 //
42 // Also, DialRegistry should be an interface that can be mocked and injected for 42 // Also, DialRegistry should be an interface that can be mocked and injected for
43 // tests; this would allow us to remove code that injects test data into the 43 // tests; this would allow us to remove code that injects test data into the
44 // real DialRegsitry. 44 // real DialRegsitry.
45 class DialAPI : public RefcountedKeyedService, 45 class DialAPI : public RefcountedKeyedService,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // listeners. 85 // listeners.
86 void NotifyListenerAddedOnIOThread(); 86 void NotifyListenerAddedOnIOThread();
87 void NotifyListenerRemovedOnIOThread(); 87 void NotifyListenerRemovedOnIOThread();
88 88
89 // Fills the |device| API struct from |device_data|. 89 // Fills the |device| API struct from |device_data|.
90 void FillDialDevice(const media_router::DialDeviceData& device_data, 90 void FillDialDevice(const media_router::DialDeviceData& device_data,
91 api::dial::DialDevice* device) const; 91 api::dial::DialDevice* device) const;
92 92
93 Profile* profile_; 93 Profile* profile_;
94 94
95 // Created lazily on first access on the IO thread. 95 // Created lazily on first access on the IO thread. Does not take ownership of
96 std::unique_ptr<media_router::DialRegistry> dial_registry_; 96 // |dial_registry_|.
97 scoped_refptr<media_router::DialRegistry> dial_registry_;
97 98
98 // Device data for testing. 99 // Device data for testing.
99 std::unique_ptr<media_router::DialDeviceData> test_device_data_; 100 std::unique_ptr<media_router::DialDeviceData> test_device_data_;
100 std::unique_ptr<media_router::DialDeviceDescriptionData> 101 std::unique_ptr<media_router::DialDeviceDescriptionData>
101 test_device_description_; 102 test_device_description_;
102 103
103 DISALLOW_COPY_AND_ASSIGN(DialAPI); 104 DISALLOW_COPY_AND_ASSIGN(DialAPI);
104 }; 105 };
105 106
106 // DiscoverNow function. This function needs a round-trip from the IO thread 107 // DiscoverNow function. This function needs a round-trip from the IO thread
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 device_description_fetcher_; 158 device_description_fetcher_;
158 159
159 DialAPI* dial_; 160 DialAPI* dial_;
160 161
161 DISALLOW_COPY_AND_ASSIGN(DialFetchDeviceDescriptionFunction); 162 DISALLOW_COPY_AND_ASSIGN(DialFetchDeviceDescriptionFunction);
162 }; 163 };
163 164
164 } // namespace extensions 165 } // namespace extensions
165 166
166 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ 167 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698