| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Declaration of ATL module object and DLL exports. | 5 // Declaration of ATL module object and DLL exports. |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/atomic_ref_count.h" | 8 #include "base/atomic_ref_count.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/logging_win.h" | 11 #include "base/logging_win.h" |
| 12 #include "base/thread.h" | 12 #include "base/thread.h" |
| 13 #include "ceee/common/com_utils.h" | 13 #include "ceee/common/com_utils.h" |
| 14 #include "ceee/common/install_utils.h" | 14 #include "ceee/common/install_utils.h" |
| 15 #include "ceee/ie/broker/broker_rpc_client.h" |
| 15 #include "ceee/ie/common/ceee_module_util.h" | 16 #include "ceee/ie/common/ceee_module_util.h" |
| 16 #include "ceee/ie/plugin/bho/browser_helper_object.h" | 17 #include "ceee/ie/plugin/bho/browser_helper_object.h" |
| 17 #include "ceee/ie/plugin/bho/executor.h" | 18 #include "ceee/ie/plugin/bho/executor.h" |
| 18 #include "ceee/ie/plugin/toolband/toolband_module_reporting.h" | 19 #include "ceee/ie/plugin/toolband/toolband_module_reporting.h" |
| 19 #include "ceee/ie/plugin/toolband/tool_band.h" | 20 #include "ceee/ie/plugin/toolband/tool_band.h" |
| 20 #include "ceee/ie/plugin/scripting/script_host.h" | 21 #include "ceee/ie/plugin/scripting/script_host.h" |
| 21 #include "ceee/common/windows_constants.h" | 22 #include "ceee/common/windows_constants.h" |
| 22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 23 | 24 |
| 24 #include "toolband.h" // NOLINT | 25 #include "toolband.h" // NOLINT |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // Called just prior to starting the message loop | 74 // Called just prior to starting the message loop |
| 74 virtual void Init(); | 75 virtual void Init(); |
| 75 | 76 |
| 76 // Called just after the message loop ends | 77 // Called just after the message loop ends |
| 77 virtual void CleanUp(); | 78 virtual void CleanUp(); |
| 78 | 79 |
| 79 // Called by FireEventTask so that the broker we instantiate in the | 80 // Called by FireEventTask so that the broker we instantiate in the |
| 80 // worker thread can be used. | 81 // worker thread can be used. |
| 81 void FireEventToBroker(BSTR event_name, BSTR event_args); | 82 void FireEventToBroker(BSTR event_name, BSTR event_args); |
| 82 protected: | 83 protected: |
| 83 CComPtr<ICeeeBroker> broker_; | 84 BrokerRpcClient broker_rpc_; |
| 84 static const int kMaxNumberOfRetries = 5; | |
| 85 static const int64 kRetryDelayMs = 10; | |
| 86 int current_number_of_retries_; | |
| 87 }; | 85 }; |
| 88 | 86 |
| 89 class FireEventTask : public Task { | 87 class FireEventTask : public Task { |
| 90 public: | 88 public: |
| 91 FireEventTask(ComWorkerThread* worker_thread, | 89 FireEventTask(ComWorkerThread* worker_thread, |
| 92 const std::string& event_name, | 90 const std::string& event_name, |
| 93 const std::string& event_args) | 91 const std::string& event_args) |
| 94 : worker_thread_(worker_thread), | 92 : worker_thread_(worker_thread), |
| 95 event_name_(event_name.c_str()), | 93 event_name_(event_name.c_str()), |
| 96 event_args_(event_args.c_str()) { | 94 event_args_(event_args.c_str()) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 message_loop->PostTask(FROM_HERE, | 282 message_loop->PostTask(FROM_HERE, |
| 285 new FireEventTask(worker_thread_, event_name, event_args)); | 283 new FireEventTask(worker_thread_, event_name, event_args)); |
| 286 } else { | 284 } else { |
| 287 LOG(ERROR) << "Trying to post a message before the COM worker thread is" | 285 LOG(ERROR) << "Trying to post a message before the COM worker thread is" |
| 288 "completely initialized and ready."; | 286 "completely initialized and ready."; |
| 289 } | 287 } |
| 290 } | 288 } |
| 291 | 289 |
| 292 | 290 |
| 293 ToolbandModule::ComWorkerThread::ComWorkerThread() | 291 ToolbandModule::ComWorkerThread::ComWorkerThread() |
| 294 : base::Thread("CEEE-COM Worker Thread"), | 292 : base::Thread("CEEE-COM Worker Thread") { |
| 295 current_number_of_retries_(0) { | |
| 296 } | 293 } |
| 297 | 294 |
| 298 void ToolbandModule::ComWorkerThread::Init() { | 295 void ToolbandModule::ComWorkerThread::Init() { |
| 299 ::CoInitializeEx(0, COINIT_MULTITHREADED); | 296 ::CoInitializeEx(0, COINIT_MULTITHREADED); |
| 297 // TODO(vitalybuka@google.com): Start broker without COM. |
| 298 CComPtr<ICeeeBroker> broker_; |
| 300 HRESULT hr = broker_.CoCreateInstance(CLSID_CeeeBroker); | 299 HRESULT hr = broker_.CoCreateInstance(CLSID_CeeeBroker); |
| 301 DCHECK(SUCCEEDED(hr)) << "Failed to create broker. " << com::LogHr(hr); | 300 DCHECK(SUCCEEDED(hr)) << "Failed to create broker. " << com::LogHr(hr); |
| 301 broker_rpc_.Connect(); |
| 302 DCHECK(broker_rpc_.is_connected()); |
| 303 ::CoUninitialize(); |
| 302 } | 304 } |
| 303 | 305 |
| 304 void ToolbandModule::ComWorkerThread::CleanUp() { | 306 void ToolbandModule::ComWorkerThread::CleanUp() { |
| 305 broker_.Release(); | 307 broker_rpc_.Disconnect(); |
| 306 ::CoUninitialize(); | |
| 307 } | 308 } |
| 308 | 309 |
| 309 void ToolbandModule::ComWorkerThread::FireEventToBroker(BSTR event_name, | 310 void ToolbandModule::ComWorkerThread::FireEventToBroker(BSTR event_name, |
| 310 BSTR event_args) { | 311 BSTR event_args) { |
| 311 DCHECK(broker_ != NULL); | 312 DCHECK(broker_rpc_.is_connected()); |
| 312 if (broker_ != NULL) { | 313 bool result = broker_rpc_.FireEvent(event_name, event_args); |
| 313 HRESULT hr = broker_->FireEvent(event_name, event_args); | 314 DCHECK(result); |
| 314 if (SUCCEEDED(hr)) { | |
| 315 current_number_of_retries_ = 0; | |
| 316 return; | |
| 317 } | |
| 318 // If the server is busy (which can happen if it is calling in as we try to | |
| 319 // to call out to it), then we should retry a few times a little later. | |
| 320 if (current_number_of_retries_ < kMaxNumberOfRetries && message_loop()) { | |
| 321 ++current_number_of_retries_; | |
| 322 LOG(WARNING) << "Retrying Broker FireEvent Failure. " << com::LogHr(hr); | |
| 323 message_loop()->PostDelayedTask(FROM_HERE, | |
| 324 new FireEventTask(this, event_name, event_args), kRetryDelayMs); | |
| 325 } else { | |
| 326 current_number_of_retries_ = 0; | |
| 327 DCHECK(SUCCEEDED(hr)) << "Broker FireEvent Failed. " << com::LogHr(hr); | |
| 328 } | |
| 329 } | |
| 330 } | 315 } |
| 331 | 316 |
| 332 ToolbandModule module; | 317 ToolbandModule module; |
| 333 | 318 |
| 334 void ceee_module_util::AddRefModuleWorkerThread() { | 319 void ceee_module_util::AddRefModuleWorkerThread() { |
| 335 module.IncThreadRefCount(); | 320 module.IncThreadRefCount(); |
| 336 } | 321 } |
| 337 void ceee_module_util::ReleaseModuleWorkerThread() { | 322 void ceee_module_util::ReleaseModuleWorkerThread() { |
| 338 module.DecThreadRefCount(); | 323 module.DecThreadRefCount(); |
| 339 } | 324 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 384 } |
| 400 | 385 |
| 401 CEEE_DEFINE_DLL_REGISTER_SERVER() | 386 CEEE_DEFINE_DLL_REGISTER_SERVER() |
| 402 | 387 |
| 403 // DllUnregisterServer - Removes entries from the system registry | 388 // DllUnregisterServer - Removes entries from the system registry |
| 404 STDAPI DllUnregisterServer(void) { | 389 STDAPI DllUnregisterServer(void) { |
| 405 // We always allow unregistration, even if no --enable-ceee install flag. | 390 // We always allow unregistration, even if no --enable-ceee install flag. |
| 406 HRESULT hr = module.DllUnregisterServer(); | 391 HRESULT hr = module.DllUnregisterServer(); |
| 407 return hr; | 392 return hr; |
| 408 } | 393 } |
| OLD | NEW |