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

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

Issue 6142009: Upating the app, ceee, chrome, ipc, media, and net directories to use the correct lock.h file. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Unified patch updating all references to the new base/synchronization/lock.h Created 9 years, 11 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/browser_thread.h ('k') | chrome/browser/cancelable_request.h » ('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/browser_thread.h" 5 #include "chrome/browser/browser_thread.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 virtual bool BelongsToCurrentThread() { 56 virtual bool BelongsToCurrentThread() {
57 return BrowserThread::CurrentlyOn(id_); 57 return BrowserThread::CurrentlyOn(id_);
58 } 58 }
59 59
60 private: 60 private:
61 BrowserThread::ID id_; 61 BrowserThread::ID id_;
62 DISALLOW_COPY_AND_ASSIGN(BrowserThreadMessageLoopProxy); 62 DISALLOW_COPY_AND_ASSIGN(BrowserThreadMessageLoopProxy);
63 }; 63 };
64 64
65 65
66 Lock BrowserThread::lock_; 66 base::Lock BrowserThread::lock_;
67 67
68 BrowserThread* BrowserThread::browser_threads_[ID_COUNT]; 68 BrowserThread* BrowserThread::browser_threads_[ID_COUNT];
69 69
70 BrowserThread::BrowserThread(BrowserThread::ID identifier) 70 BrowserThread::BrowserThread(BrowserThread::ID identifier)
71 : Thread(browser_thread_names[identifier]), 71 : Thread(browser_thread_names[identifier]),
72 identifier_(identifier) { 72 identifier_(identifier) {
73 Initialize(); 73 Initialize();
74 } 74 }
75 75
76 BrowserThread::BrowserThread(ID identifier, MessageLoop* message_loop) 76 BrowserThread::BrowserThread(ID identifier, MessageLoop* message_loop)
77 : Thread(message_loop->thread_name().c_str()), 77 : Thread(message_loop->thread_name().c_str()),
78 identifier_(identifier) { 78 identifier_(identifier) {
79 set_message_loop(message_loop); 79 set_message_loop(message_loop);
80 Initialize(); 80 Initialize();
81 } 81 }
82 82
83 void BrowserThread::Initialize() { 83 void BrowserThread::Initialize() {
84 AutoLock lock(lock_); 84 base::AutoLock lock(lock_);
85 DCHECK(identifier_ >= 0 && identifier_ < ID_COUNT); 85 DCHECK(identifier_ >= 0 && identifier_ < ID_COUNT);
86 DCHECK(browser_threads_[identifier_] == NULL); 86 DCHECK(browser_threads_[identifier_] == NULL);
87 browser_threads_[identifier_] = this; 87 browser_threads_[identifier_] = this;
88 } 88 }
89 89
90 BrowserThread::~BrowserThread() { 90 BrowserThread::~BrowserThread() {
91 // Stop the thread here, instead of the parent's class destructor. This is so 91 // Stop the thread here, instead of the parent's class destructor. This is so
92 // that if there are pending tasks that run, code that checks that it's on the 92 // that if there are pending tasks that run, code that checks that it's on the
93 // correct BrowserThread succeeds. 93 // correct BrowserThread succeeds.
94 Stop(); 94 Stop();
95 95
96 AutoLock lock(lock_); 96 base::AutoLock lock(lock_);
97 browser_threads_[identifier_] = NULL; 97 browser_threads_[identifier_] = NULL;
98 #ifndef NDEBUG 98 #ifndef NDEBUG
99 // Double check that the threads are ordered correctly in the enumeration. 99 // Double check that the threads are ordered correctly in the enumeration.
100 for (int i = identifier_ + 1; i < ID_COUNT; ++i) { 100 for (int i = identifier_ + 1; i < ID_COUNT; ++i) {
101 DCHECK(!browser_threads_[i]) << 101 DCHECK(!browser_threads_[i]) <<
102 "Threads must be listed in the reverse order that they die"; 102 "Threads must be listed in the reverse order that they die";
103 } 103 }
104 #endif 104 #endif
105 } 105 }
106 106
107 // static 107 // static
108 bool BrowserThread::IsWellKnownThread(ID identifier) { 108 bool BrowserThread::IsWellKnownThread(ID identifier) {
109 AutoLock lock(lock_); 109 base::AutoLock lock(lock_);
110 return (identifier >= 0 && identifier < ID_COUNT && 110 return (identifier >= 0 && identifier < ID_COUNT &&
111 browser_threads_[identifier]); 111 browser_threads_[identifier]);
112 } 112 }
113 113
114 // static 114 // static
115 bool BrowserThread::CurrentlyOn(ID identifier) { 115 bool BrowserThread::CurrentlyOn(ID identifier) {
116 // We shouldn't use MessageLoop::current() since it uses LazyInstance which 116 // We shouldn't use MessageLoop::current() since it uses LazyInstance which
117 // may be deleted by ~AtExitManager when a WorkerPool thread calls this 117 // may be deleted by ~AtExitManager when a WorkerPool thread calls this
118 // function. 118 // function.
119 // http://crbug.com/63678 119 // http://crbug.com/63678
120 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton; 120 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton;
121 AutoLock lock(lock_); 121 base::AutoLock lock(lock_);
122 DCHECK(identifier >= 0 && identifier < ID_COUNT); 122 DCHECK(identifier >= 0 && identifier < ID_COUNT);
123 return browser_threads_[identifier] && 123 return browser_threads_[identifier] &&
124 browser_threads_[identifier]->message_loop() == MessageLoop::current(); 124 browser_threads_[identifier]->message_loop() == MessageLoop::current();
125 } 125 }
126 126
127 // static 127 // static
128 bool BrowserThread::IsMessageLoopValid(ID identifier) { 128 bool BrowserThread::IsMessageLoopValid(ID identifier) {
129 AutoLock lock(lock_); 129 base::AutoLock lock(lock_);
130 DCHECK(identifier >= 0 && identifier < ID_COUNT); 130 DCHECK(identifier >= 0 && identifier < ID_COUNT);
131 return browser_threads_[identifier] && 131 return browser_threads_[identifier] &&
132 browser_threads_[identifier]->message_loop(); 132 browser_threads_[identifier]->message_loop();
133 } 133 }
134 134
135 // static 135 // static
136 bool BrowserThread::PostTask(ID identifier, 136 bool BrowserThread::PostTask(ID identifier,
137 const tracked_objects::Location& from_here, 137 const tracked_objects::Location& from_here,
138 Task* task) { 138 Task* task) {
139 return PostTaskHelper(identifier, from_here, task, 0, true); 139 return PostTaskHelper(identifier, from_here, task, 0, true);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 224 }
225 } else { 225 } else {
226 delete task; 226 delete task;
227 } 227 }
228 228
229 if (!guaranteed_to_outlive_target_thread) 229 if (!guaranteed_to_outlive_target_thread)
230 lock_.Release(); 230 lock_.Release();
231 231
232 return !!message_loop; 232 return !!message_loop;
233 } 233 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_thread.h ('k') | chrome/browser/cancelable_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698