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

Unified Diff: content/public/browser/navigator_connect_service_factory.h

Issue 861373002: Refactor navigator.connect code to make it more flexible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/public/browser/navigator_connect_service_factory.h
diff --git a/content/browser/device_sensors/ambient_light_mac.h b/content/public/browser/navigator_connect_service_factory.h
similarity index 13%
copy from content/browser/device_sensors/ambient_light_mac.h
copy to content/public/browser/navigator_connect_service_factory.h
index 8d34e165b80bc6c26da60dec1084fd0872c69352..f66b2de18524142863df79dd359bb04bacf48de4 100644
--- a/content/browser/device_sensors/ambient_light_mac.h
+++ b/content/public/browser/navigator_connect_service_factory.h
@@ -2,39 +2,44 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CONTENT_BROWSER_DEVICE_SENSORS_AMBIENT_LIGHT_MAC_H_
-#define CONTENT_BROWSER_DEVICE_SENSORS_AMBIENT_LIGHT_MAC_H_
+#ifndef CONTENT_PUBLIC_BROWSER_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_
+#define CONTENT_PUBLIC_BROWSER_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_
-#include <IOKit/IOKitLib.h>
+#include "base/callback.h"
-#include "base/memory/scoped_ptr.h"
+class GURL;
namespace content {
-// Provides an interface to retrieve ambient light data from MacBooks.
-class AmbientLightSensor {
- public:
- // Create AmbientLightSensor object, return NULL if no valid is sensor found.
- static scoped_ptr<AmbientLightSensor> Create();
-
- ~AmbientLightSensor();
-
- // Retrieve lux values from Ambient Light Sensor.
- bool ReadSensorValue(uint64_t lux_value[2]);
-
- private:
- AmbientLightSensor();
+struct NavigatorConnectClient;
+class MessagePortDelegate;
- // Probe the local hardware looking for Ambient Light sensor and
- // initialize an I/O connection to it.
- bool Init();
-
- // IOKit connection to the local sensor.
- io_connect_t io_connection_;
-
- DISALLOW_COPY_AND_ASSIGN(AmbientLightSensor);
+// Implement this interface to provide a new kind of navigator.connect
+// accessible service.
+// Instances of this class are owned by NavigatorConnectContext. Register new
+// factories by calling NavigatorConnectContext::AddFactory.
+class NavigatorConnectServiceFactory {
+ public:
+ // Call with nullptr to indicate connection failure. Ownership of the delegate
+ // remains with the factory. It is assumed that for the passed
+ // MessagePortDelegate implementation the route_id and message_port_id of a
+ // connection are the same.
+ using ConnectCallback = base::Callback<void(MessagePortDelegate*)>;
+
+ virtual ~NavigatorConnectServiceFactory() {}
+
+ // Return true if this factory is responsible for handling connections to the
+ // |target_url|. The most recently added factory that returns true for a
+ // particular url is picked to handle the connection attempt.
+ virtual bool HandlesUrl(const GURL& target_url) = 0;
+
+ // Called to try to establish a connection. Only called if this factory was
+ // the most recently added factory that returned true from |HandlesUrl| for
+ // the url being connected to.
+ virtual void Connect(const NavigatorConnectClient& client,
+ const ConnectCallback& callback) = 0;
};
} // namespace content
-#endif // CONTENT_BROWSER_DEVICE_SENSORS_AMBIENT_LIGHT_MAC_H_
+#endif // CONTENT_PUBLIC_BROWSER_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_
« no previous file with comments | « content/public/browser/navigator_connect_context.h ('k') | content/public/common/navigator_connect_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698