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

Side by Side Diff: content/child/webcrypto/webcrypto_impl.cc

Issue 410743002: [refactor] Replace custom utility function with base's "vector_as_array()" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase onto master Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
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/task_runner.h" 14 #include "base/task_runner.h"
14 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
15 #include "base/threading/sequenced_worker_pool.h" 16 #include "base/threading/sequenced_worker_pool.h"
16 #include "base/threading/worker_pool.h" 17 #include "base/threading/worker_pool.h"
17 #include "content/child/webcrypto/algorithm_dispatch.h" 18 #include "content/child/webcrypto/algorithm_dispatch.h"
18 #include "content/child/webcrypto/crypto_data.h" 19 #include "content/child/webcrypto/crypto_data.h"
19 #include "content/child/webcrypto/status.h" 20 #include "content/child/webcrypto/status.h"
20 #include "content/child/webcrypto/structured_clone.h" 21 #include "content/child/webcrypto/structured_clone.h"
21 #include "content/child/webcrypto/webcrypto_util.h" 22 #include "content/child/webcrypto/webcrypto_util.h"
22 #include "content/child/worker_thread_task_runner.h" 23 #include "content/child/worker_thread_task_runner.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const std::vector<uint8_t>& buffer, 113 const std::vector<uint8_t>& buffer,
113 blink::WebCryptoResult* result) { 114 blink::WebCryptoResult* result) {
114 if (status.IsError()) { 115 if (status.IsError()) {
115 CompleteWithError(status, result); 116 CompleteWithError(status, result);
116 } else { 117 } else {
117 if (buffer.size() > UINT_MAX) { 118 if (buffer.size() > UINT_MAX) {
118 // WebArrayBuffers have a smaller range than std::vector<>, so 119 // WebArrayBuffers have a smaller range than std::vector<>, so
119 // theoretically this could overflow. 120 // theoretically this could overflow.
120 CompleteWithError(Status::ErrorUnexpected(), result); 121 CompleteWithError(Status::ErrorUnexpected(), result);
121 } else { 122 } else {
122 result->completeWithBuffer(webcrypto::Uint8VectorStart(buffer), 123 result->completeWithBuffer(vector_as_array(&buffer), buffer.size());
123 buffer.size());
124 } 124 }
125 } 125 }
126 } 126 }
127 127
128 void CompleteWithKeyOrError(const Status& status, 128 void CompleteWithKeyOrError(const Status& status,
129 const blink::WebCryptoKey& key, 129 const blink::WebCryptoKey& key,
130 blink::WebCryptoResult* result) { 130 blink::WebCryptoResult* result) {
131 if (status.IsError()) { 131 if (status.IsError()) {
132 CompleteWithError(status, result); 132 CompleteWithError(status, result);
133 } else { 133 } else {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 void DoExportKeyReply(scoped_ptr<ExportKeyState> state) { 474 void DoExportKeyReply(scoped_ptr<ExportKeyState> state) {
475 if (state->format != blink::WebCryptoKeyFormatJwk) { 475 if (state->format != blink::WebCryptoKeyFormatJwk) {
476 CompleteWithBufferOrError(state->status, state->buffer, &state->result); 476 CompleteWithBufferOrError(state->status, state->buffer, &state->result);
477 return; 477 return;
478 } 478 }
479 479
480 if (state->status.IsError()) { 480 if (state->status.IsError()) {
481 CompleteWithError(state->status, &state->result); 481 CompleteWithError(state->status, &state->result);
482 } else { 482 } else {
483 state->result.completeWithJson( 483 state->result.completeWithJson(
484 reinterpret_cast<const char*>( 484 reinterpret_cast<const char*>(vector_as_array(&state->buffer)),
485 webcrypto::Uint8VectorStart(&state->buffer)),
486 state->buffer.size()); 485 state->buffer.size());
487 } 486 }
488 } 487 }
489 488
490 void DoExportKey(scoped_ptr<ExportKeyState> passed_state) { 489 void DoExportKey(scoped_ptr<ExportKeyState> passed_state) {
491 ExportKeyState* state = passed_state.get(); 490 ExportKeyState* state = passed_state.get();
492 if (state->cancelled()) 491 if (state->cancelled())
493 return; 492 return;
494 state->status = 493 state->status =
495 webcrypto::ExportKey(state->format, state->key, &state->buffer); 494 webcrypto::ExportKey(state->format, state->key, &state->buffer);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 &key); 761 &key);
763 } 762 }
764 763
765 bool WebCryptoImpl::serializeKeyForClone( 764 bool WebCryptoImpl::serializeKeyForClone(
766 const blink::WebCryptoKey& key, 765 const blink::WebCryptoKey& key,
767 blink::WebVector<unsigned char>& key_data) { 766 blink::WebVector<unsigned char>& key_data) {
768 return webcrypto::SerializeKeyForClone(key, &key_data); 767 return webcrypto::SerializeKeyForClone(key, &key_data);
769 } 768 }
770 769
771 } // namespace content 770 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/shared_crypto_unittest.cc ('k') | content/child/webcrypto/webcrypto_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698