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

Side by Side Diff: chrome/browser/chrome_thread.cc

Issue 1800008: Created a MessageLoopProxy interface. This provides a thread-safe refcounted ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 7 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
« no previous file with comments | « chrome/browser/chrome_thread.h ('k') | chrome/browser/chrome_thread_unittest.cc » ('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) 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 #include "chrome/browser/chrome_thread.h" 5 #include "chrome/browser/chrome_thread.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/message_loop_proxy.h"
8 9
9 // Friendly names for the well-known threads. 10 // Friendly names for the well-known threads.
10 static const char* chrome_thread_names[ChromeThread::ID_COUNT] = { 11 static const char* chrome_thread_names[ChromeThread::ID_COUNT] = {
11 "", // UI (name assembled in browser_main.cc). 12 "", // UI (name assembled in browser_main.cc).
12 "Chrome_DBThread", // DB 13 "Chrome_DBThread", // DB
13 "Chrome_WebKitThread", // WEBKIT 14 "Chrome_WebKitThread", // WEBKIT
14 "Chrome_FileThread", // FILE 15 "Chrome_FileThread", // FILE
15 "Chrome_ProcessLauncherThread", // PROCESS_LAUNCHER 16 "Chrome_ProcessLauncherThread", // PROCESS_LAUNCHER
16 "Chrome_IOThread", // IO 17 "Chrome_IOThread", // IO
17 #if defined(USE_X11) 18 #if defined(USE_X11)
18 "Chrome_Background_X11Thread", // BACKGROUND_X11 19 "Chrome_Background_X11Thread", // BACKGROUND_X11
19 #endif 20 #endif
20 }; 21 };
21 22
23 // An implementation of MessageLoopProxy to be used in conjunction
24 // with ChromeThread.
25 class ChromeThreadMessageLoopProxy : public MessageLoopProxy {
26 public:
27 explicit ChromeThreadMessageLoopProxy(ChromeThread::ID identifier)
28 : id_(identifier) {
29 }
30
31 // MessageLoopProxy implementation.
32 virtual bool PostTask(const tracked_objects::Location& from_here,
33 Task* task) {
34 return ChromeThread::PostTask(id_, from_here, task);
35 }
36
37 virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
38 Task* task, int64 delay_ms) {
39 return ChromeThread::PostDelayedTask(id_, from_here, task, delay_ms);
40 }
41
42 virtual bool PostNonNestableTask(const tracked_objects::Location& from_here,
43 Task* task) {
44 return ChromeThread::PostNonNestableTask(id_, from_here, task);
45 }
46
47 virtual bool PostNonNestableDelayedTask(
48 const tracked_objects::Location& from_here,
49 Task* task,
50 int64 delay_ms) {
51 return ChromeThread::PostNonNestableDelayedTask(id_, from_here, task,
52 delay_ms);
53 }
54
55 private:
56 ChromeThread::ID id_;
57 DISALLOW_COPY_AND_ASSIGN(ChromeThreadMessageLoopProxy);
58 };
59
60
22 Lock ChromeThread::lock_; 61 Lock ChromeThread::lock_;
23 62
24 ChromeThread* ChromeThread::chrome_threads_[ID_COUNT]; 63 ChromeThread* ChromeThread::chrome_threads_[ID_COUNT];
25 64
26 ChromeThread::ChromeThread(ChromeThread::ID identifier) 65 ChromeThread::ChromeThread(ChromeThread::ID identifier)
27 : Thread(chrome_thread_names[identifier]), 66 : Thread(chrome_thread_names[identifier]),
28 identifier_(identifier) { 67 identifier_(identifier) {
29 Initialize(); 68 Initialize();
30 } 69 }
31 70
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 chrome_threads_[i]->message_loop() == cur_message_loop) { 154 chrome_threads_[i]->message_loop() == cur_message_loop) {
116 *identifier = chrome_threads_[i]->identifier_; 155 *identifier = chrome_threads_[i]->identifier_;
117 return true; 156 return true;
118 } 157 }
119 } 158 }
120 159
121 return false; 160 return false;
122 } 161 }
123 162
124 // static 163 // static
164 scoped_refptr<MessageLoopProxy> ChromeThread::GetMessageLoopProxyForThread(
165 ID identifier) {
166 scoped_refptr<MessageLoopProxy> proxy =
167 new ChromeThreadMessageLoopProxy(identifier);
168 return proxy;
169 }
170
171 // static
125 bool ChromeThread::PostTaskHelper( 172 bool ChromeThread::PostTaskHelper(
126 ID identifier, 173 ID identifier,
127 const tracked_objects::Location& from_here, 174 const tracked_objects::Location& from_here,
128 Task* task, 175 Task* task,
129 int64 delay_ms, 176 int64 delay_ms,
130 bool nestable) { 177 bool nestable) {
131 DCHECK(identifier >= 0 && identifier < ID_COUNT); 178 DCHECK(identifier >= 0 && identifier < ID_COUNT);
132 // Optimization: to avoid unnecessary locks, we listed the ID enumeration in 179 // Optimization: to avoid unnecessary locks, we listed the ID enumeration in
133 // order of lifetime. So no need to lock if we know that the other thread 180 // order of lifetime. So no need to lock if we know that the other thread
134 // outlives this one. 181 // outlives this one.
(...skipping 18 matching lines...) Expand all
153 } 200 }
154 } else { 201 } else {
155 delete task; 202 delete task;
156 } 203 }
157 204
158 if (!guaranteed_to_outlive_target_thread) 205 if (!guaranteed_to_outlive_target_thread)
159 lock_.Release(); 206 lock_.Release();
160 207
161 return !!message_loop; 208 return !!message_loop;
162 } 209 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_thread.h ('k') | chrome/browser/chrome_thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698