OLD | NEW |
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 #include "chrome/browser/ui/cocoa/run_loop_testing.h" | 5 #include "chrome/browser/ui/cocoa/run_loop_testing.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
| 9 #include <memory> |
| 10 |
9 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/message_loop/message_pump_mac.h" | 12 #include "base/message_loop/message_pump_mac.h" |
12 | 13 |
13 // This class is scheduled with a delayed selector to quit the message pump. | 14 // This class is scheduled with a delayed selector to quit the message pump. |
14 @interface CocoaQuitTask : NSObject { | 15 @interface CocoaQuitTask : NSObject { |
15 @private | 16 @private |
16 base::MessagePumpNSRunLoop* pump_; | 17 base::MessagePumpNSRunLoop* pump_; |
17 } | 18 } |
18 - (id)initWithMessagePump:(base::MessagePumpNSRunLoop*)pump; | 19 - (id)initWithMessagePump:(base::MessagePumpNSRunLoop*)pump; |
19 - (void)doQuit; | 20 - (void)doQuit; |
20 @end | 21 @end |
(...skipping 10 matching lines...) Expand all Loading... |
31 pump_->Quit(); | 32 pump_->Quit(); |
32 } | 33 } |
33 @end | 34 @end |
34 | 35 |
35 //////////////////////////////////////////////////////////////////////////////// | 36 //////////////////////////////////////////////////////////////////////////////// |
36 | 37 |
37 namespace chrome { | 38 namespace chrome { |
38 namespace testing { | 39 namespace testing { |
39 | 40 |
40 void NSRunLoopRunAllPending() { | 41 void NSRunLoopRunAllPending() { |
41 scoped_ptr<base::MessagePumpNSRunLoop> message_pump( | 42 std::unique_ptr<base::MessagePumpNSRunLoop> message_pump( |
42 new base::MessagePumpNSRunLoop); | 43 new base::MessagePumpNSRunLoop); |
43 | 44 |
44 // Put a delayed selector on the queue. All other pending delayed selectors | 45 // Put a delayed selector on the queue. All other pending delayed selectors |
45 // will run before this, after which the internal loop can end. | 46 // will run before this, after which the internal loop can end. |
46 base::scoped_nsobject<CocoaQuitTask> quit_task( | 47 base::scoped_nsobject<CocoaQuitTask> quit_task( |
47 [[CocoaQuitTask alloc] initWithMessagePump:message_pump.get()]); | 48 [[CocoaQuitTask alloc] initWithMessagePump:message_pump.get()]); |
48 | 49 |
49 [quit_task performSelector:@selector(doQuit) | 50 [quit_task performSelector:@selector(doQuit) |
50 withObject:nil | 51 withObject:nil |
51 afterDelay:0]; | 52 afterDelay:0]; |
52 | 53 |
53 // Spin the internal loop, running it until the quit task is pumped. Pass NULL | 54 // Spin the internal loop, running it until the quit task is pumped. Pass NULL |
54 // because there is no delegate MessageLoop; only the Cocoa work queues will | 55 // because there is no delegate MessageLoop; only the Cocoa work queues will |
55 // be pumped. | 56 // be pumped. |
56 message_pump->Run(NULL); | 57 message_pump->Run(NULL); |
57 } | 58 } |
58 | 59 |
59 } // namespace testing | 60 } // namespace testing |
60 } // namespace chrome | 61 } // namespace chrome |
OLD | NEW |