Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / browser / api / webcam_private / webcam_private_api.h
blob3275598ff3ab14392b0803f183ac36f3fed0fab1
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;
94 bool RunAsync() override;
96 private:
97 void OnOpenWebcam(const std::string& webcam_id, bool success);
99 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateOpenSerialWebcamFunction);
102 class WebcamPrivateCloseWebcamFunction : public AsyncExtensionFunction {
103 public:
104 WebcamPrivateCloseWebcamFunction();
105 DECLARE_EXTENSION_FUNCTION("webcamPrivate.closeWebcam",
106 WEBCAMPRIVATE_CLOSEWEBCAM);
108 protected:
109 ~WebcamPrivateCloseWebcamFunction() override;
110 bool RunAsync() override;
112 private:
113 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateCloseWebcamFunction);
116 class WebcamPrivateSetFunction : public AsyncExtensionFunction {
117 public:
118 WebcamPrivateSetFunction();
119 DECLARE_EXTENSION_FUNCTION("webcamPrivate.set", WEBCAMPRIVATE_SET);
121 protected:
122 ~WebcamPrivateSetFunction() override;
123 bool RunAsync() override;
125 private:
126 void OnSetWebcamParameters(bool success);
128 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateSetFunction);
131 class WebcamPrivateGetFunction : public AsyncExtensionFunction {
132 public:
133 WebcamPrivateGetFunction();
134 DECLARE_EXTENSION_FUNCTION("webcamPrivate.get", WEBCAMPRIVATE_GET);
136 protected:
137 ~WebcamPrivateGetFunction() override;
138 bool RunAsync() override;
140 private:
141 enum InquiryType {
142 INQUIRY_PAN,
143 INQUIRY_TILT,
144 INQUIRY_ZOOM,
146 void OnGetWebcamParameters(InquiryType type, bool success, int value);
148 int pan_;
149 int tilt_;
150 int zoom_;
151 bool get_pan_;
152 bool get_tilt_;
153 bool get_zoom_;
154 bool success_;
156 DISALLOW_COPY_AND_ASSIGN(WebcamPrivateGetFunction);
159 class WebcamPrivateResetFunction : public AsyncExtensionFunction {
160 public:
161 WebcamPrivateResetFunction();
162 DECLARE_EXTENSION_FUNCTION("webcamPrivate.reset", WEBCAMPRIVATE_RESET);
164 protected:
165 ~WebcamPrivateResetFunction() override;
166 bool RunAsync() override;
168 private:
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_