1 // Copyright 2015 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 EXTENSIONS_BROWSER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_STREAM_MANAGER_H_
6 #define EXTENSIONS_BROWSER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_STREAM_MANAGER_H_
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/scoped_observer.h"
15 #include "components/keyed_service/core/keyed_service.h"
16 #include "extensions/browser/extension_registry_observer.h"
22 namespace extensions
{
24 class StreamContainer
;
26 // A container for streams that have not yet been claimed by a
27 // MimeHandlerViewGuest. If the embedding RenderFrameHost is closed or navigates
28 // away from the resource being streamed, the stream is aborted. This is
29 // BrowserContext-keyed because mime handlers are extensions, which are
30 // per-BrowserContext.
31 class MimeHandlerStreamManager
: public KeyedService
,
32 public ExtensionRegistryObserver
{
34 MimeHandlerStreamManager();
35 ~MimeHandlerStreamManager() override
;
36 static MimeHandlerStreamManager
* Get(content::BrowserContext
* context
);
38 void AddStream(const std::string
& view_id
,
39 scoped_ptr
<StreamContainer
> stream
,
40 int render_process_id
,
43 scoped_ptr
<StreamContainer
> ReleaseStream(const std::string
& view_id
);
45 // ExtensionRegistryObserver override.
46 void OnExtensionUnloaded(content::BrowserContext
* browser_context
,
47 const Extension
* extension
,
48 UnloadedExtensionInfo::Reason reason
) override
;
51 class EmbedderObserver
;
53 // Maps view id->StreamContainer to maintain their lifetime until they are
55 std::map
<std::string
, linked_ptr
<StreamContainer
>> streams_
;
57 // Maps extension id->view id for removing the associated streams when an
58 // extension is unloaded.
59 std::map
<std::string
, std::set
<std::string
>> streams_by_extension_id_
;
61 // Maps view id->EmbedderObserver for maintaining the lifetime of the
62 // EmbedderObserver until it is removed.
63 std::map
<std::string
, linked_ptr
<EmbedderObserver
>> embedder_observers_
;
65 ScopedObserver
<ExtensionRegistry
, ExtensionRegistryObserver
>
66 extension_registry_observer_
;
69 } // namespace extensions
71 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_STREAM_MANAGER_H_