Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / media / cdm / browser_cdm_manager.h
blob85be4c182a59b9297562f7cd49d22e732ea5a77f
1 // Copyright 2014 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 CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_
6 #define CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/containers/scoped_ptr_hash_map.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "content/common/content_export.h"
17 #include "content/common/media/cdm_messages_enums.h"
18 #include "ipc/ipc_message.h"
19 // TODO(xhwang): Drop this when KeyError is moved to a common header.
20 #include "media/base/media_keys.h"
21 #include "url/gurl.h"
23 namespace media {
24 class BrowserCdm;
27 namespace content {
29 class RenderFrameHost;
30 class WebContents;
32 // This class manages all CDM objects. It receives control operations from the
33 // the render process, and forwards them to corresponding CDM object. Callbacks
34 // from CDM objects are converted to IPCs and then sent to the render process.
35 class CONTENT_EXPORT BrowserCdmManager {
36 public:
37 // Creates a new BrowserCdmManager for |rfh|.
38 static BrowserCdmManager* Create(RenderFrameHost* rfh);
40 ~BrowserCdmManager();
42 media::BrowserCdm* GetCdm(int cdm_id);
44 // CDM callbacks.
45 void OnSessionCreated(int cdm_id,
46 uint32 session_id,
47 const std::string& web_session_id);
48 void OnSessionMessage(int cdm_id,
49 uint32 session_id,
50 const std::vector<uint8>& message,
51 const GURL& destination_url);
52 void OnSessionReady(int cdm_id, uint32 session_id);
53 void OnSessionClosed(int cdm_id, uint32 session_id);
54 void OnSessionError(int cdm_id,
55 uint32 session_id,
56 media::MediaKeys::KeyError error_code,
57 uint32 system_code);
59 // Message handlers.
60 void OnInitializeCdm(int cdm_id,
61 const std::string& key_system,
62 const GURL& frame_url);
63 void OnCreateSession(int cdm_id,
64 uint32 session_id,
65 CdmHostMsg_CreateSession_ContentType content_type,
66 const std::vector<uint8>& init_data);
67 void OnUpdateSession(int cdm_id,
68 uint32 session_id,
69 const std::vector<uint8>& response);
70 void OnReleaseSession(int cdm_id, uint32 session_id);
71 void OnSetCdm(int player_id, int cdm_id);
72 void OnDestroyCdm(int cdm_id);
74 private:
75 // Clients must use Create() or subclass constructor.
76 explicit BrowserCdmManager(RenderFrameHost* render_frame_host);
78 // Cancels all pending session creations associated with |cdm_id|.
79 void CancelAllPendingSessionCreations(int cdm_id);
81 // Adds a new CDM identified by |cdm_id| for the given |key_system| and
82 // |security_origin|.
83 void AddCdm(int cdm_id,
84 const std::string& key_system,
85 const GURL& security_origin);
87 // Removes the CDM with the specified id.
88 void RemoveCdm(int cdm_id);
90 int RoutingID();
92 // Helper function to send messages to RenderFrameObserver.
93 bool Send(IPC::Message* msg);
95 // If |permitted| is false, it does nothing but send
96 // |CdmMsg_SessionError| IPC message.
97 // The primary use case is infobar permission callback, i.e., when infobar
98 // can decide user's intention either from interacting with the actual info
99 // bar or from the saved preference.
100 void CreateSessionIfPermitted(int cdm_id,
101 uint32 session_id,
102 const std::string& content_type,
103 const std::vector<uint8>& init_data,
104 bool permitted);
106 RenderFrameHost* const render_frame_host_;
108 WebContents* const web_contents_;
110 // A map from CDM IDs to managed CDMs.
111 typedef base::ScopedPtrHashMap<int, media::BrowserCdm> CdmMap;
112 CdmMap cdm_map_;
114 // Map from CDM ID to CDM's security origin.
115 std::map<int, GURL> cdm_security_origin_map_;
117 // Map from CDM ID to a callback to cancel the permission request.
118 std::map<int, base::Closure> cdm_cancel_permision_map_;
120 // NOTE: Weak pointers must be invalidated before all other member variables.
121 base::WeakPtrFactory<BrowserCdmManager> weak_ptr_factory_;
123 DISALLOW_COPY_AND_ASSIGN(BrowserCdmManager);
126 } // namespace content
128 #endif // CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_