Home | History | Annotate | Download | only in tab_capture
      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 
     10 #include "base/memory/scoped_vector.h"
     11 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
     12 #include "chrome/common/extensions/api/tab_capture.h"
     13 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
     14 #include "content/public/browser/media_request_state.h"
     15 #include "content/public/browser/notification_observer.h"
     16 #include "content/public/browser/notification_registrar.h"
     17 
     18 class Profile;
     19 
     20 namespace extensions {
     21 
     22 struct TabCaptureRequest;
     23 class FullscreenObserver;
     24 
     25 namespace tab_capture = extensions::api::tab_capture;
     26 
     27 class TabCaptureRegistry : public BrowserContextKeyedService,
     28                            public content::NotificationObserver,
     29                            public MediaCaptureDevicesDispatcher::Observer {
     30  public:
     31   typedef std::vector<std::pair<int, tab_capture::TabCaptureState> >
     32       RegistryCaptureInfo;
     33 
     34   explicit TabCaptureRegistry(Profile* profile);
     35 
     36   // List all pending, active and stopped capture requests.
     37   const RegistryCaptureInfo GetCapturedTabs(
     38       const std::string& extension_id) const;
     39 
     40   // Add a tab capture request to the registry when a stream is requested
     41   // through the API.
     42   bool AddRequest(int render_process_id,
     43                   int render_view_id,
     44                   const std::string& extension_id,
     45                   int tab_id,
     46                   tab_capture::TabCaptureState status);
     47 
     48   // The MediaStreamDevicesController will verify the request before creating
     49   // the stream by checking the registry here.
     50   bool VerifyRequest(int render_process_id, int render_view_id);
     51 
     52  private:
     53   friend class FullscreenObserver;
     54 
     55   virtual ~TabCaptureRegistry();
     56 
     57   // content::NotificationObserver implementation.
     58   virtual void Observe(int type,
     59                        const content::NotificationSource& source,
     60                        const content::NotificationDetails& details) OVERRIDE;
     61 
     62   // MediaCaptureDevicesDispatcher::Observer implementation.
     63   virtual void OnRequestUpdate(
     64       int render_process_id,
     65       int render_view_id,
     66       const content::MediaStreamDevice& device,
     67       const content::MediaRequestState state) OVERRIDE;
     68 
     69   void DispatchStatusChangeEvent(const TabCaptureRequest* request) const;
     70 
     71   TabCaptureRequest* FindCaptureRequest(int render_process_id,
     72                                         int render_view_id) const;
     73 
     74   void DeleteCaptureRequest(int render_process_id, int render_view_id);
     75 
     76   content::NotificationRegistrar registrar_;
     77   Profile* const profile_;
     78   ScopedVector<TabCaptureRequest> requests_;
     79 
     80   DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry);
     81 };
     82 
     83 }  // namespace extension
     84 
     85 #endif  // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_
     86