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

Side by Side Diff: ppapi/proxy/message_handler.cc

Issue 1864293002: Convert //ppapi to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more nullptr Created 4 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
« no previous file with comments | « ppapi/proxy/message_handler.h ('k') | ppapi/proxy/nacl_message_scanner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ppapi/proxy/message_handler.h" 5 #include "ppapi/proxy/message_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 18 matching lines...) Expand all
29 void* user_data, 29 void* user_data,
30 ScopedPPVar message_data) { 30 ScopedPPVar message_data) {
31 CallWhileUnlocked(function, instance, user_data, 31 CallWhileUnlocked(function, instance, user_data,
32 &message_data.get()); 32 &message_data.get());
33 } 33 }
34 34
35 void HandleBlockingMessageWrapper(HandleBlockingMessageFunc function, 35 void HandleBlockingMessageWrapper(HandleBlockingMessageFunc function,
36 PP_Instance instance, 36 PP_Instance instance,
37 void* user_data, 37 void* user_data,
38 ScopedPPVar message_data, 38 ScopedPPVar message_data,
39 scoped_ptr<IPC::Message> reply_msg) { 39 std::unique_ptr<IPC::Message> reply_msg) {
40 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 40 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
41 if (!dispatcher) 41 if (!dispatcher)
42 return; 42 return;
43 PP_Var result = PP_MakeUndefined(); 43 PP_Var result = PP_MakeUndefined();
44 MessageLoopResource::GetCurrent()-> 44 MessageLoopResource::GetCurrent()->
45 set_currently_handling_blocking_message(true); 45 set_currently_handling_blocking_message(true);
46 CallWhileUnlocked( 46 CallWhileUnlocked(
47 function, instance, user_data, &message_data.get(), &result); 47 function, instance, user_data, &message_data.get(), &result);
48 MessageLoopResource::GetCurrent()-> 48 MessageLoopResource::GetCurrent()->
49 set_currently_handling_blocking_message(false); 49 set_currently_handling_blocking_message(false);
50 PpapiMsg_PPPMessageHandler_HandleBlockingMessage::WriteReplyParams( 50 PpapiMsg_PPPMessageHandler_HandleBlockingMessage::WriteReplyParams(
51 reply_msg.get(), 51 reply_msg.get(),
52 SerializedVarReturnValue::Convert(dispatcher, result), 52 SerializedVarReturnValue::Convert(dispatcher, result),
53 true /* was_handled */); 53 true /* was_handled */);
54 dispatcher->Send(reply_msg.release()); 54 dispatcher->Send(reply_msg.release());
55 } 55 }
56 56
57 } // namespace 57 } // namespace
58 58
59 // static 59 // static
60 scoped_ptr<MessageHandler> MessageHandler::Create( 60 std::unique_ptr<MessageHandler> MessageHandler::Create(
61 PP_Instance instance, 61 PP_Instance instance,
62 const PPP_MessageHandler_0_2* handler_if, 62 const PPP_MessageHandler_0_2* handler_if,
63 void* user_data, 63 void* user_data,
64 PP_Resource message_loop, 64 PP_Resource message_loop,
65 int32_t* error) { 65 int32_t* error) {
66 scoped_ptr<MessageHandler> result; 66 std::unique_ptr<MessageHandler> result;
67 // The interface and all function pointers must be valid. 67 // The interface and all function pointers must be valid.
68 if (!handler_if || 68 if (!handler_if ||
69 !handler_if->HandleMessage || 69 !handler_if->HandleMessage ||
70 !handler_if->HandleBlockingMessage || 70 !handler_if->HandleBlockingMessage ||
71 !handler_if->Destroy) { 71 !handler_if->Destroy) {
72 *error = PP_ERROR_BADARGUMENT; 72 *error = PP_ERROR_BADARGUMENT;
73 return result; 73 return result;
74 } 74 }
75 thunk::EnterResourceNoLock<thunk::PPB_MessageLoop_API> 75 thunk::EnterResourceNoLock<thunk::PPB_MessageLoop_API>
76 enter_loop(message_loop, true); 76 enter_loop(message_loop, true);
(...skipping 29 matching lines...) Expand all
106 return !!message_loop_->task_runner().get(); 106 return !!message_loop_->task_runner().get();
107 } 107 }
108 108
109 void MessageHandler::HandleMessage(ScopedPPVar var) { 109 void MessageHandler::HandleMessage(ScopedPPVar var) {
110 message_loop_->task_runner()->PostTask( 110 message_loop_->task_runner()->PostTask(
111 FROM_HERE, RunWhileLocked(base::Bind(&HandleMessageWrapper, 111 FROM_HERE, RunWhileLocked(base::Bind(&HandleMessageWrapper,
112 handler_if_->HandleMessage, 112 handler_if_->HandleMessage,
113 instance_, user_data_, var))); 113 instance_, user_data_, var)));
114 } 114 }
115 115
116 void MessageHandler::HandleBlockingMessage(ScopedPPVar var, 116 void MessageHandler::HandleBlockingMessage(
117 scoped_ptr<IPC::Message> reply_msg) { 117 ScopedPPVar var,
118 std::unique_ptr<IPC::Message> reply_msg) {
118 message_loop_->task_runner()->PostTask( 119 message_loop_->task_runner()->PostTask(
119 FROM_HERE, 120 FROM_HERE,
120 RunWhileLocked(base::Bind( 121 RunWhileLocked(base::Bind(
121 &HandleBlockingMessageWrapper, handler_if_->HandleBlockingMessage, 122 &HandleBlockingMessageWrapper, handler_if_->HandleBlockingMessage,
122 instance_, user_data_, var, base::Passed(std::move(reply_msg))))); 123 instance_, user_data_, var, base::Passed(std::move(reply_msg)))));
123 } 124 }
124 125
125 MessageHandler::MessageHandler( 126 MessageHandler::MessageHandler(
126 PP_Instance instance, 127 PP_Instance instance,
127 const PPP_MessageHandler_0_2* handler_if, 128 const PPP_MessageHandler_0_2* handler_if,
128 void* user_data, 129 void* user_data,
129 scoped_refptr<MessageLoopResource> message_loop) 130 scoped_refptr<MessageLoopResource> message_loop)
130 : instance_(instance), 131 : instance_(instance),
131 handler_if_(handler_if), 132 handler_if_(handler_if),
132 user_data_(user_data), 133 user_data_(user_data),
133 message_loop_(message_loop) { 134 message_loop_(message_loop) {
134 } 135 }
135 136
136 } // namespace proxy 137 } // namespace proxy
137 } // namespace ppapi 138 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/message_handler.h ('k') | ppapi/proxy/nacl_message_scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698