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 // ChromePostman implementation. | 5 // ChromePostman implementation. |
6 #include "ceee/ie/broker/chrome_postman.h" | 6 #include "ceee/ie/broker/chrome_postman.h" |
7 | 7 |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "ceee/ie/broker/api_dispatcher.h" | 9 #include "ceee/ie/broker/api_dispatcher.h" |
10 #include "ceee/ie/common/api_registration.h" | 10 #include "ceee/ie/common/api_registration.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 virtual void Run() { | 62 virtual void Run() { |
63 ProductionApiDispatcher::get()->HandleApiRequest(message_, NULL); | 63 ProductionApiDispatcher::get()->HandleApiRequest(message_, NULL); |
64 } | 64 } |
65 private: | 65 private: |
66 CComBSTR message_; | 66 CComBSTR message_; |
67 }; | 67 }; |
68 | 68 |
69 class FireEventTask : public Task { | 69 class FireEventTask : public Task { |
70 public: | 70 public: |
71 FireEventTask(BSTR event_name, BSTR event_args) | 71 FireEventTask(const char* event_name, const char* event_args) |
72 : event_name_(event_name), event_args_(event_args) {} | 72 : event_name_(event_name), event_args_(event_args) {} |
73 | 73 |
74 virtual void Run() { | 74 virtual void Run() { |
75 ProductionApiDispatcher::get()->FireEvent(event_name_, event_args_); | 75 ProductionApiDispatcher::get()->FireEvent(event_name_.c_str(), |
| 76 event_args_.c_str()); |
76 } | 77 } |
77 private: | 78 private: |
78 CComBSTR event_name_; | 79 std::string event_name_; |
79 CComBSTR event_args_; | 80 std::string event_args_; |
80 }; | 81 }; |
81 | 82 |
82 | 83 |
83 ChromePostman* ChromePostman::single_instance_ = NULL; | 84 ChromePostman* ChromePostman::single_instance_ = NULL; |
84 ChromePostman::ChromePostman() { | 85 ChromePostman::ChromePostman() { |
85 DCHECK(single_instance_ == NULL); | 86 DCHECK(single_instance_ == NULL); |
86 single_instance_ = this; | 87 single_instance_ = this; |
87 frame_reset_count_ = 0; | 88 frame_reset_count_ = 0; |
88 } | 89 } |
89 | 90 |
(...skipping 12 matching lines...) Expand all Loading... |
102 } | 103 } |
103 | 104 |
104 void ChromePostman::Term() { | 105 void ChromePostman::Term() { |
105 api_worker_thread_.Stop(); | 106 api_worker_thread_.Stop(); |
106 chrome_postman_thread_.Stop(); | 107 chrome_postman_thread_.Stop(); |
107 } | 108 } |
108 | 109 |
109 void ChromePostman::PostMessage(BSTR message, BSTR target) { | 110 void ChromePostman::PostMessage(BSTR message, BSTR target) { |
110 MessageLoop* message_loop = chrome_postman_thread_.message_loop(); | 111 MessageLoop* message_loop = chrome_postman_thread_.message_loop(); |
111 if (message_loop) { | 112 if (message_loop) { |
| 113 // TODO(siggi@chromium.org): Remove the task subclass and change this to |
| 114 // use NewRunnableMethod. |
112 message_loop->PostTask( | 115 message_loop->PostTask( |
113 FROM_HERE, new ChromeFrameMessageTask(&chrome_postman_thread_, | 116 FROM_HERE, new ChromeFrameMessageTask(&chrome_postman_thread_, |
114 message, target)); | 117 message, target)); |
115 } else { | 118 } else { |
116 LOG(ERROR) << "Trying to post a message before the postman thread is" | 119 LOG(ERROR) << "Trying to post a message before the postman thread is" |
117 "completely initialized and ready."; | 120 "completely initialized and ready."; |
118 } | 121 } |
119 } | 122 } |
120 | 123 |
121 void ChromePostman::FireEvent(BSTR event_name, BSTR event_args) { | 124 void ChromePostman::FireEvent(const char* event_name, const char* event_args) { |
122 MessageLoop* message_loop = api_worker_thread_.message_loop(); | 125 MessageLoop* message_loop = api_worker_thread_.message_loop(); |
123 if (message_loop) { | 126 if (message_loop) { |
| 127 // TODO(siggi@chromium.org): Remove the task subclass and change this to |
| 128 // use NewRunnableMethod. |
124 message_loop->PostTask(FROM_HERE, | 129 message_loop->PostTask(FROM_HERE, |
125 new FireEventTask(event_name, event_args)); | 130 new FireEventTask(event_name, event_args)); |
126 } else { | 131 } else { |
127 LOG(ERROR) << "Trying to post a message before the API worker thread is" | 132 LOG(ERROR) << "Trying to post a message before the API worker thread is" |
128 "completely initialized and ready."; | 133 "completely initialized and ready."; |
129 } | 134 } |
130 } | 135 } |
131 | 136 |
132 HRESULT ChromePostman::OnCfReadyStateChanged(LONG state) { | 137 HRESULT ChromePostman::OnCfReadyStateChanged(LONG state) { |
133 if (state == READYSTATE_COMPLETE) { | 138 if (state == READYSTATE_COMPLETE) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 void ChromePostman::ApiInvocationWorkerThread::Init() { | 296 void ChromePostman::ApiInvocationWorkerThread::Init() { |
292 ::CoInitializeEx(0, COINIT_MULTITHREADED); | 297 ::CoInitializeEx(0, COINIT_MULTITHREADED); |
293 ProductionApiDispatcher::get()->SetApiInvocationThreadId( | 298 ProductionApiDispatcher::get()->SetApiInvocationThreadId( |
294 ::GetCurrentThreadId()); | 299 ::GetCurrentThreadId()); |
295 } | 300 } |
296 | 301 |
297 void ChromePostman::ApiInvocationWorkerThread::CleanUp() { | 302 void ChromePostman::ApiInvocationWorkerThread::CleanUp() { |
298 ::CoUninitialize(); | 303 ::CoUninitialize(); |
299 ProductionApiDispatcher::get()->SetApiInvocationThreadId(0); | 304 ProductionApiDispatcher::get()->SetApiInvocationThreadId(0); |
300 } | 305 } |
OLD | NEW |