Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: components/cdm/browser/media_drm_storage_impl.cc

Issue 2765343003: media: Add MediaDrmStorage (Closed)
Patch Set: media: Add MediaDrmStorage Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // The |origin| comes from a renderer process and cannot be trusted.
79 if (!origin_.IsSameOriginWith(origin)) {
dcheng 2017/03/31 18:01:56 Nit: as mentioned yesterday, let's remove the orig
xhwang 2017/03/31 18:25:37 Done.
80 DVLOG(1) << __func__ << ": Origin mismatch " << origin_ << " vs " << origin;
81 Close();
82 return;
83 }
84
85 initialized_ = true;
86 }
87
88 void MediaDrmStorageImpl::OnProvisioned(const OnProvisionedCallback& callback) {
89 DVLOG(1) << __func__;
90 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
91
92 if (!initialized_) {
93 DVLOG(1) << __func__ << ": Not initialized.";
94 callback.Run(false);
95 return;
96 }
97
98 NOTIMPLEMENTED();
99 callback.Run(false);
100 }
101
102 void MediaDrmStorageImpl::SavePersistentSession(
103 const std::string& session_id,
104 media::mojom::SessionDataPtr session_data,
105 const SavePersistentSessionCallback& callback) {
106 DVLOG(2) << __func__;
107 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
108
109 if (!initialized_) {
110 DVLOG(1) << __func__ << ": Not initialized.";
111 callback.Run(false);
112 return;
113 }
114
115 NOTIMPLEMENTED();
116 callback.Run(false);
117 }
118
119 void MediaDrmStorageImpl::LoadPersistentSession(
120 const std::string& session_id,
121 const LoadPersistentSessionCallback& callback) {
122 DVLOG(2) << __func__;
123 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
124
125 if (!initialized_) {
126 DVLOG(1) << __func__ << ": Not initialized.";
127 callback.Run(nullptr);
128 return;
129 }
130
131 NOTIMPLEMENTED();
132 callback.Run(nullptr);
133 }
134
135 void MediaDrmStorageImpl::RemovePersistentSession(
136 const std::string& session_id,
137 const RemovePersistentSessionCallback& callback) {
138 DVLOG(2) << __func__;
139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
140
141 if (!initialized_) {
142 DVLOG(1) << __func__ << ": Not initialized.";
143 callback.Run(false);
144 return;
145 }
146
147 NOTIMPLEMENTED();
148 callback.Run(false);
149 }
150
151 void MediaDrmStorageImpl::RenderFrameDeleted(
152 content::RenderFrameHost* render_frame_host) {
153 if (render_frame_host == render_frame_host_) {
154 DVLOG(1) << __func__ << ": RenderFrame destroyed.";
155 Close();
156 }
157 }
158
159 void MediaDrmStorageImpl::DidFinishNavigation(
160 content::NavigationHandle* navigation_handle) {
161 if (!origin_.IsSameOriginWith(url::Origin(navigation_handle->GetURL()))) {
dcheng 2017/03/31 18:01:56 1) I think this should be checking that navigation
xhwang 2017/03/31 18:25:37 Done. But is it possible that after navigation we
162 DVLOG(1) << __func__ << ": Close connection on navigation.";
163 Close();
164 }
165 }
166
167 void MediaDrmStorageImpl::Close() {
168 DVLOG(1) << __func__;
169 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
170
171 Observe(nullptr);
dcheng 2017/03/31 18:01:56 This is unnecessary: WebContentsObserver unobserve
xhwang 2017/03/31 18:25:37 Done. I actually saw this pattern in a few places
172 delete this;
173 }
174
175 } // namespace cdm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698