make use of media_use_ffmpeg in BUILD.gn
[chromium-blink-merge.git] / extensions / browser / api / webcam_private / webcam_private_api.h
blobec2cf93fed783d494c273c318494072c030bc098
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_
8 #include <map>
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"
18 class Profile;
20 namespace extensions {
22 class ProcessManager;
24 class WebcamPrivateAPI : public BrowserContextKeyedAPI {
25 public:
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);
44 private:
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,
52 bool success);
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);
82 template <>
83 void BrowserContextKeyedAPIFactory<WebcamPrivateAPI>
84 ::DeclareFactoryDependencies();
86 class WebcamPrivateOpenSerialWebcamFunction : public AsyncExtensionFunction {
87 public:
88 WebcamPrivateOpenSerialWebcamFunction();
89 DECLARE_EXTENSION_FUNCTION("webcamPrivate.openSerialWebcam",
90 WEBCAMPRIVATE_OPENSERIALWEBCAM);
92 protected:
93 ~WebcamPrivateOpenSerialWebcamFunction() override;
95 // AsyncExtensionFunction:
96 bool RunAsync() override;
98 private:
99 void OnOpenWebcam(const std::string& webcam_id, bool success);
101 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateOpenSerialWebcamFunction);
104 class WebcamPrivateCloseWebcamFunction : public AsyncExtensionFunction {
105 public:
106 WebcamPrivateCloseWebcamFunction();
107 DECLARE_EXTENSION_FUNCTION("webcamPrivate.closeWebcam",
108 WEBCAMPRIVATE_CLOSEWEBCAM);
110 protected:
111 ~WebcamPrivateCloseWebcamFunction() override;
113 // AsyncApiFunction:
114 bool RunAsync() override;
116 private:
117 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateCloseWebcamFunction);
120 class WebcamPrivateSetFunction : public SyncExtensionFunction {
121 public:
122 WebcamPrivateSetFunction();
123 DECLARE_EXTENSION_FUNCTION("webcamPrivate.set", WEBCAMPRIVATE_SET);
125 protected:
126 ~WebcamPrivateSetFunction() override;
127 bool RunSync() override;
129 private:
130 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateSetFunction);
133 class WebcamPrivateGetFunction : public SyncExtensionFunction {
134 public:
135 WebcamPrivateGetFunction();
136 DECLARE_EXTENSION_FUNCTION("webcamPrivate.get", WEBCAMPRIVATE_GET);
138 protected:
139 ~WebcamPrivateGetFunction() override;
140 bool RunSync() override;
142 private:
143 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateGetFunction);
146 class WebcamPrivateResetFunction : public SyncExtensionFunction {
147 public:
148 WebcamPrivateResetFunction();
149 DECLARE_EXTENSION_FUNCTION("webcamPrivate.reset", WEBCAMPRIVATE_RESET);
151 protected:
152 ~WebcamPrivateResetFunction() override;
153 bool RunSync() override;
155 private:
156 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateResetFunction);
159 } // namespace extensions
161 #endif // EXTENSIONS_BROWSER_API_WEBCAM_PRIVATE_WEBCAM_PRIVATE_API_H_