OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 #include "components/cdm/browser/media_drm_storage_impl.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/memory/ptr_util.h" | |
9 #include "components/prefs/pref_registry_simple.h" | |
10 #include "components/prefs/pref_service.h" | |
11 #include "components/prefs/scoped_user_pref_update.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "content/public/browser/navigation_handle.h" | |
14 | |
15 // The storage will be managed by PrefService. All data will be stored in a | |
16 // dictionary under the key "media.media_drm_storage". The dictionary is | |
17 // structured as follows: | |
18 // | |
19 // { | |
20 // $origin: { | |
21 // "origin_id": $origin_id | |
22 // "creation_time": $creation_time | |
23 // "sessions" : { | |
24 // $session_id: { | |
25 // "key_set_id": $key_set_id, | |
26 // "mime_type": $mime_type, | |
27 // "creation_time": $creation_time | |
28 // }, | |
29 // # more session_id map... | |
30 // } | |
31 // }, | |
32 // # more origin map... | |
33 // } | |
34 | |
35 namespace cdm { | |
36 | |
37 namespace { | |
38 | |
39 const char kMediaDrmStorage[] = "media.media_drm_storage"; | |
40 | |
41 } // namespace | |
42 | |
43 // static | |
44 void MediaDrmStorageImpl::RegisterProfilePrefs(PrefRegistrySimple* registry) { | |
45 registry->RegisterDictionaryPref(kMediaDrmStorage); | |
46 } | |
47 | |
48 MediaDrmStorageImpl::MediaDrmStorageImpl( | |
49 content::RenderFrameHost* render_frame_host, | |
50 PrefService* pref_service, | |
51 const url::Origin& origin, | |
52 media::mojom::MediaDrmStorageRequest request) | |
53 : render_frame_host_(render_frame_host), | |
54 pref_service_(pref_service), | |
55 origin_(origin), | |
56 binding_(this, std::move(request)) { | |
57 DVLOG(1) << __func__ << ": origin = " << origin; | |
58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
59 DCHECK(pref_service_); | |
60 | |
61 // |this| owns |binding_|, so unretained is safe. | |
62 binding_.set_connection_error_handler( | |
63 base::Bind(&MediaDrmStorageImpl::Close, base::Unretained(this))); | |
64 } | |
65 | |
66 MediaDrmStorageImpl::~MediaDrmStorageImpl() { | |
67 DVLOG(1) << __func__; | |
68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
69 } | |
70 | |
71 // TODO(xhwang): Update this function to return an origin ID. If the origin is | |
72 // not the same as |origin_|, return an empty origin ID. | |
73 void MediaDrmStorageImpl::Initialize(const url::Origin& origin) { | |
74 DVLOG(1) << __func__ << ": origin = " << origin; | |
75 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
76 DCHECK(!initialized_); | |
77 | |
78 initialized_ = true; | |
79 } | |
80 | |
81 void MediaDrmStorageImpl::OnProvisioned(const OnProvisionedCallback& callback) { | |
82 DVLOG(1) << __func__; | |
83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
84 | |
85 if (!initialized_) { | |
86 DVLOG(1) << __func__ << ": Not initialized."; | |
87 callback.Run(false); | |
88 return; | |
89 } | |
90 | |
91 NOTIMPLEMENTED(); | |
92 callback.Run(false); | |
93 } | |
94 | |
95 void MediaDrmStorageImpl::SavePersistentSession( | |
96 const std::string& session_id, | |
97 media::mojom::SessionDataPtr session_data, | |
98 const SavePersistentSessionCallback& callback) { | |
99 DVLOG(2) << __func__; | |
100 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
101 | |
102 if (!initialized_) { | |
103 DVLOG(1) << __func__ << ": Not initialized."; | |
104 callback.Run(false); | |
105 return; | |
106 } | |
107 | |
108 NOTIMPLEMENTED(); | |
109 callback.Run(false); | |
110 } | |
111 | |
112 void MediaDrmStorageImpl::LoadPersistentSession( | |
113 const std::string& session_id, | |
114 const LoadPersistentSessionCallback& callback) { | |
115 DVLOG(2) << __func__; | |
116 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
117 | |
118 if (!initialized_) { | |
119 DVLOG(1) << __func__ << ": Not initialized."; | |
120 callback.Run(nullptr); | |
121 return; | |
122 } | |
123 | |
124 NOTIMPLEMENTED(); | |
125 callback.Run(nullptr); | |
126 } | |
127 | |
128 void MediaDrmStorageImpl::RemovePersistentSession( | |
129 const std::string& session_id, | |
130 const RemovePersistentSessionCallback& callback) { | |
131 DVLOG(2) << __func__; | |
132 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
133 | |
134 if (!initialized_) { | |
135 DVLOG(1) << __func__ << ": Not initialized."; | |
136 callback.Run(false); | |
137 return; | |
138 } | |
139 | |
140 NOTIMPLEMENTED(); | |
141 callback.Run(false); | |
142 } | |
143 | |
144 void MediaDrmStorageImpl::RenderFrameDeleted( | |
145 content::RenderFrameHost* render_frame_host) { | |
146 if (render_frame_host == render_frame_host_) { | |
147 DVLOG(1) << __func__ << ": RenderFrame destroyed."; | |
148 Close(); | |
149 } | |
150 } | |
151 | |
152 void MediaDrmStorageImpl::DidFinishNavigation( | |
153 content::NavigationHandle* navigation_handle) { | |
154 if (navigation_handle->GetRenderFrameHost() != render_frame_host_) { | |
dcheng
2017/04/01 00:32:03
This should be ==, not != (which I think should an
xhwang
2017/04/01 00:37:02
Ah, now I know what you mean!
Done.
| |
155 DVLOG(1) << __func__ << ": Close connection on navigation."; | |
156 Close(); | |
157 } | |
158 } | |
159 | |
160 void MediaDrmStorageImpl::Close() { | |
161 DVLOG(1) << __func__; | |
162 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
163 | |
164 delete this; | |
165 } | |
166 | |
167 } // namespace cdm | |
OLD | NEW |