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

Side by Side Diff: content/browser/presentation/presentation_service_impl.cc

Issue 1140713005: [PresentationAPI] Implements send API for Blob data from WebPresentationClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated unit tests Created 5 years, 7 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/presentation/presentation_service_impl.h" 5 #include "content/browser/presentation/presentation_service_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "content/browser/presentation/presentation_type_converters.h" 10 #include "content/browser/presentation/presentation_type_converters.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 output->data.Swap(input->data.get()); 42 output->data.Swap(input->data.get());
43 } else { 43 } else {
44 // string message 44 // string message
45 output->type = 45 output->type =
46 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; 46 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT;
47 output->message.Swap(input->message.get()); 47 output->message.Swap(input->message.get());
48 } 48 }
49 return output.Pass(); 49 return output.Pass();
50 } 50 }
51 51
52 content::PresentationMessageType GetMessageTypeFromMojo(
53 presentation::PresentationMessageType mojoPresentationMessageType) {
54 switch (mojoPresentationMessageType) {
55 case presentation::PRESENTATION_MESSAGE_TYPE_TEXT:
56 return content::PresentationMessageType::TEXT;
57 case presentation::PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER:
58 return content::PresentationMessageType::ARRAY_BUFFER;
59 case presentation::PRESENTATION_MESSAGE_TYPE_BLOB:
60 return content::PresentationMessageType::BLOB;
61 }
62 NOTREACHED();
63 return content::PresentationMessageType::ARRAY_BUFFER;
64 }
65
52 scoped_ptr<content::PresentationSessionMessage> GetPresentationSessionMessage( 66 scoped_ptr<content::PresentationSessionMessage> GetPresentationSessionMessage(
53 presentation::SessionMessagePtr input) { 67 presentation::SessionMessagePtr input) {
54 DCHECK(!input.is_null()); 68 DCHECK(!input.is_null());
55 scoped_ptr<content::PresentationSessionMessage> output; 69 scoped_ptr<content::PresentationSessionMessage> output;
56 if (input->type == presentation::PresentationMessageType:: 70 if (input->type == presentation::PresentationMessageType::
57 PRESENTATION_MESSAGE_TYPE_TEXT) { 71 PRESENTATION_MESSAGE_TYPE_TEXT) {
58 DCHECK(!input->message.is_null()); 72 DCHECK(!input->message.is_null());
59 DCHECK(input->data.is_null()); 73 DCHECK(input->data.is_null());
60 // Return null PresentationSessionMessage if size exceeds. 74 // Return null PresentationSessionMessage if size exceeds.
61 if (input->message.size() > content::kMaxPresentationSessionMessageSize) 75 if (input->message.size() > content::kMaxPresentationSessionMessageSize)
62 return output.Pass(); 76 return output.Pass();
63 77
64 output = content::PresentationSessionMessage::CreateStringMessage( 78 output = content::PresentationSessionMessage::CreateStringMessage(
65 input->presentation_url, 79 input->presentation_url,
66 input->presentation_id, 80 input->presentation_id,
67 make_scoped_ptr(new std::string)); 81 make_scoped_ptr(new std::string));
68 input->message.Swap(output->message.get()); 82 input->message.Swap(output->message.get());
69 83
70 } else if (input->type == presentation::PresentationMessageType:: 84 } else {
71 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER) { 85 // ArrayBuffer or Blob data.
mark a. foltz 2015/06/02 23:51:02 Prefer using switch() statement with NOTREACHED so
USE s.singapati at gmail.com 2015/06/03 15:03:50 Done.
72 DCHECK(!input->data.is_null()); 86 DCHECK(!input->data.is_null());
73 DCHECK(input->message.is_null()); 87 DCHECK(input->message.is_null());
74 // Return null PresentationSessionMessage if size exceeds. 88 // Return null PresentationSessionMessage if size exceeds.
75 if (input->data.size() > content::kMaxPresentationSessionMessageSize) 89 if (input->data.size() > content::kMaxPresentationSessionMessageSize)
76 return output.Pass(); 90 return output.Pass();
77 91
78 output = content::PresentationSessionMessage::CreateBinaryMessage( 92 output = content::PresentationSessionMessage::CreateBinaryMessage(
79 input->presentation_url, 93 input->presentation_url,
80 input->presentation_id, 94 input->presentation_id,
81 make_scoped_ptr(new std::vector<uint8_t>)); 95 make_scoped_ptr(new std::vector<uint8_t>),
96 GetMessageTypeFromMojo(input->type));
82 input->data.Swap(output->data.get()); 97 input->data.Swap(output->data.get());
83 } 98 }
84 99
85 return output.Pass(); 100 return output.Pass();
86 } 101 }
87 102
88 void InvokeNewSessionMojoCallbackWithError( 103 void InvokeNewSessionMojoCallbackWithError(
89 const NewSessionMojoCallback& callback) { 104 const NewSessionMojoCallback& callback) {
90 callback.Run( 105 callback.Run(
91 presentation::PresentationSessionInfoPtr(), 106 presentation::PresentationSessionInfoPtr(),
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { 680 void PresentationServiceImpl::DefaultSessionStartContext::Reset() {
666 ScopedVector<DefaultSessionMojoCallback> callbacks; 681 ScopedVector<DefaultSessionMojoCallback> callbacks;
667 callbacks.swap(callbacks_); 682 callbacks.swap(callbacks_);
668 for (const auto& callback : callbacks) 683 for (const auto& callback : callbacks)
669 callback->Run(presentation::PresentationSessionInfoPtr()); 684 callback->Run(presentation::PresentationSessionInfoPtr());
670 session_.reset(); 685 session_.reset();
671 } 686 }
672 687
673 } // namespace content 688 } // namespace content
674 689
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698