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

Side by Side Diff: chrome/browser/spellchecker.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-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/spellchecker.h" 5 #include "chrome/browser/spellchecker.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Try saving it to |fallback_file_name_|, which almost surely has 193 // Try saving it to |fallback_file_name_|, which almost surely has
194 // write permission. If even this fails, there is nothing to be done. 194 // write permission. If even this fails, there is nothing to be done.
195 FilePath fallback_dir = fallback_file_name_.DirName(); 195 FilePath fallback_dir = fallback_file_name_.DirName();
196 // Create the directory if it does not exist. 196 // Create the directory if it does not exist.
197 if (!file_util::PathExists(fallback_dir)) 197 if (!file_util::PathExists(fallback_dir))
198 file_util::CreateDirectory(fallback_dir); 198 file_util::CreateDirectory(fallback_dir);
199 SaveBufferToFile(data_, fallback_file_name_); 199 SaveBufferToFile(data_, fallback_file_name_);
200 } // Unsuccessful save is taken care of in SpellChecker::Initialize(). 200 } // Unsuccessful save is taken care of in SpellChecker::Initialize().
201 201
202 // Set Flag that dictionary is not downloading anymore. 202 // Set Flag that dictionary is not downloading anymore.
203 MessageLoop* ui_loop = ChromeThread::GetMessageLoop(ChromeThread::UI); 203 ChromeThread::PostTask(
204 ui_loop->PostTask(FROM_HERE, 204 ChromeThread::UI, FROM_HERE,
205 new UIProxyForIOTask(on_dictionary_save_complete_callback_task_, NULL)); 205 new UIProxyForIOTask(on_dictionary_save_complete_callback_task_, NULL));
206 } 206 }
207 207
208 // Design: this task tries to read the dictionary from disk and load it into 208 // Design: this task tries to read the dictionary from disk and load it into
209 // memory. It is executed on the file thread, and posts the results back to 209 // memory. It is executed on the file thread, and posts the results back to
210 // the IO thread (via the UI thread---see UIProxyForIOTask). 210 // the IO thread (via the UI thread---see UIProxyForIOTask).
211 // The task first checks for the existence of the dictionary in one of the two 211 // The task first checks for the existence of the dictionary in one of the two
212 // given locations. If it does not exist, the task informs the SpellChecker, 212 // given locations. If it does not exist, the task informs the SpellChecker,
213 // which will try to download the directory and run a new ReadDictionaryTask. 213 // which will try to download the directory and run a new ReadDictionaryTask.
214 class ReadDictionaryTask : public Task { 214 class ReadDictionaryTask : public Task {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 261 }
262 262
263 Finish(true); 263 Finish(true);
264 } 264 }
265 265
266 private: 266 private:
267 void Finish(bool file_existed) { 267 void Finish(bool file_existed) {
268 Task* task = NewRunnableMethod(spellchecker_, &SpellChecker::HunspellInited, 268 Task* task = NewRunnableMethod(spellchecker_, &SpellChecker::HunspellInited,
269 hunspell_, bdict_file_, file_existed); 269 hunspell_, bdict_file_, file_existed);
270 if (spellchecker_->file_loop_) { 270 if (spellchecker_->file_loop_) {
271 MessageLoop* ui_loop = ChromeThread::GetMessageLoop(ChromeThread::UI);
272 // We were called on the file loop. Post back to the IO loop. 271 // We were called on the file loop. Post back to the IO loop.
273 // If this never gets posted to the IO loop, then we will leak |hunspell_| 272 // If this never gets posted to the IO loop, then we will leak |hunspell_|
274 // and |bdict_file_|. But that can only happen during shutdown, so it's 273 // and |bdict_file_|. But that can only happen during shutdown, so it's
275 // not worth caring about. 274 // not worth caring about.
276 ui_loop->PostTask(FROM_HERE, new UIProxyForIOTask(task, spellchecker_)); 275 ChromeThread::PostTask(
276 ChromeThread::UI, FROM_HERE,
277 new UIProxyForIOTask(task, spellchecker_));
277 } else { 278 } else {
278 // We were called directly (e.g., during testing). Run the task directly. 279 // We were called directly (e.g., during testing). Run the task directly.
279 task->Run(); 280 task->Run();
280 delete task; 281 delete task;
281 } 282 }
282 } 283 }
283 284
284 // The SpellChecker we are working for. We are guaranteed to be outlived 285 // The SpellChecker we are working for. We are guaranteed to be outlived
285 // by this object because it AddRefs() itself before calling us. 286 // by this object because it AddRefs() itself before calling us.
286 // Accessing it is not necessarily thread safe, but are careful to only access 287 // Accessing it is not necessarily thread safe, but are careful to only access
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 896
896 // Populate the vector of WideStrings. 897 // Populate the vector of WideStrings.
897 for (int i = 0; i < number_of_suggestions; i++) { 898 for (int i = 0; i < number_of_suggestions; i++) {
898 if (i < kMaxSuggestions) 899 if (i < kMaxSuggestions)
899 optional_suggestions->push_back(UTF8ToUTF16(suggestions[i])); 900 optional_suggestions->push_back(UTF8ToUTF16(suggestions[i]));
900 free(suggestions[i]); 901 free(suggestions[i]);
901 } 902 }
902 if (suggestions != NULL) 903 if (suggestions != NULL)
903 free(suggestions); 904 free(suggestions);
904 } 905 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698