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

Side by Side Diff: base/message_loop.h

Issue 1660: Move a bunch of code from the old to new TLS interface. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 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 | « no previous file | base/message_loop.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 BASE_MESSAGE_LOOP_H_ 5 #ifndef BASE_MESSAGE_LOOP_H_
6 #define BASE_MESSAGE_LOOP_H_ 6 #define BASE_MESSAGE_LOOP_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/histogram.h" 13 #include "base/histogram.h"
14 #include "base/message_pump.h" 14 #include "base/message_pump.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "base/ref_counted.h" 16 #include "base/ref_counted.h"
17 #include "base/task.h" 17 #include "base/task.h"
18 #include "base/timer.h" 18 #include "base/timer.h"
19 #include "base/thread_local_storage.h"
20 19
21 #if defined(OS_WIN) 20 #if defined(OS_WIN)
22 // We need this to declare base::MessagePumpWin::Dispatcher, which we should 21 // We need this to declare base::MessagePumpWin::Dispatcher, which we should
23 // really just eliminate. 22 // really just eliminate.
24 #include "base/message_pump_win.h" 23 #include "base/message_pump_win.h"
25 #endif 24 #endif
26 25
27 // A MessageLoop is used to process events for a particular thread. There is 26 // A MessageLoop is used to process events for a particular thread. There is
28 // at most one MessageLoop instance per thread. 27 // at most one MessageLoop instance per thread.
29 // 28 //
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 Type type() const { return type_; } 193 Type type() const { return type_; }
195 194
196 // Optional call to connect the thread name with this loop. 195 // Optional call to connect the thread name with this loop.
197 void set_thread_name(const std::string& thread_name) { 196 void set_thread_name(const std::string& thread_name) {
198 DCHECK(thread_name_.empty()) << "Should not rename this thread!"; 197 DCHECK(thread_name_.empty()) << "Should not rename this thread!";
199 thread_name_ = thread_name; 198 thread_name_ = thread_name;
200 } 199 }
201 const std::string& thread_name() const { return thread_name_; } 200 const std::string& thread_name() const { return thread_name_; }
202 201
203 // Returns the MessageLoop object for the current thread, or null if none. 202 // Returns the MessageLoop object for the current thread, or null if none.
204 static MessageLoop* current() { 203 static MessageLoop* current();
205 MessageLoop* loop = static_cast<MessageLoop*>(tls_index_.Get());
206 // TODO(darin): sadly, we cannot enable this yet since people call us even
207 // when they have no intention of using us.
208 //DCHECK(loop) << "Ouch, did you forget to initialize me?";
209 return loop;
210 }
211 204
212 // Enables or disables the recursive task processing. This happens in the case 205 // Enables or disables the recursive task processing. This happens in the case
213 // of recursive message loops. Some unwanted message loop may occurs when 206 // of recursive message loops. Some unwanted message loop may occurs when
214 // using common controls or printer functions. By default, recursive task 207 // using common controls or printer functions. By default, recursive task
215 // processing is disabled. 208 // processing is disabled.
216 // 209 //
217 // The specific case where tasks get queued is: 210 // The specific case where tasks get queued is:
218 // - The thread is running a message loop. 211 // - The thread is running a message loop.
219 // - It receives a task #1 and execute it. 212 // - It receives a task #1 and execute it.
220 // - The task #1 implicitly start a message loop, like a MessageBox in the 213 // - The task #1 implicitly start a message loop, like a MessageBox in the
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 329
337 // Start recording histogram info about events and action IF it was enabled 330 // Start recording histogram info about events and action IF it was enabled
338 // and IF the statistics recorder can accept a registration of our histogram. 331 // and IF the statistics recorder can accept a registration of our histogram.
339 void StartHistogrammer(); 332 void StartHistogrammer();
340 333
341 // Add occurence of event to our histogram, so that we can see what is being 334 // Add occurence of event to our histogram, so that we can see what is being
342 // done in a specific MessageLoop instance (i.e., specific thread). 335 // done in a specific MessageLoop instance (i.e., specific thread).
343 // If message_histogram_ is NULL, this is a no-op. 336 // If message_histogram_ is NULL, this is a no-op.
344 void HistogramEvent(int event); 337 void HistogramEvent(int event);
345 338
346 static TLSSlot tls_index_;
347 static const LinearHistogram::DescriptionPair event_descriptions_[]; 339 static const LinearHistogram::DescriptionPair event_descriptions_[];
348 static bool enable_histogrammer_; 340 static bool enable_histogrammer_;
349 341
350 Type type_; 342 Type type_;
351 343
352 // A list of tasks that need to be processed by this instance. Note that 344 // A list of tasks that need to be processed by this instance. Note that
353 // this queue is only accessed (push/pop) by our current thread. 345 // this queue is only accessed (push/pop) by our current thread.
354 TaskQueue work_queue_; 346 TaskQueue work_queue_;
355 347
356 // Contains delayed tasks, sorted by their 'delayed_run_time' property. 348 // Contains delayed tasks, sorted by their 'delayed_run_time' property.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 #endif // defined(OS_WIN) 448 #endif // defined(OS_WIN)
457 }; 449 };
458 450
459 // Do not add any member variables to MessageLoopForIO! This is important b/c 451 // Do not add any member variables to MessageLoopForIO! This is important b/c
460 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 452 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
461 // data that you need should be stored on the MessageLoop's pump_ instance. 453 // data that you need should be stored on the MessageLoop's pump_ instance.
462 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 454 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
463 MessageLoopForIO_should_not_have_extra_member_variables); 455 MessageLoopForIO_should_not_have_extra_member_variables);
464 456
465 #endif // BASE_MESSAGE_LOOP_H_ 457 #endif // BASE_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « no previous file | base/message_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698