| 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/child/webcrypto/webcrypto_impl.h" | 5 #include "content/child/webcrypto/webcrypto_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/task_runner.h" | 14 #include "base/task_runner.h" |
| 15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
| 17 #include "base/threading/worker_pool.h" | 17 #include "base/threading/worker_pool.h" |
| 18 #include "content/child/webcrypto/algorithm_dispatch.h" | 18 #include "content/child/webcrypto/algorithm_dispatch.h" |
| 19 #include "content/child/webcrypto/crypto_data.h" | 19 #include "content/child/webcrypto/crypto_data.h" |
| 20 #include "content/child/webcrypto/generate_key_result.h" | 20 #include "content/child/webcrypto/generate_key_result.h" |
| 21 #include "content/child/webcrypto/status.h" | 21 #include "content/child/webcrypto/status.h" |
| 22 #include "content/child/webcrypto/webcrypto_util.h" | 22 #include "content/child/webcrypto/webcrypto_util.h" |
| 23 #include "content/child/worker_thread_task_runner.h" | |
| 24 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 23 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
| 25 #include "third_party/WebKit/public/platform/WebString.h" | 24 #include "third_party/WebKit/public/platform/WebString.h" |
| 26 | 25 |
| 27 namespace content { | 26 namespace content { |
| 28 | 27 |
| 29 using webcrypto::Status; | 28 using webcrypto::Status; |
| 30 | 29 |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 // --------------------- | 32 // --------------------- |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 void CompleteWithKeyOrError(const Status& status, | 127 void CompleteWithKeyOrError(const Status& status, |
| 129 const blink::WebCryptoKey& key, | 128 const blink::WebCryptoKey& key, |
| 130 blink::WebCryptoResult* result) { | 129 blink::WebCryptoResult* result) { |
| 131 if (status.IsError()) { | 130 if (status.IsError()) { |
| 132 CompleteWithError(status, result); | 131 CompleteWithError(status, result); |
| 133 } else { | 132 } else { |
| 134 result->completeWithKey(key); | 133 result->completeWithKey(key); |
| 135 } | 134 } |
| 136 } | 135 } |
| 137 | 136 |
| 138 // Gets a task runner for the current thread. The current thread is either: | 137 // Gets a task runner for the current thread. |
| 139 // | |
| 140 // * The main Blink thread | |
| 141 // * A Blink web worker thread | |
| 142 // | |
| 143 // A different mechanism is needed for posting to these threads. The main | |
| 144 // thread has an associated message loop and can simply use | |
| 145 // base::ThreadTaskRunnerHandle. Whereas the web worker threads are managed by | |
| 146 // Blink and need to be indirected through WorkerThreadTaskRunner. | |
| 147 scoped_refptr<base::TaskRunner> GetCurrentBlinkThread() { | 138 scoped_refptr<base::TaskRunner> GetCurrentBlinkThread() { |
| 148 if (base::ThreadTaskRunnerHandle::IsSet()) | 139 DCHECK(base::ThreadTaskRunnerHandle::IsSet()); |
| 149 return base::ThreadTaskRunnerHandle::Get(); | 140 return base::ThreadTaskRunnerHandle::Get(); |
| 150 return WorkerThreadTaskRunner::current(); | |
| 151 } | 141 } |
| 152 | 142 |
| 153 // -------------------------------------------------------------------- | 143 // -------------------------------------------------------------------- |
| 154 // State | 144 // State |
| 155 // -------------------------------------------------------------------- | 145 // -------------------------------------------------------------------- |
| 156 // | 146 // |
| 157 // Explicit state classes are used rather than base::Bind(). This is done | 147 // Explicit state classes are used rather than base::Bind(). This is done |
| 158 // both for clarity, but also to avoid extraneous allocations for things | 148 // both for clarity, but also to avoid extraneous allocations for things |
| 159 // like passing buffers and result objects between threads. | 149 // like passing buffers and result objects between threads. |
| 160 // | 150 // |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 webcrypto::CryptoData(key_data, key_data_size), &key); | 782 webcrypto::CryptoData(key_data, key_data_size), &key); |
| 793 } | 783 } |
| 794 | 784 |
| 795 bool WebCryptoImpl::serializeKeyForClone( | 785 bool WebCryptoImpl::serializeKeyForClone( |
| 796 const blink::WebCryptoKey& key, | 786 const blink::WebCryptoKey& key, |
| 797 blink::WebVector<unsigned char>& key_data) { | 787 blink::WebVector<unsigned char>& key_data) { |
| 798 return webcrypto::SerializeKeyForClone(key, &key_data); | 788 return webcrypto::SerializeKeyForClone(key, &key_data); |
| 799 } | 789 } |
| 800 | 790 |
| 801 } // namespace content | 791 } // namespace content |
| OLD | NEW |