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

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: lower similarity threshold 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 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 NavigatorConnectService;
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 service
18 static scoped_ptr<AmbientLightSensor> Create(); 24 // passed to the callback is transfered.
25 using ConnectCallback =
26 base::Callback<void(scoped_ptr<NavigatorConnectService>)>;
19 27
20 ~AmbientLightSensor(); 28 virtual ~NavigatorConnectServiceFactory() {}
21 29
22 // Retrieve lux values from Ambient Light Sensor. 30 // Return true if this factory is responsible for handling connections to the
23 bool ReadSensorValue(uint64_t lux_value[2]); 31 // |target_url|. The most recently added factory that returns true for a
32 // particular url is picked to handle the connection attempt.
33 virtual bool HandlesUrl(const GURL& target_url) = 0;
24 34
25 private: 35 // Called to try to establish a connection. Only called if this factory was
26 AmbientLightSensor(); 36 // the most recently added factory that returned true from |HandlesUrl| for
27 37 // the url being connected to.
28 // Probe the local hardware looking for Ambient Light sensor and 38 virtual void Connect(const NavigatorConnectClient& client,
29 // initialize an I/O connection to it. 39 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 }; 40 };
37 41
38 } // namespace content 42 } // namespace content
39 43
40 #endif // CONTENT_BROWSER_DEVICE_SENSORS_AMBIENT_LIGHT_MAC_H_ 44 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698