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

Side by Side Diff: remoting/host/plugin/host_script_object.cc

Issue 7355011: Modify Chromoting logging to hook into base logging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add timestamp Created 9 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "remoting/host/plugin/host_script_object.h" 5 #include "remoting/host/plugin/host_script_object.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/task.h" 9 #include "base/task.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
11 #include "remoting/base/auth_token_util.h" 11 #include "remoting/base/auth_token_util.h"
12 #include "remoting/base/util.h"
12 #include "remoting/host/chromoting_host.h" 13 #include "remoting/host/chromoting_host.h"
13 #include "remoting/host/chromoting_host_context.h" 14 #include "remoting/host/chromoting_host_context.h"
14 #include "remoting/host/host_config.h" 15 #include "remoting/host/host_config.h"
15 #include "remoting/host/host_key_pair.h" 16 #include "remoting/host/host_key_pair.h"
16 #include "remoting/host/in_memory_host_config.h" 17 #include "remoting/host/in_memory_host_config.h"
17 #include "remoting/host/plugin/host_plugin_utils.h" 18 #include "remoting/host/plugin/host_plugin_utils.h"
18 #include "remoting/host/register_support_host_request.h" 19 #include "remoting/host/register_support_host_request.h"
19 #include "remoting/host/support_access_verifier.h" 20 #include "remoting/host/support_access_verifier.h"
20 21
21 namespace remoting { 22 namespace remoting {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 const char* kAttrNameRequestedAccessCode = "REQUESTED_ACCESS_CODE"; 56 const char* kAttrNameRequestedAccessCode = "REQUESTED_ACCESS_CODE";
56 const char* kAttrNameReceivedAccessCode = "RECEIVED_ACCESS_CODE"; 57 const char* kAttrNameReceivedAccessCode = "RECEIVED_ACCESS_CODE";
57 const char* kAttrNameConnected = "CONNECTED"; 58 const char* kAttrNameConnected = "CONNECTED";
58 const char* kAttrNameAffirmingConnection = "AFFIRMING_CONNECTION"; 59 const char* kAttrNameAffirmingConnection = "AFFIRMING_CONNECTION";
59 const char* kAttrNameError = "ERROR"; 60 const char* kAttrNameError = "ERROR";
60 61
61 const int kMaxLoginAttempts = 5; 62 const int kMaxLoginAttempts = 5;
62 63
63 } // namespace 64 } // namespace
64 65
66 // This flag blocks LOGs to the UI if we're already in the middle of logging
67 // to the UI. This prevents a potential infinite loop if we encounter an error
68 // while sending the log message to the UI.
69 static bool logging_to_plugin_ = false;
dmac 2011/07/21 23:37:07 again, should these be prefixed with a g? and they
garykac 2011/08/02 00:15:37 Done.
70 static HostNPScriptObject* logging_scriptable_object_ = NULL;
71 static logging::LogMessageHandlerFunction logging_old_handler_ = NULL;
72
65 HostNPScriptObject::HostNPScriptObject(NPP plugin, NPObject* parent) 73 HostNPScriptObject::HostNPScriptObject(NPP plugin, NPObject* parent)
66 : plugin_(plugin), 74 : plugin_(plugin),
67 parent_(parent), 75 parent_(parent),
68 state_(kDisconnected), 76 state_(kDisconnected),
69 log_debug_info_func_(NULL), 77 log_debug_info_func_(NULL),
70 on_state_changed_func_(NULL), 78 on_state_changed_func_(NULL),
71 np_thread_id_(base::PlatformThread::CurrentId()), 79 np_thread_id_(base::PlatformThread::CurrentId()),
72 failed_login_attempts_(0), 80 failed_login_attempts_(0),
73 disconnected_event_(true, false) { 81 disconnected_event_(true, false) {
74 logger_.reset(new HostPluginLogger(this)); 82 logging_old_handler_ = logging::GetLogMessageHandler();
dmac 2011/07/21 23:37:07 Is this not assuming that HostNPScriptObject is on
garykac 2011/08/02 00:15:37 No, er.. yes. It's not not assuming... I mean it
75 logger_->VLog(2, "HostNPScriptObject"); 83 logging::SetLogMessageHandler(&LogToUI);
84 logging_scriptable_object_ = this;
85
86 VLOG(2) << "HostNPScriptObject";
76 host_context_.SetUITaskPostFunction(base::Bind( 87 host_context_.SetUITaskPostFunction(base::Bind(
77 &HostNPScriptObject::PostTaskToNPThread, base::Unretained(this))); 88 &HostNPScriptObject::PostTaskToNPThread, base::Unretained(this)));
78 } 89 }
79 90
80 HostNPScriptObject::~HostNPScriptObject() { 91 HostNPScriptObject::~HostNPScriptObject() {
81 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 92 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
82 93
94 logging::SetLogMessageHandler(logging_old_handler_);
95 logging_old_handler_ = NULL;
96 logging_scriptable_object_ = NULL;
97
83 // Disconnect synchronously. We cannot disconnect asynchronously 98 // Disconnect synchronously. We cannot disconnect asynchronously
84 // here because |host_context_| needs to be stopped on the plugin 99 // here because |host_context_| needs to be stopped on the plugin
85 // thread, but the plugin thread may not exist after the instance 100 // thread, but the plugin thread may not exist after the instance
86 // is destroyed. 101 // is destroyed.
87 destructing_.Set(); 102 destructing_.Set();
88 disconnected_event_.Reset(); 103 disconnected_event_.Reset();
89 DisconnectInternal(); 104 DisconnectInternal();
90 disconnected_event_.Wait(); 105 disconnected_event_.Wait();
91 106
92 host_context_.Stop(); 107 host_context_.Stop();
93 if (log_debug_info_func_) { 108 if (log_debug_info_func_) {
94 g_npnetscape_funcs->releaseobject(log_debug_info_func_); 109 g_npnetscape_funcs->releaseobject(log_debug_info_func_);
95 } 110 }
96 if (on_state_changed_func_) { 111 if (on_state_changed_func_) {
97 g_npnetscape_funcs->releaseobject(on_state_changed_func_); 112 g_npnetscape_funcs->releaseobject(on_state_changed_func_);
98 } 113 }
99 } 114 }
100 115
101 bool HostNPScriptObject::Init() { 116 bool HostNPScriptObject::Init() {
102 logger_->VLog(2, "Init"); 117 VLOG(2) << "Init";
103 // TODO(wez): This starts a bunch of threads, which might fail. 118 // TODO(wez): This starts a bunch of threads, which might fail.
104 host_context_.Start(); 119 host_context_.Start();
105 return true; 120 return true;
106 } 121 }
107 122
108 bool HostNPScriptObject::HasMethod(const std::string& method_name) { 123 bool HostNPScriptObject::HasMethod(const std::string& method_name) {
109 logger_->VLog(2, "HasMethod %s", method_name.c_str()); 124 VLOG(2) << "HasMethod " << method_name;
110 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 125 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
111 return (method_name == kFuncNameConnect || 126 return (method_name == kFuncNameConnect ||
112 method_name == kFuncNameDisconnect); 127 method_name == kFuncNameDisconnect);
113 } 128 }
114 129
115 bool HostNPScriptObject::InvokeDefault(const NPVariant* args, 130 bool HostNPScriptObject::InvokeDefault(const NPVariant* args,
116 uint32_t argCount, 131 uint32_t argCount,
117 NPVariant* result) { 132 NPVariant* result) {
118 logger_->VLog(2, "InvokeDefault"); 133 VLOG(2) << "InvokeDefault";
119 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 134 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
120 SetException("exception during default invocation"); 135 SetException("exception during default invocation");
121 return false; 136 return false;
122 } 137 }
123 138
124 bool HostNPScriptObject::Invoke(const std::string& method_name, 139 bool HostNPScriptObject::Invoke(const std::string& method_name,
125 const NPVariant* args, 140 const NPVariant* args,
126 uint32_t argCount, 141 uint32_t argCount,
127 NPVariant* result) { 142 NPVariant* result) {
128 logger_->VLog(2, "Invoke %s", method_name.c_str()); 143 VLOG(2) << "Invoke " << method_name;
129 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 144 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
130 if (method_name == kFuncNameConnect) { 145 if (method_name == kFuncNameConnect) {
131 return Connect(args, argCount, result); 146 return Connect(args, argCount, result);
132 } else if (method_name == kFuncNameDisconnect) { 147 } else if (method_name == kFuncNameDisconnect) {
133 return Disconnect(args, argCount, result); 148 return Disconnect(args, argCount, result);
134 } else { 149 } else {
135 SetException("Invoke: unknown method " + method_name); 150 SetException("Invoke: unknown method " + method_name);
136 return false; 151 return false;
137 } 152 }
138 } 153 }
139 154
140 bool HostNPScriptObject::HasProperty(const std::string& property_name) { 155 bool HostNPScriptObject::HasProperty(const std::string& property_name) {
141 logger_->VLog(2, "HasProperty %s", property_name.c_str()); 156 VLOG(2) << "HasProperty " << property_name;
142 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 157 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
143 return (property_name == kAttrNameAccessCode || 158 return (property_name == kAttrNameAccessCode ||
144 property_name == kAttrNameState || 159 property_name == kAttrNameState ||
145 property_name == kAttrNameLogDebugInfo || 160 property_name == kAttrNameLogDebugInfo ||
146 property_name == kAttrNameOnStateChanged || 161 property_name == kAttrNameOnStateChanged ||
147 property_name == kAttrNameDisconnected || 162 property_name == kAttrNameDisconnected ||
148 property_name == kAttrNameRequestedAccessCode || 163 property_name == kAttrNameRequestedAccessCode ||
149 property_name == kAttrNameReceivedAccessCode || 164 property_name == kAttrNameReceivedAccessCode ||
150 property_name == kAttrNameConnected || 165 property_name == kAttrNameConnected ||
151 property_name == kAttrNameAffirmingConnection || 166 property_name == kAttrNameAffirmingConnection ||
152 property_name == kAttrNameError); 167 property_name == kAttrNameError);
153 } 168 }
154 169
155 bool HostNPScriptObject::GetProperty(const std::string& property_name, 170 bool HostNPScriptObject::GetProperty(const std::string& property_name,
156 NPVariant* result) { 171 NPVariant* result) {
157 logger_->VLog(2, "GetProperty %s", property_name.c_str()); 172 VLOG(2) << "GetProperty " << property_name;
158 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 173 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
159 if (!result) { 174 if (!result) {
160 SetException("GetProperty: NULL result"); 175 SetException("GetProperty: NULL result");
161 return false; 176 return false;
162 } 177 }
163 178
164 if (property_name == kAttrNameOnStateChanged) { 179 if (property_name == kAttrNameOnStateChanged) {
165 OBJECT_TO_NPVARIANT(on_state_changed_func_, *result); 180 OBJECT_TO_NPVARIANT(on_state_changed_func_, *result);
166 return true; 181 return true;
167 } else if (property_name == kAttrNameLogDebugInfo) { 182 } else if (property_name == kAttrNameLogDebugInfo) {
(...skipping 24 matching lines...) Expand all
192 INT32_TO_NPVARIANT(kError, *result); 207 INT32_TO_NPVARIANT(kError, *result);
193 return true; 208 return true;
194 } else { 209 } else {
195 SetException("GetProperty: unsupported property " + property_name); 210 SetException("GetProperty: unsupported property " + property_name);
196 return false; 211 return false;
197 } 212 }
198 } 213 }
199 214
200 bool HostNPScriptObject::SetProperty(const std::string& property_name, 215 bool HostNPScriptObject::SetProperty(const std::string& property_name,
201 const NPVariant* value) { 216 const NPVariant* value) {
202 logger_->VLog(2, "SetProperty %s", property_name.c_str()); 217 VLOG(2) << "SetProperty " << property_name;
203 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 218 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
204 219
205 if (property_name == kAttrNameOnStateChanged) { 220 if (property_name == kAttrNameOnStateChanged) {
206 if (NPVARIANT_IS_OBJECT(*value)) { 221 if (NPVARIANT_IS_OBJECT(*value)) {
207 if (on_state_changed_func_) { 222 if (on_state_changed_func_) {
208 g_npnetscape_funcs->releaseobject(on_state_changed_func_); 223 g_npnetscape_funcs->releaseobject(on_state_changed_func_);
209 } 224 }
210 on_state_changed_func_ = NPVARIANT_TO_OBJECT(*value); 225 on_state_changed_func_ = NPVARIANT_TO_OBJECT(*value);
211 if (on_state_changed_func_) { 226 if (on_state_changed_func_) {
212 g_npnetscape_funcs->retainobject(on_state_changed_func_); 227 g_npnetscape_funcs->retainobject(on_state_changed_func_);
(...skipping 20 matching lines...) Expand all
233 SetException("SetProperty: unexpected type for property " + 248 SetException("SetProperty: unexpected type for property " +
234 property_name); 249 property_name);
235 } 250 }
236 return false; 251 return false;
237 } 252 }
238 253
239 return false; 254 return false;
240 } 255 }
241 256
242 bool HostNPScriptObject::RemoveProperty(const std::string& property_name) { 257 bool HostNPScriptObject::RemoveProperty(const std::string& property_name) {
243 logger_->VLog(2, "RemoveProperty %s", property_name.c_str()); 258 VLOG(2) << "RemoveProperty " << property_name;
244 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 259 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
245 return false; 260 return false;
246 } 261 }
247 262
248 bool HostNPScriptObject::Enumerate(std::vector<std::string>* values) { 263 bool HostNPScriptObject::Enumerate(std::vector<std::string>* values) {
249 logger_->VLog(2, "Enumerate"); 264 VLOG(2) << "Enumerate";
250 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 265 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
251 const char* entries[] = { 266 const char* entries[] = {
252 kAttrNameAccessCode, 267 kAttrNameAccessCode,
253 kAttrNameState, 268 kAttrNameState,
254 kAttrNameLogDebugInfo, 269 kAttrNameLogDebugInfo,
255 kAttrNameOnStateChanged, 270 kAttrNameOnStateChanged,
256 kFuncNameConnect, 271 kFuncNameConnect,
257 kFuncNameDisconnect, 272 kFuncNameDisconnect,
258 kAttrNameDisconnected, 273 kAttrNameDisconnected,
259 kAttrNameRequestedAccessCode, 274 kAttrNameRequestedAccessCode,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 308
294 OnStateChanged(kDisconnected); 309 OnStateChanged(kDisconnected);
295 } 310 }
296 311
297 // string uid, string auth_token 312 // string uid, string auth_token
298 bool HostNPScriptObject::Connect(const NPVariant* args, 313 bool HostNPScriptObject::Connect(const NPVariant* args,
299 uint32_t arg_count, 314 uint32_t arg_count,
300 NPVariant* result) { 315 NPVariant* result) {
301 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 316 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
302 317
303 LogDebugInfo("Connecting..."); 318 LOG(INFO) << "Connecting...";
304 319
305 if (arg_count != 2) { 320 if (arg_count != 2) {
306 SetException("connect: bad number of arguments"); 321 SetException("connect: bad number of arguments");
307 return false; 322 return false;
308 } 323 }
309 324
310 std::string uid = StringFromNPVariant(args[0]); 325 std::string uid = StringFromNPVariant(args[0]);
311 if (uid.empty()) { 326 if (uid.empty()) {
312 SetException("connect: bad uid argument"); 327 SetException("connect: bad uid argument");
313 return false; 328 return false;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 base::Bind(&HostNPScriptObject::OnReceivedSupportID, 378 base::Bind(&HostNPScriptObject::OnReceivedSupportID,
364 base::Unretained(this), 379 base::Unretained(this),
365 access_verifier.get()))) { 380 access_verifier.get()))) {
366 OnStateChanged(kDisconnected); 381 OnStateChanged(kDisconnected);
367 return; 382 return;
368 } 383 }
369 384
370 // Create the Host. 385 // Create the Host.
371 scoped_refptr<ChromotingHost> host = 386 scoped_refptr<ChromotingHost> host =
372 ChromotingHost::Create(&host_context_, host_config, 387 ChromotingHost::Create(&host_context_, host_config,
373 access_verifier.release(), logger_.get()); 388 access_verifier.release());
374 host->AddStatusObserver(this); 389 host->AddStatusObserver(this);
375 host->AddStatusObserver(register_request.get()); 390 host->AddStatusObserver(register_request.get());
376 host->set_it2me(true); 391 host->set_it2me(true);
377 392
378 // Nothing went wrong, so lets save the host, config and request. 393 // Nothing went wrong, so lets save the host, config and request.
379 host_ = host; 394 host_ = host;
380 host_config_ = host_config; 395 host_config_ = host_config;
381 register_request_.reset(register_request.release()); 396 register_request_.reset(register_request.release());
382 397
383 // Start the Host. 398 // Start the Host.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 471 }
457 472
458 if (!host_context_.IsUIThread()) { 473 if (!host_context_.IsUIThread()) {
459 host_context_.PostToUIThread( 474 host_context_.PostToUIThread(
460 FROM_HERE, 475 FROM_HERE,
461 NewRunnableMethod(this, &HostNPScriptObject::OnStateChanged, state)); 476 NewRunnableMethod(this, &HostNPScriptObject::OnStateChanged, state));
462 return; 477 return;
463 } 478 }
464 state_ = state; 479 state_ = state;
465 if (on_state_changed_func_) { 480 if (on_state_changed_func_) {
466 logger_->VLog(2, "Calling state changed %s", state); 481 VLOG(2) << "Calling state changed " << state;
467 bool is_good = InvokeAndIgnoreResult(on_state_changed_func_, NULL, 0); 482 bool is_good = InvokeAndIgnoreResult(on_state_changed_func_, NULL, 0);
468 LOG_IF(ERROR, !is_good) << "OnStateChanged failed"; 483 LOG_IF(ERROR, !is_good) << "OnStateChanged failed";
469 } 484 }
470 } 485 }
471 486
487 // static
488 bool HostNPScriptObject::LogToUI(int severity, const char* file, int line,
489 size_t message_start,
490 const std::string& str) {
491 if (logging_scriptable_object_ && !logging_to_plugin_) {
dmac 2011/07/21 23:37:07 accessing logging_to_plugin_ from multiple thread
garykac 2011/08/02 00:15:37 Pushed this check down into the UIThread code belo
492 logging_to_plugin_ = true;
493 std::string message = remoting::GetTimestampString();
494 message += (str.c_str() + message_start);
495 logging_scriptable_object_->LogDebugInfo(message);
496 logging_to_plugin_ = false;
497 }
498 if (logging_old_handler_)
499 return (logging_old_handler_)(severity, file, line, message_start, str);
500 return false;
501 }
502
472 void HostNPScriptObject::LogDebugInfo(const std::string& message) { 503 void HostNPScriptObject::LogDebugInfo(const std::string& message) {
473 if (!host_context_.IsUIThread()) { 504 if (!host_context_.IsUIThread()) {
474 host_context_.PostToUIThread( 505 host_context_.PostToUIThread(
475 FROM_HERE, 506 FROM_HERE,
476 NewRunnableMethod(this, &HostNPScriptObject::LogDebugInfo, message)); 507 NewRunnableMethod(this, &HostNPScriptObject::LogDebugInfo, message));
477 return; 508 return;
478 } 509 }
479 if (log_debug_info_func_) { 510 if (log_debug_info_func_) {
480 NPVariant* arg = new NPVariant(); 511 NPVariant* arg = new NPVariant();
481 STRINGZ_TO_NPVARIANT(message.c_str(), *arg); 512 STRINGZ_TO_NPVARIANT(message.c_str(), *arg);
482 bool is_good = InvokeAndIgnoreResult(log_debug_info_func_, arg, 1); 513 bool is_good = InvokeAndIgnoreResult(log_debug_info_func_, arg, 1);
483 LOG_IF(ERROR, !is_good) << "LogDebugInfo failed"; 514 LOG_IF(ERROR, !is_good) << "LogDebugInfo failed";
484 } 515 }
485 } 516 }
486 517
487 void HostNPScriptObject::SetException(const std::string& exception_string) { 518 void HostNPScriptObject::SetException(const std::string& exception_string) {
488 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 519 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
489 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 520 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
490 LogDebugInfo(exception_string); 521 LOG(INFO) << exception_string;
491 } 522 }
492 523
493 bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func, 524 bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func,
494 const NPVariant* args, 525 const NPVariant* args,
495 uint32_t argCount) { 526 uint32_t argCount) {
496 NPVariant np_result; 527 NPVariant np_result;
497 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, 528 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args,
498 argCount, &np_result); 529 argCount, &np_result);
499 if (is_good) 530 if (is_good)
500 g_npnetscape_funcs->releasevariantvalue(&np_result); 531 g_npnetscape_funcs->releasevariantvalue(&np_result);
(...skipping 12 matching lines...) Expand all
513 task); 544 task);
514 } 545 }
515 546
516 void HostNPScriptObject::NPTaskSpringboard(void* task) { 547 void HostNPScriptObject::NPTaskSpringboard(void* task) {
517 Task* real_task = reinterpret_cast<Task*>(task); 548 Task* real_task = reinterpret_cast<Task*>(task);
518 real_task->Run(); 549 real_task->Run();
519 delete real_task; 550 delete real_task;
520 } 551 }
521 552
522 } // namespace remoting 553 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698