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

Side by Side 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, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 CONTENT_BROWSER_DEVICE_SENSORS_AMBIENT_LIGHT_MAC_H_ 5 #ifndef CONTENT_PUBLIC_BROWSER_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_
6 #define CONTENT_BROWSER_DEVICE_SENSORS_AMBIENT_LIGHT_MAC_H_ 6 #define CONTENT_PUBLIC_BROWSER_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_
7 7
8 #include <IOKit/IOKitLib.h> 8 #include "base/callback.h"
9 9
10 #include "base/memory/scoped_ptr.h" 10 class GURL;
11 11
12 namespace content { 12 namespace content {
13 13
14 // Provides an interface to retrieve ambient light data from MacBooks. 14 struct NavigatorConnectClient;
15 class AmbientLightSensor { 15 class MessagePortDelegate;
16
17 // Implement this interface to provide a new kind of navigator.connect
18 // accessible service.
19 // Instances of this class are owned by NavigatorConnectContext. Register new
20 // factories by calling NavigatorConnectContext::AddFactory.
21 class NavigatorConnectServiceFactory {
16 public: 22 public:
17 // Create AmbientLightSensor object, return NULL if no valid is sensor found. 23 // Call with nullptr to indicate connection failure. Ownership of the delegate
18 static scoped_ptr<AmbientLightSensor> Create(); 24 // remains with the factory. It is assumed that for the passed
25 // MessagePortDelegate implementation the route_id and message_port_id of a
26 // connection are the same.
27 using ConnectCallback = base::Callback<void(MessagePortDelegate*)>;
19 28
20 ~AmbientLightSensor(); 29 virtual ~NavigatorConnectServiceFactory() {}
21 30
22 // Retrieve lux values from Ambient Light Sensor. 31 // Return true if this factory is responsible for handling connections to the
23 bool ReadSensorValue(uint64_t lux_value[2]); 32 // |target_url|. The most recently added factory that returns true for a
33 // particular url is picked to handle the connection attempt.
34 virtual bool HandlesUrl(const GURL& target_url) = 0;
24 35
25 private: 36 // Called to try to establish a connection. Only called if this factory was
26 AmbientLightSensor(); 37 // the most recently added factory that returned true from |HandlesUrl| for
27 38 // the url being connected to.
28 // Probe the local hardware looking for Ambient Light sensor and 39 virtual void Connect(const NavigatorConnectClient& client,
29 // initialize an I/O connection to it. 40 const ConnectCallback& callback) = 0;
30 bool Init();
31
32 // IOKit connection to the local sensor.
33 io_connect_t io_connection_;
34
35 DISALLOW_COPY_AND_ASSIGN(AmbientLightSensor);
36 }; 41 };
37 42
38 } // namespace content 43 } // namespace content
39 44
40 #endif // CONTENT_BROWSER_DEVICE_SENSORS_AMBIENT_LIGHT_MAC_H_ 45 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_
OLDNEW
« 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