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

Side by Side Diff: components/nacl/renderer/pnacl_translation_resource_host.cc

Issue 1142063003: content/child: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Build fix. 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "pnacl_translation_resource_host.h" 5 #include "pnacl_translation_resource_host.h"
6 6
7 #include "components/nacl/common/nacl_host_messages.h" 7 #include "components/nacl/common/nacl_host_messages.h"
8 #include "ppapi/c/pp_errors.h" 8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/shared_impl/ppapi_globals.h" 9 #include "ppapi/shared_impl/ppapi_globals.h"
10 10
11 using ppapi::PpapiGlobals; 11 using ppapi::PpapiGlobals;
12 12
13 PnaclTranslationResourceHost::PnaclTranslationResourceHost( 13 PnaclTranslationResourceHost::PnaclTranslationResourceHost(
14 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) 14 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
15 : io_message_loop_(io_message_loop), sender_(NULL) {} 15 : io_task_runner_(io_task_runner), sender_(NULL) {
16 }
16 17
17 PnaclTranslationResourceHost::~PnaclTranslationResourceHost() { 18 PnaclTranslationResourceHost::~PnaclTranslationResourceHost() {
18 DCHECK(io_message_loop_->BelongsToCurrentThread()); 19 DCHECK(io_task_runner_->BelongsToCurrentThread());
19 CleanupCacheRequests(); 20 CleanupCacheRequests();
20 } 21 }
21 22
22 void PnaclTranslationResourceHost::OnFilterAdded(IPC::Sender* sender) { 23 void PnaclTranslationResourceHost::OnFilterAdded(IPC::Sender* sender) {
23 DCHECK(io_message_loop_->BelongsToCurrentThread()); 24 DCHECK(io_task_runner_->BelongsToCurrentThread());
24 sender_ = sender; 25 sender_ = sender;
25 } 26 }
26 27
27 void PnaclTranslationResourceHost::OnFilterRemoved() { 28 void PnaclTranslationResourceHost::OnFilterRemoved() {
28 DCHECK(io_message_loop_->BelongsToCurrentThread()); 29 DCHECK(io_task_runner_->BelongsToCurrentThread());
29 sender_ = NULL; 30 sender_ = NULL;
30 } 31 }
31 32
32 void PnaclTranslationResourceHost::OnChannelClosing() { 33 void PnaclTranslationResourceHost::OnChannelClosing() {
33 DCHECK(io_message_loop_->BelongsToCurrentThread()); 34 DCHECK(io_task_runner_->BelongsToCurrentThread());
34 sender_ = NULL; 35 sender_ = NULL;
35 } 36 }
36 37
37 bool PnaclTranslationResourceHost::OnMessageReceived( 38 bool PnaclTranslationResourceHost::OnMessageReceived(
38 const IPC::Message& message) { 39 const IPC::Message& message) {
39 DCHECK(io_message_loop_->BelongsToCurrentThread()); 40 DCHECK(io_task_runner_->BelongsToCurrentThread());
40 bool handled = true; 41 bool handled = true;
41 IPC_BEGIN_MESSAGE_MAP(PnaclTranslationResourceHost, message) 42 IPC_BEGIN_MESSAGE_MAP(PnaclTranslationResourceHost, message)
42 IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply) 43 IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply)
43 IPC_MESSAGE_UNHANDLED(handled = false) 44 IPC_MESSAGE_UNHANDLED(handled = false)
44 IPC_END_MESSAGE_MAP() 45 IPC_END_MESSAGE_MAP()
45 return handled; 46 return handled;
46 } 47 }
47 48
48 void PnaclTranslationResourceHost::RequestNexeFd( 49 void PnaclTranslationResourceHost::RequestNexeFd(
49 int render_view_id, 50 int render_view_id,
50 PP_Instance instance, 51 PP_Instance instance,
51 const nacl::PnaclCacheInfo& cache_info, 52 const nacl::PnaclCacheInfo& cache_info,
52 RequestNexeFdCallback callback) { 53 RequestNexeFdCallback callback) {
53 DCHECK(PpapiGlobals::Get()-> 54 DCHECK(PpapiGlobals::Get()->
54 GetMainThreadMessageLoop()->BelongsToCurrentThread()); 55 GetMainThreadMessageLoop()->BelongsToCurrentThread());
55 io_message_loop_->PostTask( 56 io_task_runner_->PostTask(
56 FROM_HERE, 57 FROM_HERE,
57 base::Bind(&PnaclTranslationResourceHost::SendRequestNexeFd, 58 base::Bind(&PnaclTranslationResourceHost::SendRequestNexeFd, this,
58 this, 59 render_view_id, instance, cache_info, callback));
59 render_view_id,
60 instance,
61 cache_info,
62 callback));
63 return; 60 return;
64 } 61 }
65 62
66 void PnaclTranslationResourceHost::SendRequestNexeFd( 63 void PnaclTranslationResourceHost::SendRequestNexeFd(
67 int render_view_id, 64 int render_view_id,
68 PP_Instance instance, 65 PP_Instance instance,
69 const nacl::PnaclCacheInfo& cache_info, 66 const nacl::PnaclCacheInfo& cache_info,
70 RequestNexeFdCallback callback) { 67 RequestNexeFdCallback callback) {
71 DCHECK(io_message_loop_->BelongsToCurrentThread()); 68 DCHECK(io_task_runner_->BelongsToCurrentThread());
72 if (!sender_ || !sender_->Send(new NaClHostMsg_NexeTempFileRequest( 69 if (!sender_ || !sender_->Send(new NaClHostMsg_NexeTempFileRequest(
73 render_view_id, instance, cache_info))) { 70 render_view_id, instance, cache_info))) {
74 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( 71 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
75 FROM_HERE, 72 FROM_HERE,
76 base::Bind(callback, 73 base::Bind(callback,
77 static_cast<int32_t>(PP_ERROR_FAILED), 74 static_cast<int32_t>(PP_ERROR_FAILED),
78 false, 75 false,
79 PP_kInvalidFileHandle)); 76 PP_kInvalidFileHandle));
80 return; 77 return;
81 } 78 }
82 pending_cache_requests_.insert(std::make_pair(instance, callback)); 79 pending_cache_requests_.insert(std::make_pair(instance, callback));
83 } 80 }
84 81
85 void PnaclTranslationResourceHost::ReportTranslationFinished( 82 void PnaclTranslationResourceHost::ReportTranslationFinished(
86 PP_Instance instance, 83 PP_Instance instance,
87 PP_Bool success) { 84 PP_Bool success) {
88 DCHECK(PpapiGlobals::Get()-> 85 DCHECK(PpapiGlobals::Get()->
89 GetMainThreadMessageLoop()->BelongsToCurrentThread()); 86 GetMainThreadMessageLoop()->BelongsToCurrentThread());
90 io_message_loop_->PostTask( 87 io_task_runner_->PostTask(
91 FROM_HERE, 88 FROM_HERE,
92 base::Bind(&PnaclTranslationResourceHost::SendReportTranslationFinished, 89 base::Bind(&PnaclTranslationResourceHost::SendReportTranslationFinished,
93 this, 90 this, instance, success));
94 instance,
95 success));
96 return; 91 return;
97 } 92 }
98 93
99 void PnaclTranslationResourceHost::SendReportTranslationFinished( 94 void PnaclTranslationResourceHost::SendReportTranslationFinished(
100 PP_Instance instance, 95 PP_Instance instance,
101 PP_Bool success) { 96 PP_Bool success) {
102 DCHECK(io_message_loop_->BelongsToCurrentThread()); 97 DCHECK(io_task_runner_->BelongsToCurrentThread());
103 // If the sender is closed or we have been detached, we are probably shutting 98 // If the sender is closed or we have been detached, we are probably shutting
104 // down, so just don't send anything. 99 // down, so just don't send anything.
105 if (!sender_) 100 if (!sender_)
106 return; 101 return;
107 DCHECK(pending_cache_requests_.count(instance) == 0); 102 DCHECK(pending_cache_requests_.count(instance) == 0);
108 sender_->Send(new NaClHostMsg_ReportTranslationFinished(instance, 103 sender_->Send(new NaClHostMsg_ReportTranslationFinished(instance,
109 PP_ToBool(success))); 104 PP_ToBool(success)));
110 } 105 }
111 106
112 void PnaclTranslationResourceHost::OnNexeTempFileReply( 107 void PnaclTranslationResourceHost::OnNexeTempFileReply(
113 PP_Instance instance, 108 PP_Instance instance,
114 bool is_hit, 109 bool is_hit,
115 IPC::PlatformFileForTransit file) { 110 IPC::PlatformFileForTransit file) {
116 DCHECK(io_message_loop_->BelongsToCurrentThread()); 111 DCHECK(io_task_runner_->BelongsToCurrentThread());
117 base::File base_file = IPC::PlatformFileForTransitToFile(file); 112 base::File base_file = IPC::PlatformFileForTransitToFile(file);
118 CacheRequestInfoMap::iterator it = pending_cache_requests_.find(instance); 113 CacheRequestInfoMap::iterator it = pending_cache_requests_.find(instance);
119 if (!base_file.IsValid()) { 114 if (!base_file.IsValid()) {
120 DLOG(ERROR) << "Got invalid platformfilefortransit"; 115 DLOG(ERROR) << "Got invalid platformfilefortransit";
121 } 116 }
122 if (it != pending_cache_requests_.end()) { 117 if (it != pending_cache_requests_.end()) {
123 PP_FileHandle file_handle = PP_kInvalidFileHandle; 118 PP_FileHandle file_handle = PP_kInvalidFileHandle;
124 int32_t status = PP_ERROR_FAILED; 119 int32_t status = PP_ERROR_FAILED;
125 if (base_file.IsValid()) { 120 if (base_file.IsValid()) {
126 file_handle = base_file.TakePlatformFile(); 121 file_handle = base_file.TakePlatformFile();
127 status = PP_OK; 122 status = PP_OK;
128 } 123 }
129 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( 124 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
130 FROM_HERE, 125 FROM_HERE,
131 base::Bind(it->second, status, is_hit, file_handle)); 126 base::Bind(it->second, status, is_hit, file_handle));
132 pending_cache_requests_.erase(it); 127 pending_cache_requests_.erase(it);
133 } else { 128 } else {
134 DLOG(ERROR) << "Could not find pending request for reply"; 129 DLOG(ERROR) << "Could not find pending request for reply";
135 } 130 }
136 } 131 }
137 132
138 void PnaclTranslationResourceHost::CleanupCacheRequests() { 133 void PnaclTranslationResourceHost::CleanupCacheRequests() {
139 DCHECK(io_message_loop_->BelongsToCurrentThread()); 134 DCHECK(io_task_runner_->BelongsToCurrentThread());
140 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin(); 135 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin();
141 it != pending_cache_requests_.end(); 136 it != pending_cache_requests_.end();
142 ++it) { 137 ++it) {
143 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( 138 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
144 FROM_HERE, 139 FROM_HERE,
145 base::Bind(it->second, 140 base::Bind(it->second,
146 static_cast<int32_t>(PP_ERROR_ABORTED), 141 static_cast<int32_t>(PP_ERROR_ABORTED),
147 false, 142 false,
148 PP_kInvalidFileHandle)); 143 PP_kInvalidFileHandle));
149 } 144 }
150 pending_cache_requests_.clear(); 145 pending_cache_requests_.clear();
151 } 146 }
OLDNEW
« no previous file with comments | « components/nacl/renderer/pnacl_translation_resource_host.h ('k') | components/printing/test/print_mock_render_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698