[M108 Aura Migration][NaCl][PPFwk] Add error logs + SVACE/DLOG/Static analysis fix
[platform/framework/web/chromium-efl.git] / content / renderer / pepper / audio_helper.cc
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/renderer/pepper/audio_helper.h"
6
7 #include <memory>
8
9 #include "base/check.h"
10 #include "base/logging.h"
11 #include "content/common/pepper_file_util.h"
12 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_errors.h"
14
15 using ppapi::TrackedCallback;
16
17 namespace content {
18
19 // AudioHelper -----------------------------------------------------------------
20
21 AudioHelper::AudioHelper() {}
22
23 AudioHelper::~AudioHelper() {}
24
25 int32_t AudioHelper::GetSyncSocketImpl(int* sync_socket) {
26   if (socket_for_create_callback_) {
27     *sync_socket = IntegerFromSyncSocketHandle(
28         socket_for_create_callback_->handle());
29     return PP_OK;
30   }
31   LOG(ERROR) << "Cannot get sync socket";
32   return PP_ERROR_FAILED;
33 }
34
35 int32_t AudioHelper::GetSharedMemoryImpl(base::UnsafeSharedMemoryRegion** shm) {
36   if (shared_memory_for_create_callback_.IsValid()) {
37     *shm = &shared_memory_for_create_callback_;
38     return PP_OK;
39   }
40   LOG(ERROR) << "Cannot get shared memory";
41   return PP_ERROR_FAILED;
42 }
43
44 void AudioHelper::StreamCreated(
45     base::UnsafeSharedMemoryRegion shared_memory_region,
46     base::SyncSocket::ScopedHandle socket_handle) {
47   if (TrackedCallback::IsPending(create_callback_)) {
48     // Trusted side of proxy can specify a callback to receive handles. In
49     // this case we don't need to map any data or start the thread since it
50     // will be handled by the proxy.
51     shared_memory_for_create_callback_ = std::move(shared_memory_region);
52     socket_for_create_callback_ =
53         std::make_unique<base::SyncSocket>(std::move(socket_handle));
54
55     create_callback_->Run(PP_OK);
56
57     // It might be nice to close the handles here to free up some system
58     // resources, but we can't since there's a race condition. The handles must
59     // be valid until they're sent over IPC, which is done from the I/O thread
60     // which will often get done after this code executes. We could do
61     // something more elaborate like an ACK from the plugin or post a task to
62     // the I/O thread and back, but this extra complexity doesn't seem worth it
63     // just to clean up these handles faster.
64   } else {
65     OnSetStreamInfo(std::move(shared_memory_region), std::move(socket_handle));
66   }
67 }
68
69 void AudioHelper::SetCreateCallback(
70     scoped_refptr<ppapi::TrackedCallback> create_callback) {
71   DCHECK(!TrackedCallback::IsPending(create_callback_));
72   create_callback_ = create_callback;
73 }
74
75 }  // namespace content