| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 bool module_initialized() const { | 60 bool module_initialized() const { |
| 60 return module_initialized_; | 61 return module_initialized_; |
| 61 } | 62 } |
| 62 | 63 |
| 63 // Fires an event to the broker, so that the call can be made with an | 64 // Fires an event to the broker, so that the call can be made with an |
| 64 // instance of a broker proxy that was CoCreated in the worker thread. | 65 // instance of a broker proxy that was CoCreated in the worker thread. |
| 65 void FireEventToBroker(const std::string& event_name, | 66 void FireEventToBroker(const std::string& event_name, |
| 66 const std::string& event_args); | 67 const std::string& event_args); |
| 67 | 68 |
| 68 private: | 69 private: |
| 70 // TODO(vitalybuka@google.com): Fire events without this thread. |
| 69 class ComWorkerThread : public base::Thread { | 71 class ComWorkerThread : public base::Thread { |
| 70 public: | 72 public: |
| 71 ComWorkerThread(); | 73 ComWorkerThread(); |
| 72 | 74 |
| 73 // Called just prior to starting the message loop | 75 // Called just prior to starting the message loop |
| 74 virtual void Init(); | 76 virtual void Init(); |
| 75 | 77 |
| 76 // Called just after the message loop ends | 78 // Called just after the message loop ends |
| 77 virtual void CleanUp(); | 79 virtual void CleanUp(); |
| 78 | 80 |
| 79 // Called by FireEventTask so that the broker we instantiate in the | 81 // Called by FireEventTask so that the broker we instantiate in the |
| 80 // worker thread can be used. | 82 // worker thread can be used. |
| 81 void FireEventToBroker(BSTR event_name, BSTR event_args); | 83 void FireEventToBroker(BSTR event_name, BSTR event_args); |
| 82 protected: | 84 protected: |
| 83 CComPtr<ICeeeBroker> broker_; | 85 BrokerRpcClient broker_rpc_; |
| 84 static const int kMaxNumberOfRetries = 5; | |
| 85 static const int64 kRetryDelayMs = 10; | |
| 86 int current_number_of_retries_; | |
| 87 }; | 86 }; |
| 88 | 87 |
| 89 class FireEventTask : public Task { | 88 class FireEventTask : public Task { |
| 90 public: | 89 public: |
| 91 FireEventTask(ComWorkerThread* worker_thread, | 90 FireEventTask(ComWorkerThread* worker_thread, |
| 92 const std::string& event_name, | 91 const std::string& event_name, |
| 93 const std::string& event_args) | 92 const std::string& event_args) |
| 94 : worker_thread_(worker_thread), | 93 : worker_thread_(worker_thread), |
| 95 event_name_(event_name.c_str()), | 94 event_name_(event_name.c_str()), |
| 96 event_args_(event_args.c_str()) { | 95 event_args_(event_args.c_str()) { |
| 97 } | 96 } |
| 98 FireEventTask(ComWorkerThread* worker_thread, | |
| 99 const BSTR event_name, | |
| 100 const BSTR event_args) | |
| 101 : worker_thread_(worker_thread), | |
| 102 event_name_(event_name), | |
| 103 event_args_(event_args) { | |
| 104 } | |
| 105 virtual void Run() { | 97 virtual void Run() { |
| 106 worker_thread_->FireEventToBroker(event_name_, event_args_); | 98 worker_thread_->FireEventToBroker(event_name_, event_args_); |
| 107 } | 99 } |
| 108 private: | 100 private: |
| 109 ComWorkerThread* worker_thread_; | 101 ComWorkerThread* worker_thread_; |
| 110 CComBSTR event_name_; | 102 CComBSTR event_name_; |
| 111 CComBSTR event_args_; | 103 CComBSTR event_args_; |
| 112 }; | 104 }; |
| 113 // We only start the thread on first use. If we would start it on | 105 // We only start the thread on first use. If we would start it on |
| 114 // initialization, when our DLL is loaded into the broker process, | 106 // initialization, when our DLL is loaded into the broker process, |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 message_loop->PostTask(FROM_HERE, | 276 message_loop->PostTask(FROM_HERE, |
| 285 new FireEventTask(worker_thread_, event_name, event_args)); | 277 new FireEventTask(worker_thread_, event_name, event_args)); |
| 286 } else { | 278 } else { |
| 287 LOG(ERROR) << "Trying to post a message before the COM worker thread is" | 279 LOG(ERROR) << "Trying to post a message before the COM worker thread is" |
| 288 "completely initialized and ready."; | 280 "completely initialized and ready."; |
| 289 } | 281 } |
| 290 } | 282 } |
| 291 | 283 |
| 292 | 284 |
| 293 ToolbandModule::ComWorkerThread::ComWorkerThread() | 285 ToolbandModule::ComWorkerThread::ComWorkerThread() |
| 294 : base::Thread("CEEE-COM Worker Thread"), | 286 : base::Thread("CEEE-COM Worker Thread") { |
| 295 current_number_of_retries_(0) { | |
| 296 } | 287 } |
| 297 | 288 |
| 298 void ToolbandModule::ComWorkerThread::Init() { | 289 void ToolbandModule::ComWorkerThread::Init() { |
| 299 ::CoInitializeEx(0, COINIT_MULTITHREADED); | 290 ::CoInitializeEx(0, COINIT_MULTITHREADED); |
| 291 // TODO(vitalybuka@google.com): Start broker without COM. |
| 292 CComPtr<ICeeeBroker> broker_; |
| 300 HRESULT hr = broker_.CoCreateInstance(CLSID_CeeeBroker); | 293 HRESULT hr = broker_.CoCreateInstance(CLSID_CeeeBroker); |
| 301 DCHECK(SUCCEEDED(hr)) << "Failed to create broker. " << com::LogHr(hr); | 294 DCHECK(SUCCEEDED(hr)) << "Failed to create broker. " << com::LogHr(hr); |
| 295 broker_rpc_.Connect(); |
| 296 DCHECK(broker_rpc_.is_connected()); |
| 297 ::CoUninitialize(); |
| 302 } | 298 } |
| 303 | 299 |
| 304 void ToolbandModule::ComWorkerThread::CleanUp() { | 300 void ToolbandModule::ComWorkerThread::CleanUp() { |
| 305 broker_.Release(); | 301 broker_rpc_.Disconnect(); |
| 306 ::CoUninitialize(); | |
| 307 } | 302 } |
| 308 | 303 |
| 309 void ToolbandModule::ComWorkerThread::FireEventToBroker(BSTR event_name, | 304 void ToolbandModule::ComWorkerThread::FireEventToBroker(BSTR event_name, |
| 310 BSTR event_args) { | 305 BSTR event_args) { |
| 311 DCHECK(broker_ != NULL); | 306 DCHECK(broker_rpc_.is_connected()); |
| 312 if (broker_ != NULL) { | 307 bool result = broker_rpc_.FireEvent(event_name, event_args); |
| 313 HRESULT hr = broker_->FireEvent(event_name, event_args); | 308 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 } | 309 } |
| 331 | 310 |
| 332 ToolbandModule module; | 311 ToolbandModule module; |
| 333 | 312 |
| 334 void ceee_module_util::AddRefModuleWorkerThread() { | 313 void ceee_module_util::AddRefModuleWorkerThread() { |
| 335 module.IncThreadRefCount(); | 314 module.IncThreadRefCount(); |
| 336 } | 315 } |
| 337 void ceee_module_util::ReleaseModuleWorkerThread() { | 316 void ceee_module_util::ReleaseModuleWorkerThread() { |
| 338 module.DecThreadRefCount(); | 317 module.DecThreadRefCount(); |
| 339 } | 318 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 378 } |
| 400 | 379 |
| 401 CEEE_DEFINE_DLL_REGISTER_SERVER() | 380 CEEE_DEFINE_DLL_REGISTER_SERVER() |
| 402 | 381 |
| 403 // DllUnregisterServer - Removes entries from the system registry | 382 // DllUnregisterServer - Removes entries from the system registry |
| 404 STDAPI DllUnregisterServer(void) { | 383 STDAPI DllUnregisterServer(void) { |
| 405 // We always allow unregistration, even if no --enable-ceee install flag. | 384 // We always allow unregistration, even if no --enable-ceee install flag. |
| 406 HRESULT hr = module.DllUnregisterServer(); | 385 HRESULT hr = module.DllUnregisterServer(); |
| 407 return hr; | 386 return hr; |
| 408 } | 387 } |
| OLD | NEW |