Index: chrome/browser/extensions/api/dial/dial_api.h |
diff --git a/chrome/browser/extensions/api/dial/dial_api.h b/chrome/browser/extensions/api/dial/dial_api.h |
index c9ba27a5081a534bdead0d5e1d25316cab6e3f6e..2e5757a2c31586e1489e297887869b6815ae6181 100644 |
--- a/chrome/browser/extensions/api/dial/dial_api.h |
+++ b/chrome/browser/extensions/api/dial/dial_api.h |
@@ -10,14 +10,20 @@ |
#include "base/macros.h" |
#include "chrome/browser/extensions/api/dial/dial_device_data.h" |
#include "chrome/browser/extensions/api/dial/dial_registry.h" |
+#include "chrome/common/extensions/api/dial.h" |
#include "components/keyed_service/core/refcounted_keyed_service.h" |
#include "extensions/browser/api/async_api_function.h" |
#include "extensions/browser/event_router.h" |
namespace extensions { |
+class DeviceDescriptionFetcher; |
class DialRegistry; |
+namespace api { |
+class DialFetchDeviceDescriptionFunction; |
+} // namespace api |
+ |
// Dial API which is a ref-counted KeyedService that manages |
// the DIAL registry. It takes care of creating the registry on the IO thread |
// and is an observer of the registry. It makes sure devices events are sent out |
@@ -26,6 +32,13 @@ class DialRegistry; |
// TODO(mfoltz): This should probably inherit from BrowserContextKeyedAPI |
// instead; ShutdownOnUIThread below is a no-op, which is the whole point of |
// RefcountedKeyedService. |
+// |
+// TODO(mfoltz): The threading model for this API needs to be rethought. At a |
+// minimum, DialRegistry should move to the UI thread to avoid extra thread hops |
+// here, allow a straightforward GetDeviceList implementation |
+// (crbug.com/576817), cleanup some long-tail crashes (crbug.com/640011) that |
+// are likely due to lifetime issues, and simplify unit tests |
+// (crbug.com/661457). |
class DialAPI : public RefcountedKeyedService, |
public EventRouter::Observer, |
public DialRegistry::Observer { |
@@ -41,9 +54,15 @@ class DialAPI : public RefcountedKeyedService, |
void SendEventOnUIThread(const DialRegistry::DeviceList& devices); |
void SendErrorOnUIThread(const DialRegistry::DialErrorCode type); |
+ // Sets test device data. For tests only. |
+ void SetDeviceForTest(const DialDeviceData& device_data, |
+ const DialDeviceDescription& device_description); |
+ |
private: |
~DialAPI() override; |
+ friend class api::DialFetchDeviceDescriptionFunction; |
+ |
// RefcountedKeyedService: |
void ShutdownOnUIThread() override; |
@@ -65,6 +84,10 @@ class DialAPI : public RefcountedKeyedService, |
// Created lazily on first access on the IO thread. |
std::unique_ptr<DialRegistry> dial_registry_; |
+ // Device data for testing. |
+ DialDeviceData test_device_data_; |
+ DialDeviceDescription test_device_description_; |
+ |
DISALLOW_COPY_AND_ASSIGN(DialAPI); |
}; |
@@ -100,6 +123,33 @@ class DialDiscoverNowFunction : public AsyncApiFunction { |
DISALLOW_COPY_AND_ASSIGN(DialDiscoverNowFunction); |
}; |
+class DialFetchDeviceDescriptionFunction : public AsyncExtensionFunction { |
+ public: |
+ DialFetchDeviceDescriptionFunction(); |
+ |
+ protected: |
+ ~DialFetchDeviceDescriptionFunction() override; |
+ |
+ // AsyncExtensionFunction: |
+ bool RunAsync() override; |
+ |
+ private: |
+ DECLARE_EXTENSION_FUNCTION("dial.fetchDeviceDescription", |
+ DIAL_FETCHDEVICEDESCRIPTION) |
+ |
+ void GetDeviceDescriptionUrlOnIOThread(const std::string& label); |
+ void MaybeStartFetch(const GURL& url); |
+ void OnFetchComplete(const DialDeviceDescription& result); |
+ void OnFetchError(const std::string& result); |
+ |
+ std::unique_ptr<api::dial::FetchDeviceDescription::Params> params_; |
+ std::unique_ptr<DeviceDescriptionFetcher> device_description_fetcher_; |
+ |
+ DialAPI* dial_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DialFetchDeviceDescriptionFunction); |
+}; |
+ |
} // namespace api |
} // namespace extensions |