Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/media/cdm/browser_cdm_manager.h" | 5 #include "content/browser/media/cdm/browser_cdm_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
| 13 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/content_browser_client.h" | 15 #include "content/public/browser/content_browser_client.h" |
| 16 #include "content/public/browser/permission_manager.h" | 16 #include "content/public/browser/permission_manager.h" |
| 17 #include "content/public/browser/permission_type.h" | 17 #include "content/public/browser/permission_type.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_process_host_observer.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "media/base/browser_cdm.h" | 22 #include "media/base/browser_cdm.h" |
| 23 #include "media/base/browser_cdm_factory.h" | 23 #include "media/base/browser_cdm_factory.h" |
| 24 #include "media/base/cdm_promise.h" | 24 #include "media/base/cdm_promise.h" |
| 25 #include "media/base/limits.h" | 25 #include "media/base/limits.h" |
| 26 | 26 |
| 27 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) |
| 28 #include "content/public/common/renderer_preferences.h" | 28 #include "content/public/common/renderer_preferences.h" |
| 29 #endif | 29 #endif |
| 30 | 30 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 template <> | 98 template <> |
| 99 void CdmPromiseInternal<std::string>::resolve(const std::string& session_id) { | 99 void CdmPromiseInternal<std::string>::resolve(const std::string& session_id) { |
| 100 MarkPromiseSettled(); | 100 MarkPromiseSettled(); |
| 101 manager_->ResolvePromiseWithSession(render_frame_id_, cdm_id_, promise_id_, | 101 manager_->ResolvePromiseWithSession(render_frame_id_, cdm_id_, promise_id_, |
| 102 session_id); | 102 session_id); |
| 103 } | 103 } |
| 104 | 104 |
| 105 typedef CdmPromiseInternal<> SimplePromise; | 105 typedef CdmPromiseInternal<> SimplePromise; |
| 106 typedef CdmPromiseInternal<std::string> NewSessionPromise; | 106 typedef CdmPromiseInternal<std::string> NewSessionPromise; |
| 107 | 107 |
| 108 } // namespace | |
| 109 | |
| 110 // Render process ID to BrowserCdmManager map. | 108 // Render process ID to BrowserCdmManager map. |
| 111 typedef std::map<int, BrowserCdmManager*> BrowserCdmManagerMap; | 109 typedef std::map<int, BrowserCdmManager*> BrowserCdmManagerMap; |
| 112 base::LazyInstance<BrowserCdmManagerMap>::Leaky g_browser_cdm_manager_map = | 110 base::LazyInstance<BrowserCdmManagerMap>::Leaky g_browser_cdm_manager_map = |
| 113 LAZY_INSTANCE_INITIALIZER; | 111 LAZY_INSTANCE_INITIALIZER; |
| 114 | 112 |
|
ncarter (slow)
2015/07/08 20:56:31
We should probably add a comment here along the li
xhwang
2015/07/08 22:15:30
Done.
| |
| 113 class BrowserCdmManagerProcessWatcher : public RenderProcessHostObserver { | |
| 114 public: | |
| 115 BrowserCdmManagerProcessWatcher( | |
| 116 int render_process_id, | |
| 117 const scoped_refptr<BrowserCdmManager>& manager) | |
| 118 : browser_cdm_manager_(manager) { | |
| 119 RenderProcessHost::FromID(render_process_id)->AddObserver(this); | |
| 120 CHECK(g_browser_cdm_manager_map.Get() | |
| 121 .insert(std::make_pair(render_process_id, manager.get())) | |
| 122 .second); | |
| 123 } | |
| 124 | |
| 125 // RenderProcessHostObserver: | |
| 126 virtual void RenderProcessExited(RenderProcessHost* host, | |
| 127 base::TerminationStatus /* status */, | |
| 128 int /* exit_code */) { | |
| 129 Destroy(host); | |
| 130 } | |
| 131 | |
| 132 virtual void RenderProcessHostDestroyed(RenderProcessHost* host) { | |
| 133 Destroy(host); | |
| 134 } | |
| 135 | |
| 136 private: | |
| 137 void Destroy(RenderProcessHost* host) { | |
| 138 CHECK(g_browser_cdm_manager_map.Get().erase(host->GetID())); | |
| 139 host->RemoveObserver(this); | |
| 140 delete this; | |
| 141 } | |
| 142 | |
| 143 const scoped_refptr<BrowserCdmManager> browser_cdm_manager_; | |
| 144 }; | |
| 145 | |
| 146 } // namespace | |
| 147 | |
| 148 // static | |
| 115 BrowserCdmManager* BrowserCdmManager::FromProcess(int render_process_id) { | 149 BrowserCdmManager* BrowserCdmManager::FromProcess(int render_process_id) { |
| 116 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 150 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 117 | 151 auto& map = g_browser_cdm_manager_map.Get(); |
| 118 if (!g_browser_cdm_manager_map.Get().count(render_process_id)) | 152 auto iterator = map.find(render_process_id); |
| 119 return NULL; | 153 return (iterator == map.end()) ? nullptr : iterator->second; |
| 120 | |
| 121 return g_browser_cdm_manager_map.Get()[render_process_id]; | |
| 122 } | 154 } |
| 123 | 155 |
| 124 BrowserCdmManager::BrowserCdmManager( | 156 BrowserCdmManager::BrowserCdmManager( |
| 125 int render_process_id, | 157 int render_process_id, |
| 126 const scoped_refptr<base::TaskRunner>& task_runner) | 158 const scoped_refptr<base::TaskRunner>& task_runner) |
| 127 : BrowserMessageFilter(CdmMsgStart), | 159 : BrowserMessageFilter(CdmMsgStart), |
| 128 render_process_id_(render_process_id), | 160 render_process_id_(render_process_id), |
| 129 task_runner_(task_runner), | 161 task_runner_(task_runner), |
| 130 weak_ptr_factory_(this) { | 162 weak_ptr_factory_(this) { |
| 131 DVLOG(1) << __FUNCTION__ << ": " << render_process_id_; | 163 DVLOG(1) << __FUNCTION__ << ": " << render_process_id_; |
| 132 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 164 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 133 | 165 |
| 166 new BrowserCdmManagerProcessWatcher(render_process_id, this); | |
| 167 | |
| 134 if (!task_runner_.get()) { | 168 if (!task_runner_.get()) { |
| 135 task_runner_ = | 169 task_runner_ = |
| 136 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | 170 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
| 137 } | 171 } |
| 138 | |
| 139 DCHECK(!g_browser_cdm_manager_map.Get().count(render_process_id_)) | |
| 140 << render_process_id_; | |
| 141 g_browser_cdm_manager_map.Get()[render_process_id] = this; | |
| 142 } | 172 } |
| 143 | 173 |
| 144 BrowserCdmManager::~BrowserCdmManager() { | 174 BrowserCdmManager::~BrowserCdmManager() { |
| 145 DVLOG(1) << __FUNCTION__ << ": " << render_process_id_; | 175 DVLOG(1) << __FUNCTION__ << ": " << render_process_id_; |
| 146 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 176 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 147 DCHECK(g_browser_cdm_manager_map.Get().count(render_process_id_)); | 177 DCHECK(g_browser_cdm_manager_map.Get().count(render_process_id_) == 0); |
| 148 DCHECK_EQ(this, g_browser_cdm_manager_map.Get()[render_process_id_]); | |
| 149 | |
| 150 g_browser_cdm_manager_map.Get().erase(render_process_id_); | |
| 151 } | 178 } |
| 152 | 179 |
| 153 // Makes sure BrowserCdmManager is always deleted on the Browser UI thread. | 180 // Makes sure BrowserCdmManager is always deleted on the Browser UI thread. |
| 154 void BrowserCdmManager::OnDestruct() const { | 181 void BrowserCdmManager::OnDestruct() const { |
| 155 DVLOG(1) << __FUNCTION__ << ": " << render_process_id_; | 182 DVLOG(1) << __FUNCTION__ << ": " << render_process_id_; |
| 156 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 183 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 157 delete this; | 184 delete this; |
| 158 } else { | 185 } else { |
| 159 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | 186 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| 160 } | 187 } |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 645 BrowserCdm* cdm = GetCdm(render_frame_id, cdm_id); | 672 BrowserCdm* cdm = GetCdm(render_frame_id, cdm_id); |
| 646 if (!cdm) { | 673 if (!cdm) { |
| 647 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); | 674 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); |
| 648 return; | 675 return; |
| 649 } | 676 } |
| 650 | 677 |
| 651 cdm->LoadSession(session_type, session_id, promise.Pass()); | 678 cdm->LoadSession(session_type, session_id, promise.Pass()); |
| 652 } | 679 } |
| 653 | 680 |
| 654 } // namespace content | 681 } // namespace content |
| OLD | NEW |