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

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

Issue 27159: Avoid race crash: Don't drop reference to URL fetcher until data is extracted... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | « no previous file | no next file » | 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) 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 "chrome/browser/spellchecker.h" 5 #include "chrome/browser/spellchecker.h"
6 #include "base/basictypes.h" 6 #include "base/basictypes.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 public: 243 public:
244 DictionaryDownloadController( 244 DictionaryDownloadController(
245 Task* spellchecker_flag_set_task, 245 Task* spellchecker_flag_set_task,
246 const FilePath& dic_file_path, 246 const FilePath& dic_file_path,
247 URLRequestContext* url_request_context, 247 URLRequestContext* url_request_context,
248 MessageLoop* ui_loop) 248 MessageLoop* ui_loop)
249 : spellchecker_flag_set_task_(spellchecker_flag_set_task), 249 : spellchecker_flag_set_task_(spellchecker_flag_set_task),
250 url_request_context_(url_request_context), 250 url_request_context_(url_request_context),
251 ui_loop_(ui_loop) { 251 ui_loop_(ui_loop) {
252 // Determine dictionary file path and name. 252 // Determine dictionary file path and name.
253 fetcher_.reset(NULL);
254 dic_zip_file_path_ = dic_file_path.DirName(); 253 dic_zip_file_path_ = dic_file_path.DirName();
255 file_name_ = dic_file_path.BaseName(); 254 file_name_ = dic_file_path.BaseName();
256 } 255 }
257 256
258 // Save the file in memory buffer to the designated dictionary file. 257 // Save the file in memory buffer to the designated dictionary file.
259 // returns the number of bytes it could save. 258 // returns the number of bytes it could save.
260 // Invoke this on the file thread. 259 // Invoke this on the file thread.
261 void StartDownload() { 260 void StartDownload() {
262 static const char kDownloadServerUrl[] = 261 static const char kDownloadServerUrl[] =
263 "http://cache.pack.google.com/edgedl/chrome/dict/"; 262 "http://cache.pack.google.com/edgedl/chrome/dict/";
(...skipping 15 matching lines...) Expand all
279 } 278 }
280 279
281 // URLFetcher::Delegate interface. 280 // URLFetcher::Delegate interface.
282 virtual void OnURLFetchComplete(const URLFetcher* source, 281 virtual void OnURLFetchComplete(const URLFetcher* source,
283 const GURL& url, 282 const GURL& url,
284 const URLRequestStatus& status, 283 const URLRequestStatus& status,
285 int response_code, 284 int response_code,
286 const ResponseCookies& cookies, 285 const ResponseCookies& cookies,
287 const std::string& data) { 286 const std::string& data) {
288 DCHECK(source); 287 DCHECK(source);
289 fetcher_.reset(NULL);
290 bool save_success = false; 288 bool save_success = false;
291 if ((response_code / 100) == 2 || 289 if ((response_code / 100) == 2 ||
292 response_code == 401 || 290 response_code == 401 ||
293 response_code == 407) { 291 response_code == 407) {
294 save_success = SaveBufferToFile(data); 292 save_success = SaveBufferToFile(data);
295 } // Unsuccessful save is taken care of in SpellChecker::Initialize(). 293 } // Unsuccessful save is taken care of in SpellChecker::Initialize().
296 294
297 // Set Flag that dictionary is not downloading anymore. 295 // Set Flag that dictionary is not downloading anymore.
298 ui_loop_->PostTask(FROM_HERE, 296 ui_loop_->PostTask(FROM_HERE,
299 new UIProxyForIOTask(spellchecker_flag_set_task_)); 297 new UIProxyForIOTask(spellchecker_flag_set_task_));
298 fetcher_.reset(NULL);
300 } 299 }
301 300
302 // factory object to invokelater back to spellchecker in io thread on 301 // factory object to invokelater back to spellchecker in io thread on
303 // download completion to change appropriate flags. 302 // download completion to change appropriate flags.
304 Task* spellchecker_flag_set_task_; 303 Task* spellchecker_flag_set_task_;
305 304
306 // URLRequestContext to be used by URLFetcher. This is obtained from profile. 305 // URLRequestContext to be used by URLFetcher. This is obtained from profile.
307 // The ownership remains with the profile. 306 // The ownership remains with the profile.
308 URLRequestContext* url_request_context_; 307 URLRequestContext* url_request_context_;
309 308
(...skipping 22 matching lines...) Expand all
332 FilePath SpellChecker::GetVersionedFileName(const Language& input_language, 331 FilePath SpellChecker::GetVersionedFileName(const Language& input_language,
333 const FilePath& dict_dir) { 332 const FilePath& dict_dir) {
334 // The default version string currently in use. 333 // The default version string currently in use.
335 static const wchar_t kDefaultVersionString[] = L"-1-2"; 334 static const wchar_t kDefaultVersionString[] = L"-1-2";
336 335
337 // Use this struct to insert version strings for dictionary files which have 336 // Use this struct to insert version strings for dictionary files which have
338 // special version strings, other than the default version string. For eight 337 // special version strings, other than the default version string. For eight
339 // languages (included below in the struct), the version is kept at 1-1. The 338 // languages (included below in the struct), the version is kept at 1-1. The
340 // others (19 of them) have been updated to new default version 1-2 which 339 // others (19 of them) have been updated to new default version 1-2 which
341 // contains many new words. 340 // contains many new words.
342 // TODO (sidchat): Work on these 8 languages to bring them upto version 1-2. 341 // TODO(sidchat): Work on these 8 languages to bring them upto version 1-2.
343 static const struct { 342 static const struct {
344 // The language input. 343 // The language input.
345 const char* language; 344 const char* language;
346 345
347 // The corresponding version. 346 // The corresponding version.
348 const char* version; 347 const char* version;
349 } special_version_string[] = { 348 } special_version_string[] = {
350 {"en-GB", "-1-1"}, 349 {"en-GB", "-1-1"},
351 {"es-ES", "-1-1"}, 350 {"es-ES", "-1-1"},
352 {"nl-NL", "-1-1"}, 351 {"nl-NL", "-1-1"},
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 DHISTOGRAM_TIMES("Spellcheck.InitTime", TimeTicks::Now() - begin_time); 468 DHISTOGRAM_TIMES("Spellcheck.InitTime", TimeTicks::Now() - begin_time);
470 469
471 tried_to_init_ = true; 470 tried_to_init_ = true;
472 return false; 471 return false;
473 } 472 }
474 473
475 void SpellChecker::AddCustomWordsToHunspell() { 474 void SpellChecker::AddCustomWordsToHunspell() {
476 // Add custom words to Hunspell. 475 // Add custom words to Hunspell.
477 // This should be done in File Loop, but since Hunspell is in this IO Loop, 476 // This should be done in File Loop, but since Hunspell is in this IO Loop,
478 // this too has to be initialized here. 477 // this too has to be initialized here.
479 // TODO (sidchat): Work out a way to initialize Hunspell in the File Loop. 478 // TODO(sidchat): Work out a way to initialize Hunspell in the File Loop.
480 std::string contents; 479 std::string contents;
481 file_util::ReadFileToString(custom_dictionary_file_name_, &contents); 480 file_util::ReadFileToString(custom_dictionary_file_name_, &contents);
482 std::vector<std::string> list_of_words; 481 std::vector<std::string> list_of_words;
483 SplitString(contents, '\n', &list_of_words); 482 SplitString(contents, '\n', &list_of_words);
484 if (hunspell_.get()) { 483 if (hunspell_.get()) {
485 for (std::vector<std::string>::iterator it = list_of_words.begin(); 484 for (std::vector<std::string>::iterator it = list_of_words.begin();
486 it != list_of_words.end(); ++it) { 485 it != list_of_words.end(); ++it) {
487 hunspell_->put_word(it->c_str()); 486 hunspell_->put_word(it->c_str());
488 } 487 }
489 } 488 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 hunspell_->put_word(word_to_add.c_str()); 624 hunspell_->put_word(word_to_add.c_str());
626 625
627 // Now add the word to the custom dictionary file. 626 // Now add the word to the custom dictionary file.
628 Task* write_word_task = 627 Task* write_word_task =
629 new AddWordToCustomDictionaryTask(custom_dictionary_file_name_, word); 628 new AddWordToCustomDictionaryTask(custom_dictionary_file_name_, word);
630 if (file_loop_) 629 if (file_loop_)
631 file_loop_->PostTask(FROM_HERE, write_word_task); 630 file_loop_->PostTask(FROM_HERE, write_word_task);
632 else 631 else
633 write_word_task->Run(); 632 write_word_task->Run();
634 } 633 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698