OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/browser_thread_impl.h" | 5 #include "content/browser/browser_thread_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 void BrowserThreadImpl::Init() { | 97 void BrowserThreadImpl::Init() { |
98 BrowserThreadGlobals& globals = g_globals.Get(); | 98 BrowserThreadGlobals& globals = g_globals.Get(); |
99 | 99 |
100 using base::subtle::AtomicWord; | 100 using base::subtle::AtomicWord; |
101 AtomicWord* storage = | 101 AtomicWord* storage = |
102 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier_]); | 102 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier_]); |
103 AtomicWord stored_pointer = base::subtle::NoBarrier_Load(storage); | 103 AtomicWord stored_pointer = base::subtle::NoBarrier_Load(storage); |
104 BrowserThreadDelegate* delegate = | 104 BrowserThreadDelegate* delegate = |
105 reinterpret_cast<BrowserThreadDelegate*>(stored_pointer); | 105 reinterpret_cast<BrowserThreadDelegate*>(stored_pointer); |
106 if (delegate) | 106 if (delegate) { |
107 delegate->Init(); | 107 delegate->Init(); |
| 108 message_loop()->PostTask(FROM_HERE, |
| 109 base::Bind(&BrowserThreadDelegate::InitAsync, |
| 110 // Delegate is expected to exist for the |
| 111 // duration of the thread's lifetime |
| 112 base::Unretained(delegate))); |
| 113 } |
108 } | 114 } |
109 | 115 |
110 // We disable optimizations for this block of functions so the compiler doesn't | 116 // We disable optimizations for this block of functions so the compiler doesn't |
111 // merge them all together. | 117 // merge them all together. |
112 MSVC_DISABLE_OPTIMIZE() | 118 MSVC_DISABLE_OPTIMIZE() |
113 MSVC_PUSH_DISABLE_WARNING(4748) | 119 MSVC_PUSH_DISABLE_WARNING(4748) |
114 | 120 |
115 NOINLINE void BrowserThreadImpl::UIThreadRun(base::MessageLoop* message_loop) { | 121 NOINLINE void BrowserThreadImpl::UIThreadRun(base::MessageLoop* message_loop) { |
116 volatile int line_number = __LINE__; | 122 volatile int line_number = __LINE__; |
117 Thread::Run(message_loop); | 123 Thread::Run(message_loop); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 AtomicWord* storage = reinterpret_cast<AtomicWord*>( | 483 AtomicWord* storage = reinterpret_cast<AtomicWord*>( |
478 &globals.thread_delegates[identifier]); | 484 &globals.thread_delegates[identifier]); |
479 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( | 485 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( |
480 storage, reinterpret_cast<AtomicWord>(delegate)); | 486 storage, reinterpret_cast<AtomicWord>(delegate)); |
481 | 487 |
482 // This catches registration when previously registered. | 488 // This catches registration when previously registered. |
483 DCHECK(!delegate || !old_pointer); | 489 DCHECK(!delegate || !old_pointer); |
484 } | 490 } |
485 | 491 |
486 } // namespace content | 492 } // namespace content |
OLD | NEW |