1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_WEBCAM_PRIVATE_API_H_
6 #define EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_WEBCAM_PRIVATE_API_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/scoped_observer.h"
12 #include "extensions/browser/api/api_resource_manager.h"
13 #include "extensions/browser/api/webcam_private/webcam.h"
14 #include "extensions/browser/browser_context_keyed_api_factory.h"
15 #include "extensions/browser/extension_function.h"
16 #include "extensions/browser/process_manager_observer.h"
20 namespace extensions
{
24 class WebcamPrivateAPI
: public BrowserContextKeyedAPI
{
26 static BrowserContextKeyedAPIFactory
<WebcamPrivateAPI
>* GetFactoryInstance();
28 // Convenience method to get the WebcamPrivateAPI for a BrowserContext.
29 static WebcamPrivateAPI
* Get(content::BrowserContext
* context
);
31 explicit WebcamPrivateAPI(content::BrowserContext
* context
);
32 ~WebcamPrivateAPI() override
;
34 Webcam
* GetWebcam(const std::string
& extension_id
,
35 const std::string
& device_id
);
37 bool OpenSerialWebcam(
38 const std::string
& extension_id
,
39 const std::string
& device_path
,
40 const base::Callback
<void(const std::string
&, bool)>& callback
);
41 bool CloseWebcam(const std::string
& extension_id
,
42 const std::string
& device_id
);
45 friend class BrowserContextKeyedAPIFactory
<WebcamPrivateAPI
>;
47 void OnOpenSerialWebcam(
48 const std::string
& extension_id
,
49 const std::string
& device_path
,
50 scoped_refptr
<Webcam
> webcam
,
51 const base::Callback
<void(const std::string
&, bool)>& callback
,
54 // Note: This function does not work for serial devices. Do not use this
55 // function for serial devices.
56 bool GetDeviceId(const std::string
& extension_id
,
57 const std::string
& webcam_id
,
58 std::string
* device_id
);
59 std::string
GetWebcamId(const std::string
& extension_id
,
60 const std::string
& device_id
);
62 WebcamResource
* FindWebcamResource(const std::string
& extension_id
,
63 const std::string
& webcam_id
) const;
64 bool RemoveWebcamResource(const std::string
& extension_id
,
65 const std::string
& webcam_id
);
67 // BrowserContextKeyedAPI:
68 static const char* service_name() {
69 return "WebcamPrivateAPI";
71 static const bool kServiceIsNULLWhileTesting
= true;
72 static const bool kServiceRedirectedInIncognito
= true;
74 content::BrowserContext
* const browser_context_
;
75 scoped_ptr
<ApiResourceManager
<WebcamResource
>> webcam_resource_manager_
;
77 base::WeakPtrFactory
<WebcamPrivateAPI
> weak_ptr_factory_
;
79 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateAPI
);
83 void BrowserContextKeyedAPIFactory
<WebcamPrivateAPI
>
84 ::DeclareFactoryDependencies();
86 class WebcamPrivateOpenSerialWebcamFunction
: public AsyncExtensionFunction
{
88 WebcamPrivateOpenSerialWebcamFunction();
89 DECLARE_EXTENSION_FUNCTION("webcamPrivate.openSerialWebcam",
90 WEBCAMPRIVATE_OPENSERIALWEBCAM
);
93 ~WebcamPrivateOpenSerialWebcamFunction() override
;
94 bool RunAsync() override
;
97 void OnOpenWebcam(const std::string
& webcam_id
, bool success
);
99 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateOpenSerialWebcamFunction
);
102 class WebcamPrivateCloseWebcamFunction
: public AsyncExtensionFunction
{
104 WebcamPrivateCloseWebcamFunction();
105 DECLARE_EXTENSION_FUNCTION("webcamPrivate.closeWebcam",
106 WEBCAMPRIVATE_CLOSEWEBCAM
);
109 ~WebcamPrivateCloseWebcamFunction() override
;
110 bool RunAsync() override
;
113 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateCloseWebcamFunction
);
116 class WebcamPrivateSetFunction
: public AsyncExtensionFunction
{
118 WebcamPrivateSetFunction();
119 DECLARE_EXTENSION_FUNCTION("webcamPrivate.set", WEBCAMPRIVATE_SET
);
122 ~WebcamPrivateSetFunction() override
;
123 bool RunAsync() override
;
126 void OnSetWebcamParameters(bool success
);
128 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateSetFunction
);
131 class WebcamPrivateGetFunction
: public AsyncExtensionFunction
{
133 WebcamPrivateGetFunction();
134 DECLARE_EXTENSION_FUNCTION("webcamPrivate.get", WEBCAMPRIVATE_GET
);
137 ~WebcamPrivateGetFunction() override
;
138 bool RunAsync() override
;
146 void OnGetWebcamParameters(InquiryType type
, bool success
, int value
);
156 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateGetFunction
);
159 class WebcamPrivateResetFunction
: public AsyncExtensionFunction
{
161 WebcamPrivateResetFunction();
162 DECLARE_EXTENSION_FUNCTION("webcamPrivate.reset", WEBCAMPRIVATE_RESET
);
165 ~WebcamPrivateResetFunction() override
;
166 bool RunAsync() override
;
169 void OnResetWebcam(bool success
);
171 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateResetFunction
);
174 } // namespace extensions
176 #endif // EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_WEBCAM_PRIVATE_API_H_