OLD | NEW |
(Empty) | |
| 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 <map> |
| 9 |
| 10 #include "chrome/browser/media/media_internals.h" |
| 11 #include "chrome/browser/media/media_internals_observer.h" |
| 12 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 13 #include "chrome/common/extensions/api/tab_capture.h" |
| 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/media_request_state.h" |
| 16 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/common/media_stream_request.h" |
| 19 |
| 20 class Profile; |
| 21 |
| 22 namespace extensions { |
| 23 |
| 24 namespace tab_capture = extensions::api::tab_capture; |
| 25 |
| 26 class TabCaptureRegistry : public ProfileKeyedService, |
| 27 public content::NotificationObserver { |
| 28 public: |
| 29 struct TabCaptureRequest { |
| 30 std::string extension_id; |
| 31 int tab_id; |
| 32 tab_capture::TabCaptureState status; |
| 33 |
| 34 TabCaptureRequest() {} |
| 35 TabCaptureRequest(std::string extension_id, int tab_id, |
| 36 tab_capture::TabCaptureState status) |
| 37 : extension_id(extension_id), tab_id(tab_id), status(status) {} |
| 38 }; |
| 39 typedef std::vector<TabCaptureRequest> CaptureRequestList; |
| 40 |
| 41 explicit TabCaptureRegistry(Profile* profile); |
| 42 |
| 43 const CaptureRequestList GetCapturedTabs(const std::string& extension_id); |
| 44 bool AddRequest(const std::string& key, const TabCaptureRequest& request); |
| 45 bool VerifyRequest(const std::string& key); |
| 46 |
| 47 private: |
| 48 // Maps device_id to information about the media stream request. This is |
| 49 // expected to be small since maintaining a media stream is expensive. |
| 50 typedef std::map<std::string, TabCaptureRequest> DeviceCaptureRequestMap; |
| 51 |
| 52 class MediaObserverProxy : public MediaInternalsObserver, |
| 53 public base::RefCountedThreadSafe< |
| 54 MediaObserverProxy> { |
| 55 public: |
| 56 MediaObserverProxy() : handler_(NULL) {} |
| 57 void Attach(TabCaptureRegistry* handler); |
| 58 void Detach(); |
| 59 |
| 60 private: |
| 61 friend class base::RefCountedThreadSafe<MediaObserverProxy>; |
| 62 virtual ~MediaObserverProxy() {} |
| 63 |
| 64 // MediaInternalsObserver. |
| 65 virtual void OnRequestUpdate( |
| 66 const content::MediaStreamDevice& device, |
| 67 const content::MediaRequestState state) OVERRIDE; |
| 68 |
| 69 void RegisterAsMediaObserverOnIOThread(bool unregister); |
| 70 void UpdateOnUIThread( |
| 71 const content::MediaStreamDevice& device, |
| 72 const content::MediaRequestState new_state); |
| 73 |
| 74 TabCaptureRegistry* handler_; |
| 75 }; |
| 76 |
| 77 virtual ~TabCaptureRegistry(); |
| 78 |
| 79 void HandleRequestUpdateOnUIThread( |
| 80 const content::MediaStreamDevice& device, |
| 81 const content::MediaRequestState state); |
| 82 |
| 83 // content::NotificationObserver implementation. |
| 84 virtual void Observe(int type, |
| 85 const content::NotificationSource& source, |
| 86 const content::NotificationDetails& details) OVERRIDE; |
| 87 |
| 88 scoped_refptr<MediaObserverProxy> proxy_; |
| 89 content::NotificationRegistrar registrar_; |
| 90 Profile* const profile_; |
| 91 DeviceCaptureRequestMap requests_; |
| 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry); |
| 94 }; |
| 95 |
| 96 } // namespace extension |
| 97 |
| 98 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ |
OLD | NEW |