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

Side by Side Diff: base/message_loop.h

Issue 7518032: Android's paths and message loop implementation with JNI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix dependence again. Created 9 years, 4 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
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 BASE_MESSAGE_LOOP_H_ 5 #ifndef BASE_MESSAGE_LOOP_H_
6 #define BASE_MESSAGE_LOOP_H_ 6 #define BASE_MESSAGE_LOOP_H_
7 #pragma once 7 #pragma once
8 8
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // Normally, it is not necessary to instantiate a MessageLoop. Instead, it 108 // Normally, it is not necessary to instantiate a MessageLoop. Instead, it
109 // is typical to make use of the current thread's MessageLoop instance. 109 // is typical to make use of the current thread's MessageLoop instance.
110 explicit MessageLoop(Type type = TYPE_DEFAULT); 110 explicit MessageLoop(Type type = TYPE_DEFAULT);
111 virtual ~MessageLoop(); 111 virtual ~MessageLoop();
112 112
113 // Returns the MessageLoop object for the current thread, or null if none. 113 // Returns the MessageLoop object for the current thread, or null if none.
114 static MessageLoop* current(); 114 static MessageLoop* current();
115 115
116 static void EnableHistogrammer(bool enable_histogrammer); 116 static void EnableHistogrammer(bool enable_histogrammer);
117 117
118 typedef base::MessagePump* (MessagePumpFactory)();
119 // Using the given base::MessagePumpForUIFactory to override the default
M-A Ruel 2011/11/11 13:09:07 Can you use an action sentence instead?
120 // MessagePump implementation for 'TYPE_UI'.
121 static void InitMessagePumpForUIFactory(MessagePumpFactory* factory);
122
118 // A DestructionObserver is notified when the current MessageLoop is being 123 // A DestructionObserver is notified when the current MessageLoop is being
119 // destroyed. These obsevers are notified prior to MessageLoop::current() 124 // destroyed. These obsevers are notified prior to MessageLoop::current()
120 // being changed to return NULL. This gives interested parties the chance to 125 // being changed to return NULL. This gives interested parties the chance to
121 // do final cleanup that depends on the MessageLoop. 126 // do final cleanup that depends on the MessageLoop.
122 // 127 //
123 // NOTE: Any tasks posted to the MessageLoop during this notification will 128 // NOTE: Any tasks posted to the MessageLoop during this notification will
124 // not be run. Instead, they will be deleted. 129 // not be run. Instead, they will be deleted.
125 // 130 //
126 class BASE_API DestructionObserver { 131 class BASE_API DestructionObserver {
127 public: 132 public:
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 //---------------------------------------------------------------------------- 366 //----------------------------------------------------------------------------
362 protected: 367 protected:
363 struct RunState { 368 struct RunState {
364 // Used to count how many Run() invocations are on the stack. 369 // Used to count how many Run() invocations are on the stack.
365 int run_depth; 370 int run_depth;
366 371
367 // Used to record that Quit() was called, or that we should quit the pump 372 // Used to record that Quit() was called, or that we should quit the pump
368 // once it becomes idle. 373 // once it becomes idle.
369 bool quit_received; 374 bool quit_received;
370 375
371 #if !defined(OS_MACOSX) 376 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
372 Dispatcher* dispatcher; 377 Dispatcher* dispatcher;
373 #endif 378 #endif
374 }; 379 };
375 380
381 #if defined(OS_ANDROID)
382 // Android Java process manages the UI thread message loop. So its
383 // MessagePumpForUI needs to keep the RunState.
384 public:
385 #endif
376 class BASE_API AutoRunState : RunState { 386 class BASE_API AutoRunState : RunState {
377 public: 387 public:
378 explicit AutoRunState(MessageLoop* loop); 388 explicit AutoRunState(MessageLoop* loop);
379 ~AutoRunState(); 389 ~AutoRunState();
380 private: 390 private:
381 MessageLoop* loop_; 391 MessageLoop* loop_;
382 RunState* previous_state_; 392 RunState* previous_state_;
383 }; 393 };
394 #if defined(OS_ANDROID)
395 protected:
396 #endif
384 397
385 // This structure is copied around by value. 398 // This structure is copied around by value.
386 struct PendingTask { 399 struct PendingTask {
387 PendingTask(const base::Closure& task, 400 PendingTask(const base::Closure& task,
388 const tracked_objects::Location& posted_from, 401 const tracked_objects::Location& posted_from,
389 base::TimeTicks delayed_run_time, 402 base::TimeTicks delayed_run_time,
390 bool nestable); 403 bool nestable);
391 ~PendingTask(); 404 ~PendingTask();
392 405
393 // Used to support sorting. 406 // Used to support sorting.
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 static MessageLoopForUI* current() { 589 static MessageLoopForUI* current() {
577 MessageLoop* loop = MessageLoop::current(); 590 MessageLoop* loop = MessageLoop::current();
578 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); 591 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type());
579 return static_cast<MessageLoopForUI*>(loop); 592 return static_cast<MessageLoopForUI*>(loop);
580 } 593 }
581 594
582 #if defined(OS_WIN) 595 #if defined(OS_WIN)
583 void DidProcessMessage(const MSG& message); 596 void DidProcessMessage(const MSG& message);
584 #endif // defined(OS_WIN) 597 #endif // defined(OS_WIN)
585 598
586 #if !defined(OS_MACOSX) 599 #if defined(OS_ANDROID)
600 // On Android, the UI message loop is handled by Java side. So Run() should
601 // never be called. Instead use Start(), which will forward all the native UI
602 // events to the Java message loop.
603 void Start();
604 #elif !defined(OS_MACOSX)
587 // Please see message_pump_win/message_pump_glib for definitions of these 605 // Please see message_pump_win/message_pump_glib for definitions of these
588 // methods. 606 // methods.
589 void AddObserver(Observer* observer); 607 void AddObserver(Observer* observer);
590 void RemoveObserver(Observer* observer); 608 void RemoveObserver(Observer* observer);
591 void Run(Dispatcher* dispatcher); 609 void Run(Dispatcher* dispatcher);
592 610
593 protected: 611 protected:
594 // TODO(rvargas): Make this platform independent. 612 // TODO(rvargas): Make this platform independent.
595 base::MessagePumpForUI* pump_ui() { 613 base::MessagePumpForUI* pump_ui() {
596 return static_cast<base::MessagePumpForUI*>(pump_.get()); 614 return static_cast<base::MessagePumpForUI*>(pump_.get());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 #endif // defined(OS_POSIX) 693 #endif // defined(OS_POSIX)
676 }; 694 };
677 695
678 // Do not add any member variables to MessageLoopForIO! This is important b/c 696 // Do not add any member variables to MessageLoopForIO! This is important b/c
679 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 697 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
680 // data that you need should be stored on the MessageLoop's pump_ instance. 698 // data that you need should be stored on the MessageLoop's pump_ instance.
681 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 699 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
682 MessageLoopForIO_should_not_have_extra_member_variables); 700 MessageLoopForIO_should_not_have_extra_member_variables);
683 701
684 #endif // BASE_MESSAGE_LOOP_H_ 702 #endif // BASE_MESSAGE_LOOP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698