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

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

Issue 306032: Simplify threading in browser thread by making only ChromeThread deal with di... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: a few more simplifications Created 11 years, 1 month 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) 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 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/user_data_manager.h" 7 #include "chrome/browser/user_data_manager.h"
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 void UserDataManager::LaunchChromeForProfile(int index) const { 204 void UserDataManager::LaunchChromeForProfile(int index) const {
205 // Helper deletes itself when done. 205 // Helper deletes itself when done.
206 LaunchChromeForProfileIndexHelper* helper = 206 LaunchChromeForProfileIndexHelper* helper =
207 new LaunchChromeForProfileIndexHelper(this, index); 207 new LaunchChromeForProfileIndexHelper(this, index);
208 helper->StartLaunch(); 208 helper->StartLaunch();
209 } 209 }
210 210
211 void UserDataManager::GetProfiles(std::vector<std::wstring>* profiles) const { 211 void UserDataManager::GetProfiles(std::vector<std::wstring>* profiles) const {
212 // This function should be called on the file thread. 212 // This function should be called on the file thread.
213 DCHECK(MessageLoop::current() == 213 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
214 ChromeThread::GetMessageLoop(ChromeThread::FILE));
215 file_util::FileEnumerator file_enum( 214 file_util::FileEnumerator file_enum(
216 FilePath::FromWStringHack(user_data_root_), 215 FilePath::FromWStringHack(user_data_root_),
217 false, file_util::FileEnumerator::DIRECTORIES); 216 false, file_util::FileEnumerator::DIRECTORIES);
218 std::wstring folder_name; 217 std::wstring folder_name;
219 while (!(folder_name = file_enum.Next().ToWStringHack()).empty()) { 218 while (!(folder_name = file_enum.Next().ToWStringHack()).empty()) {
220 folder_name = file_util::GetFilenameFromPath(folder_name); 219 folder_name = file_util::GetFilenameFromPath(folder_name);
221 std::wstring profile_name; 220 std::wstring profile_name;
222 if (GetProfileNameFromFolderName(folder_name, &profile_name)) 221 if (GetProfileNameFromFolderName(folder_name, &profile_name))
223 profiles->push_back(profile_name); 222 profiles->push_back(profile_name);
224 } 223 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 void GetProfilesHelper::GetProfiles(MessageLoop* target_loop) { 273 void GetProfilesHelper::GetProfiles(MessageLoop* target_loop) {
275 // If the target loop is not NULL then use the target loop, or if it's NULL 274 // If the target loop is not NULL then use the target loop, or if it's NULL
276 // then use the current message loop to post a task on it later when we are 275 // then use the current message loop to post a task on it later when we are
277 // done building a list of profiles. 276 // done building a list of profiles.
278 if (target_loop) { 277 if (target_loop) {
279 message_loop_ = target_loop; 278 message_loop_ = target_loop;
280 } else { 279 } else {
281 message_loop_ = MessageLoop::current(); 280 message_loop_ = MessageLoop::current();
282 } 281 }
283 DCHECK(message_loop_); 282 DCHECK(message_loop_);
284 MessageLoop* file_loop = ChromeThread::GetMessageLoop(ChromeThread::FILE); 283 ChromeThread::PostTask(
285 file_loop->PostTask( 284 ChromeThread::FILE, FROM_HERE,
286 FROM_HERE,
287 NewRunnableMethod(this, &GetProfilesHelper::GetProfilesFromManager)); 285 NewRunnableMethod(this, &GetProfilesHelper::GetProfilesFromManager));
288 } 286 }
289 287
290 // Records that the delegate is closed. 288 // Records that the delegate is closed.
291 void GetProfilesHelper::OnDelegateDeleted() { 289 void GetProfilesHelper::OnDelegateDeleted() {
292 delegate_ = NULL; 290 delegate_ = NULL;
293 } 291 }
294 292
295 void GetProfilesHelper::GetProfilesFromManager() { 293 void GetProfilesHelper::GetProfilesFromManager() {
296 // This function should be called on the file thread. 294 // This function should be called on the file thread.
297 DCHECK(MessageLoop::current() == 295 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
298 ChromeThread::GetMessageLoop(ChromeThread::FILE));
299 296
300 // If the delegate is gone by now, no need to do any work. 297 // If the delegate is gone by now, no need to do any work.
301 if (!delegate_) 298 if (!delegate_)
302 return; 299 return;
303 300
304 scoped_ptr< std::vector<std::wstring> > profiles( 301 scoped_ptr< std::vector<std::wstring> > profiles(
305 new std::vector<std::wstring>); 302 new std::vector<std::wstring>);
306 UserDataManager::Get()->GetProfiles(profiles.get()); 303 UserDataManager::Get()->GetProfiles(profiles.get());
307 304
308 // Post a task on the original thread to call the delegate. 305 // Post a task on the original thread to call the delegate.
309 message_loop_->PostTask( 306 message_loop_->PostTask(
310 FROM_HERE, 307 FROM_HERE,
311 NewRunnableMethod(this, 308 NewRunnableMethod(this,
312 &GetProfilesHelper::InvokeDelegate, 309 &GetProfilesHelper::InvokeDelegate,
313 profiles.release())); 310 profiles.release()));
314 } 311 }
315 312
316 void GetProfilesHelper::InvokeDelegate(std::vector<std::wstring>* profiles) { 313 void GetProfilesHelper::InvokeDelegate(std::vector<std::wstring>* profiles) {
317 scoped_ptr< std::vector<std::wstring> > udd_profiles(profiles); 314 scoped_ptr< std::vector<std::wstring> > udd_profiles(profiles);
318 // If the delegate is gone by now, no need to do any work. 315 // If the delegate is gone by now, no need to do any work.
319 if (delegate_) 316 if (delegate_)
320 delegate_->OnGetProfilesDone(*udd_profiles.get()); 317 delegate_->OnGetProfilesDone(*udd_profiles.get());
321 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698