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. 4 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ 7 8 #include <string> 9 #include <utility> 10 #include <vector> 11 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" 19 20 class Profile; 21 22 namespace extensions { 23 24 struct TabCaptureRequest; 25 class FullscreenObserver; 26 27 namespace tab_capture = extensions::api::tab_capture; 28 29 class TabCaptureRegistry : public ProfileKeyedAPI, 30 public content::NotificationObserver, 31 public MediaCaptureDevicesDispatcher::Observer { 32 public: 33 typedef std::vector<std::pair<int, tab_capture::TabCaptureState> > 34 RegistryCaptureInfo; 35 36 static TabCaptureRegistry* Get(Profile* profile); 37 38 // Used by ProfileKeyedAPI. 39 static ProfileKeyedAPIFactory<TabCaptureRegistry>* GetFactoryInstance(); 40 41 // List all pending, active and stopped capture requests. 42 const RegistryCaptureInfo GetCapturedTabs( 43 const std::string& extension_id) const; 44 45 // Add a tab capture request to the registry when a stream is requested 46 // through the API. 47 bool AddRequest(int render_process_id, 48 int render_view_id, 49 const std::string& extension_id, 50 int tab_id, 51 tab_capture::TabCaptureState status); 52 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); 56 57 private: 58 friend class ProfileKeyedAPIFactory<TabCaptureRegistry>; 59 friend class FullscreenObserver; 60 61 explicit TabCaptureRegistry(Profile* profile); 62 virtual ~TabCaptureRegistry(); 63 64 // Used by ProfileKeyedAPI. 65 static const char* service_name() { 66 return "TabCaptureRegistry"; 67 } 68 69 static const bool kServiceIsCreatedWithBrowserContext = false; 70 static const bool kServiceRedirectedInIncognito = true; 71 72 // content::NotificationObserver implementation. 73 virtual void Observe(int type, 74 const content::NotificationSource& source, 75 const content::NotificationDetails& details) OVERRIDE; 76 77 // MediaCaptureDevicesDispatcher::Observer implementation. 78 virtual void OnRequestUpdate( 79 int render_process_id, 80 int render_view_id, 81 const content::MediaStreamDevice& device, 82 const content::MediaRequestState state) OVERRIDE; 83 84 void DispatchStatusChangeEvent(const TabCaptureRequest* request) const; 85 86 TabCaptureRequest* FindCaptureRequest(int render_process_id, 87 int render_view_id) const; 88 89 void DeleteCaptureRequest(int render_process_id, int render_view_id); 90 91 content::NotificationRegistrar registrar_; 92 Profile* const profile_; 93 ScopedVector<TabCaptureRequest> requests_; 94 95 DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry); 96 }; 97 98 } // namespace extensions 99 100 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ 101