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

Side by Side Diff: chrome_frame/chrome_frame_delegate.h

Issue 8555001: base::Bind: Convert chrome_frame/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: TaskMarshaller fix. Created 9 years, 1 month 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
« no previous file with comments | « chrome_frame/chrome_frame_automation.cc ('k') | chrome_frame/custom_sync_call_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CHROME_FRAME_CHROME_FRAME_DELEGATE_H_ 5 #ifndef CHROME_FRAME_CHROME_FRAME_DELEGATE_H_
6 #define CHROME_FRAME_CHROME_FRAME_DELEGATE_H_ 6 #define CHROME_FRAME_CHROME_FRAME_DELEGATE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <atlbase.h> 9 #include <atlbase.h>
10 #include <atlwin.h> 10 #include <atlwin.h>
11 #include <queue> 11 #include <queue>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/callback.h"
15 #include "base/file_path.h" 16 #include "base/file_path.h"
16 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/pending_task.h"
17 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
18 #include "base/task.h" 20 #include "base/task.h"
19 #include "chrome/common/automation_constants.h" 21 #include "chrome/common/automation_constants.h"
20 #include "ipc/ipc_message.h" 22 #include "ipc/ipc_message.h"
21 23
22 class GURL; 24 class GURL;
23 struct AttachExternalTabParams; 25 struct AttachExternalTabParams;
24 struct AutomationURLRequest; 26 struct AutomationURLRequest;
25 struct ContextMenuModel; 27 struct ContextMenuModel;
26 struct MiniContextMenuParams; 28 struct MiniContextMenuParams;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 virtual bool IsValid() const = 0; 60 virtual bool IsValid() const = 0;
59 61
60 // To be called when the top-most window of an application hosting 62 // To be called when the top-most window of an application hosting
61 // ChromeFrame is moved. 63 // ChromeFrame is moved.
62 virtual void OnHostMoved() = 0; 64 virtual void OnHostMoved() = 0;
63 65
64 protected: 66 protected:
65 virtual ~ChromeFrameDelegate() {} 67 virtual ~ChromeFrameDelegate() {}
66 }; 68 };
67 69
68 // Disable refcounting of ChromeFrameDelegate.
69 DISABLE_RUNNABLE_METHOD_REFCOUNT(ChromeFrameDelegate);
70
71 extern UINT kAutomationServerReady; 70 extern UINT kAutomationServerReady;
72 extern UINT kMessageFromChromeFrame; 71 extern UINT kMessageFromChromeFrame;
73 72
74 class ChromeFrameDelegateImpl : public ChromeFrameDelegate { 73 class ChromeFrameDelegateImpl : public ChromeFrameDelegate {
75 public: 74 public:
76 virtual WindowType GetWindow() { return NULL; } 75 virtual WindowType GetWindow() { return NULL; }
77 virtual void GetBounds(RECT* bounds) {} 76 virtual void GetBounds(RECT* bounds) {}
78 virtual std::string GetDocumentUrl() { return std::string(); } 77 virtual std::string GetDocumentUrl() { return std::string(); }
79 virtual void OnAutomationServerReady() {} 78 virtual void OnAutomationServerReady() {}
80 virtual void OnAutomationServerLaunchFailed( 79 virtual void OnAutomationServerLaunchFailed(
81 AutomationLaunchResult reason, const std::string& server_version) {} 80 AutomationLaunchResult reason, const std::string& server_version) {}
82 virtual void OnLoadFailed(int error_code, const std::string& url) {} 81 virtual void OnLoadFailed(int error_code, const std::string& url) {}
83 virtual bool OnMessageReceived(const IPC::Message& msg); 82 virtual bool OnMessageReceived(const IPC::Message& msg);
84 virtual void OnChannelError() {} 83 virtual void OnChannelError() {}
85 84
86 static bool IsTabMessage(const IPC::Message& message); 85 static bool IsTabMessage(const IPC::Message& message);
87 86
88 virtual bool IsValid() const { 87 virtual bool IsValid() const {
89 return true; 88 return true;
90 } 89 }
91 90
92 virtual void OnHostMoved() {} 91 virtual void OnHostMoved() {}
93 92
94 protected: 93 protected:
95 // Protected methods to be overriden. 94 // Protected methods to be overridden.
96 virtual void OnNavigationStateChanged( 95 virtual void OnNavigationStateChanged(
97 int flags, const NavigationInfo& nav_info) {} 96 int flags, const NavigationInfo& nav_info) {}
98 virtual void OnUpdateTargetUrl(const std::wstring& new_target_url) {} 97 virtual void OnUpdateTargetUrl(const std::wstring& new_target_url) {}
99 virtual void OnAcceleratorPressed(const MSG& accel_message) {} 98 virtual void OnAcceleratorPressed(const MSG& accel_message) {}
100 virtual void OnTabbedOut(bool reverse) {} 99 virtual void OnTabbedOut(bool reverse) {}
101 virtual void OnOpenURL( 100 virtual void OnOpenURL(
102 const GURL& url, const GURL& referrer, int open_disposition) {} 101 const GURL& url, const GURL& referrer, int open_disposition) {}
103 virtual void OnDidNavigate(const NavigationInfo& navigation_info) {} 102 virtual void OnDidNavigate(const NavigationInfo& navigation_info) {}
104 virtual void OnNavigationFailed(int error_code, const GURL& gurl) {} 103 virtual void OnNavigationFailed(int error_code, const GURL& gurl) {}
105 virtual void OnLoad(const GURL& url) {} 104 virtual void OnLoad(const GURL& url) {}
(...skipping 16 matching lines...) Expand all
122 virtual void OnGoToHistoryEntryOffset(int offset) {} 121 virtual void OnGoToHistoryEntryOffset(int offset) {}
123 122
124 virtual void OnGetCookiesFromHost(const GURL& url, int cookie_id) {} 123 virtual void OnGetCookiesFromHost(const GURL& url, int cookie_id) {}
125 virtual void OnCloseTab() {} 124 virtual void OnCloseTab() {}
126 }; 125 };
127 126
128 // This interface enables tasks to be marshaled to desired threads. 127 // This interface enables tasks to be marshaled to desired threads.
129 class TaskMarshaller { // NOLINT 128 class TaskMarshaller { // NOLINT
130 public: 129 public:
131 virtual void PostTask(const tracked_objects::Location& from_here, 130 virtual void PostTask(const tracked_objects::Location& from_here,
132 Task* task) = 0; 131 const base::Closure& task) = 0;
133 }; 132 };
134 133
135 // T is expected to be something CWindowImpl derived, or at least to have 134 // T is expected to be something CWindowImpl derived, or at least to have
136 // PostMessage(UINT, WPARAM) method. Do not forget to CHAIN_MSG_MAP 135 // PostMessage(UINT, WPARAM) method. Do not forget to CHAIN_MSG_MAP
137 template <class T> class TaskMarshallerThroughWindowsMessages 136 template <class T> class TaskMarshallerThroughWindowsMessages
138 : public TaskMarshaller { 137 : public TaskMarshaller {
139 public: 138 public:
140 TaskMarshallerThroughWindowsMessages() {} 139 TaskMarshallerThroughWindowsMessages() {}
141 virtual void PostTask(const tracked_objects::Location& from_here, 140 virtual void PostTask(const tracked_objects::Location& posted_from,
142 Task* task) { 141 const base::Closure& task) OVERRIDE {
143 T* this_ptr = static_cast<T*>(this); 142 T* this_ptr = static_cast<T*>(this);
144 if (this_ptr->IsWindow()) { 143 if (this_ptr->IsWindow()) {
145 this_ptr->AddRef(); 144 this_ptr->AddRef();
146 PushTask(task); 145 base::PendingTask* pending_task = new PendingTask(posted_from, task);
147 this_ptr->PostMessage(MSG_EXECUTE_TASK, reinterpret_cast<WPARAM>(task)); 146 PushTask(pending_task);
147 this_ptr->PostMessage(MSG_EXECUTE_TASK,
148 reinterpret_cast<WPARAM>(pending_task));
148 } else { 149 } else {
149 DVLOG(1) << "Dropping MSG_EXECUTE_TASK message for destroyed window."; 150 DVLOG(1) << "Dropping MSG_EXECUTE_TASK message for destroyed window.";
150 delete task;
151 } 151 }
152 } 152 }
153 153
154 protected: 154 protected:
155 ~TaskMarshallerThroughWindowsMessages() { 155 ~TaskMarshallerThroughWindowsMessages() {
156 DeleteAllPendingTasks(); 156 DeleteAllPendingTasks();
157 } 157 }
158 158
159 void DeleteAllPendingTasks() { 159 void DeleteAllPendingTasks() {
160 base::AutoLock lock(lock_); 160 base::AutoLock lock(lock_);
161 DVLOG_IF(1, !pending_tasks_.empty()) << "Destroying " 161 DVLOG_IF(1, !pending_tasks_.empty()) << "Destroying "
162 << pending_tasks_.size() 162 << pending_tasks_.size()
163 << " pending tasks"; 163 << " pending tasks";
164 while (!pending_tasks_.empty()) { 164 while (!pending_tasks_.empty()) {
165 Task* task = pending_tasks_.front(); 165 PendingTask* task = pending_tasks_.front();
166 pending_tasks_.pop(); 166 pending_tasks_.pop();
167 delete task; 167 delete task;
168 } 168 }
169 } 169 }
170 170
171 BEGIN_MSG_MAP(PostMessageMarshaller) 171 BEGIN_MSG_MAP(PostMessageMarshaller)
172 MESSAGE_HANDLER(MSG_EXECUTE_TASK, ExecuteTask) 172 MESSAGE_HANDLER(MSG_EXECUTE_TASK, ExecuteTask)
173 END_MSG_MAP() 173 END_MSG_MAP()
174 174
175 private: 175 private:
176 enum { MSG_EXECUTE_TASK = WM_APP + 6 }; 176 enum { MSG_EXECUTE_TASK = WM_APP + 6 };
177 inline LRESULT ExecuteTask(UINT, WPARAM wparam, LPARAM, 177 inline LRESULT ExecuteTask(UINT, WPARAM wparam, LPARAM,
178 BOOL& handled) { // NOLINT 178 BOOL& handled) { // NOLINT
179 Task* task = reinterpret_cast<Task*>(wparam); 179 base::PendingTask* task = reinterpret_cast<base::PendingTask*>(wparam);
180 if (task && PopTask(task)) { 180 if (task && PopTask(task)) {
181 task->Run(); 181 task->task.Run();
awong 2011/11/18 02:21:10 Being OCD...but can we call the local variable pen
James Hawkins 2011/11/18 02:24:44 Done.
182 delete task; 182 delete task;
183 } 183 }
184 184
185 T* this_ptr = static_cast<T*>(this); 185 T* this_ptr = static_cast<T*>(this);
186 this_ptr->Release(); 186 this_ptr->Release();
187 return 0; 187 return 0;
188 } 188 }
189 189
190 inline void PushTask(Task* task) { 190 inline void PushTask(base::PendingTask* task) {
191 base::AutoLock lock(lock_); 191 base::AutoLock lock(lock_);
192 pending_tasks_.push(task); 192 pending_tasks_.push(task);
193 } 193 }
194 194
195 // If the given task is front of the queue, removes the task and returns true, 195 // If the given task is front of the queue, removes the task and returns true,
196 // otherwise we assume this is an already destroyed task (but Window message 196 // otherwise we assume this is an already destroyed task (but Window message
197 // had remained in the thread queue). 197 // had remained in the thread queue).
198 inline bool PopTask(Task* task) { 198 inline bool PopTask(PendingTask* task) {
199 base::AutoLock lock(lock_); 199 base::AutoLock lock(lock_);
200 if (!pending_tasks_.empty() && task == pending_tasks_.front()) { 200 if (!pending_tasks_.empty() && task == pending_tasks_.front()) {
201 pending_tasks_.pop(); 201 pending_tasks_.pop();
202 return true; 202 return true;
203 } 203 }
204 204
205 return false; 205 return false;
206 } 206 }
207 207
208 base::Lock lock_; 208 base::Lock lock_;
209 std::queue<Task*> pending_tasks_; 209 std::queue<base::PendingTask*> pending_tasks_;
210 }; 210 };
211 211
212 #endif // CHROME_FRAME_CHROME_FRAME_DELEGATE_H_ 212 #endif // CHROME_FRAME_CHROME_FRAME_DELEGATE_H_
OLDNEW
« no previous file with comments | « chrome_frame/chrome_frame_automation.cc ('k') | chrome_frame/custom_sync_call_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698