Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / browser / guest_view / mime_handler_view / mime_handler_stream_manager.h
blob5e46ac31054571198604401a560d2f592f9dc771
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_
8 #include <map>
9 #include <set>
10 #include <string>
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"
18 namespace content {
19 class BrowserContext;
22 namespace extensions {
23 class Extension;
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 {
33 public:
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,
41 int render_frame_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;
50 private:
51 class EmbedderObserver;
53 // Maps view id->StreamContainer to maintain their lifetime until they are
54 // used or removed.
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_