| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/scoped_vector.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" | 13 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 15 #include "chrome/common/extensions/api/tab_capture.h" | 14 #include "chrome/common/extensions/api/tab_capture.h" |
| 16 #include "content/public/browser/media_request_state.h" | 15 #include "content/public/browser/media_request_state.h" |
| 17 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 19 | 19 |
| 20 class Profile; | 20 class Profile; |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 class BrowserContext; | 23 class BrowserContext; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 | 27 |
| 28 struct TabCaptureRequest; | 28 struct TabCaptureRequest; |
| 29 class FullscreenObserver; | 29 class FullscreenObserver; |
| 30 | 30 |
| 31 namespace tab_capture = extensions::api::tab_capture; | 31 namespace tab_capture = extensions::api::tab_capture; |
| 32 | 32 |
| 33 class TabCaptureRegistry : public ProfileKeyedAPI, | 33 class TabCaptureRegistry : public BrowserContextKeyedAPI, |
| 34 public content::NotificationObserver, | 34 public content::NotificationObserver, |
| 35 public MediaCaptureDevicesDispatcher::Observer { | 35 public MediaCaptureDevicesDispatcher::Observer { |
| 36 public: | 36 public: |
| 37 typedef std::vector<std::pair<int, tab_capture::TabCaptureState> > | 37 typedef std::vector<std::pair<int, tab_capture::TabCaptureState> > |
| 38 RegistryCaptureInfo; | 38 RegistryCaptureInfo; |
| 39 | 39 |
| 40 static TabCaptureRegistry* Get(content::BrowserContext* context); | 40 static TabCaptureRegistry* Get(content::BrowserContext* context); |
| 41 | 41 |
| 42 // Used by ProfileKeyedAPI. | 42 // Used by BrowserContextKeyedAPI. |
| 43 static ProfileKeyedAPIFactory<TabCaptureRegistry>* GetFactoryInstance(); | 43 static BrowserContextKeyedAPIFactory<TabCaptureRegistry>* |
| 44 GetFactoryInstance(); |
| 44 | 45 |
| 45 // List all pending, active and stopped capture requests. | 46 // List all pending, active and stopped capture requests. |
| 46 const RegistryCaptureInfo GetCapturedTabs( | 47 const RegistryCaptureInfo GetCapturedTabs( |
| 47 const std::string& extension_id) const; | 48 const std::string& extension_id) const; |
| 48 | 49 |
| 49 // Add a tab capture request to the registry when a stream is requested | 50 // Add a tab capture request to the registry when a stream is requested |
| 50 // through the API. | 51 // through the API. |
| 51 bool AddRequest(int render_process_id, | 52 bool AddRequest(int render_process_id, |
| 52 int render_view_id, | 53 int render_view_id, |
| 53 const std::string& extension_id, | 54 const std::string& extension_id, |
| 54 int tab_id, | 55 int tab_id, |
| 55 tab_capture::TabCaptureState status); | 56 tab_capture::TabCaptureState status); |
| 56 | 57 |
| 57 // The MediaStreamDevicesController will verify the request before creating | 58 // The MediaStreamDevicesController will verify the request before creating |
| 58 // the stream by checking the registry here. | 59 // the stream by checking the registry here. |
| 59 bool VerifyRequest(int render_process_id, int render_view_id); | 60 bool VerifyRequest(int render_process_id, int render_view_id); |
| 60 | 61 |
| 61 private: | 62 private: |
| 62 friend class ProfileKeyedAPIFactory<TabCaptureRegistry>; | 63 friend class BrowserContextKeyedAPIFactory<TabCaptureRegistry>; |
| 63 friend class FullscreenObserver; | 64 friend class FullscreenObserver; |
| 64 | 65 |
| 65 explicit TabCaptureRegistry(content::BrowserContext* context); | 66 explicit TabCaptureRegistry(content::BrowserContext* context); |
| 66 virtual ~TabCaptureRegistry(); | 67 virtual ~TabCaptureRegistry(); |
| 67 | 68 |
| 68 // Used by ProfileKeyedAPI. | 69 // Used by BrowserContextKeyedAPI. |
| 69 static const char* service_name() { | 70 static const char* service_name() { |
| 70 return "TabCaptureRegistry"; | 71 return "TabCaptureRegistry"; |
| 71 } | 72 } |
| 72 | 73 |
| 73 static const bool kServiceIsCreatedWithBrowserContext = false; | 74 static const bool kServiceIsCreatedWithBrowserContext = false; |
| 74 static const bool kServiceRedirectedInIncognito = true; | 75 static const bool kServiceRedirectedInIncognito = true; |
| 75 | 76 |
| 76 // content::NotificationObserver implementation. | 77 // content::NotificationObserver implementation. |
| 77 virtual void Observe(int type, | 78 virtual void Observe(int type, |
| 78 const content::NotificationSource& source, | 79 const content::NotificationSource& source, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 95 content::NotificationRegistrar registrar_; | 96 content::NotificationRegistrar registrar_; |
| 96 Profile* const profile_; | 97 Profile* const profile_; |
| 97 ScopedVector<TabCaptureRequest> requests_; | 98 ScopedVector<TabCaptureRequest> requests_; |
| 98 | 99 |
| 99 DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry); | 100 DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry); |
| 100 }; | 101 }; |
| 101 | 102 |
| 102 } // namespace extensions | 103 } // namespace extensions |
| 103 | 104 |
| 104 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ | 105 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ |
| OLD | NEW |