1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_
12 #include "base/memory/scoped_vector.h"
13 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
14 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
15 #include "chrome/common/extensions/api/tab_capture.h"
16 #include "content/public/browser/media_request_state.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
22 namespace extensions {
24 struct TabCaptureRequest;
25 class FullscreenObserver;
27 namespace tab_capture = extensions::api::tab_capture;
29 class TabCaptureRegistry : public ProfileKeyedAPI,
30 public content::NotificationObserver,
31 public MediaCaptureDevicesDispatcher::Observer {
33 typedef std::vector<std::pair<int, tab_capture::TabCaptureState> >
36 static TabCaptureRegistry* Get(Profile* profile);
38 // Used by ProfileKeyedAPI.
39 static ProfileKeyedAPIFactory<TabCaptureRegistry>* GetFactoryInstance();
41 // List all pending, active and stopped capture requests.
42 const RegistryCaptureInfo GetCapturedTabs(
43 const std::string& extension_id) const;
45 // Add a tab capture request to the registry when a stream is requested
47 bool AddRequest(int render_process_id,
49 const std::string& extension_id,
51 tab_capture::TabCaptureState status);
53 // The MediaStreamDevicesController will verify the request before creating
54 // the stream by checking the registry here.
55 bool VerifyRequest(int render_process_id, int render_view_id);
58 friend class ProfileKeyedAPIFactory<TabCaptureRegistry>;
59 friend class FullscreenObserver;
61 explicit TabCaptureRegistry(Profile* profile);
62 virtual ~TabCaptureRegistry();
64 // Used by ProfileKeyedAPI.
65 static const char* service_name() {
66 return "TabCaptureRegistry";
69 static const bool kServiceIsCreatedWithBrowserContext = false;
70 static const bool kServiceRedirectedInIncognito = true;
72 // content::NotificationObserver implementation.
73 virtual void Observe(int type,
74 const content::NotificationSource& source,
75 const content::NotificationDetails& details) OVERRIDE;
77 // MediaCaptureDevicesDispatcher::Observer implementation.
78 virtual void OnRequestUpdate(
79 int render_process_id,
81 const content::MediaStreamDevice& device,
82 const content::MediaRequestState state) OVERRIDE;
84 void DispatchStatusChangeEvent(const TabCaptureRequest* request) const;
86 TabCaptureRequest* FindCaptureRequest(int render_process_id,
87 int render_view_id) const;
89 void DeleteCaptureRequest(int render_process_id, int render_view_id);
91 content::NotificationRegistrar registrar_;
92 Profile* const profile_;
93 ScopedVector<TabCaptureRequest> requests_;
95 DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry);
98 } // namespace extensions
100 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_