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

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

Issue 258008: Move initialization of ChromeURLRequestContexts to the IO thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync again, just in case 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
« no previous file with comments | « chrome/browser/spellchecker.h ('k') | chrome/browser/sync/glue/http_bridge.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) 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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 language + special_version_string[i].version + ".bdic"; 456 language + special_version_string[i].version + ".bdic";
457 break; 457 break;
458 } 458 }
459 } 459 }
460 460
461 return dict_dir.AppendASCII(versioned_bdict_file_name); 461 return dict_dir.AppendASCII(versioned_bdict_file_name);
462 } 462 }
463 463
464 SpellChecker::SpellChecker(const FilePath& dict_dir, 464 SpellChecker::SpellChecker(const FilePath& dict_dir,
465 const std::string& language, 465 const std::string& language,
466 URLRequestContext* request_context, 466 URLRequestContextGetter* request_context_getter,
467 const FilePath& custom_dictionary_file_name) 467 const FilePath& custom_dictionary_file_name)
468 : given_dictionary_directory_(dict_dir), 468 : given_dictionary_directory_(dict_dir),
469 custom_dictionary_file_name_(custom_dictionary_file_name), 469 custom_dictionary_file_name_(custom_dictionary_file_name),
470 tried_to_init_(false), 470 tried_to_init_(false),
471 language_(language), 471 language_(language),
472 worker_loop_(NULL), 472 worker_loop_(NULL),
473 tried_to_download_dictionary_file_(false), 473 tried_to_download_dictionary_file_(false),
474 file_loop_(NULL), 474 file_loop_(NULL),
475 url_request_context_(request_context), 475 request_context_getter_(request_context_getter),
476 obtaining_dictionary_(false), 476 obtaining_dictionary_(false),
477 auto_spell_correct_turned_on_(false), 477 auto_spell_correct_turned_on_(false),
478 is_using_platform_spelling_engine_(false), 478 is_using_platform_spelling_engine_(false),
479 fetcher_(NULL), 479 fetcher_(NULL),
480 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 480 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
481 if (SpellCheckerPlatform::SpellCheckerAvailable()) { 481 if (SpellCheckerPlatform::SpellCheckerAvailable()) {
482 SpellCheckerPlatform::Init(); 482 SpellCheckerPlatform::Init();
483 if (SpellCheckerPlatform::PlatformSupportsLanguage(language)) { 483 if (SpellCheckerPlatform::PlatformSupportsLanguage(language)) {
484 // If we have reached here, then we know that the current platform 484 // If we have reached here, then we know that the current platform
485 // supports the given language and we will use it instead of hunspell. 485 // supports the given language and we will use it instead of hunspell.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 DCHECK(MessageLoop::current() == worker_loop_); 517 DCHECK(MessageLoop::current() == worker_loop_);
518 } 518 }
519 519
520 void SpellChecker::StartDictionaryDownload(const FilePath& file_name) { 520 void SpellChecker::StartDictionaryDownload(const FilePath& file_name) {
521 // Determine URL of file to download. 521 // Determine URL of file to download.
522 static const char kDownloadServerUrl[] = 522 static const char kDownloadServerUrl[] =
523 "http://cache.pack.google.com/edgedl/chrome/dict/"; 523 "http://cache.pack.google.com/edgedl/chrome/dict/";
524 GURL url = GURL(std::string(kDownloadServerUrl) + WideToUTF8( 524 GURL url = GURL(std::string(kDownloadServerUrl) + WideToUTF8(
525 l10n_util::ToLower(bdic_file_name_.ToWStringHack()))); 525 l10n_util::ToLower(bdic_file_name_.ToWStringHack())));
526 fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this)); 526 fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this));
527 fetcher_->set_request_context(url_request_context_); 527 fetcher_->set_request_context(request_context_getter_);
528 obtaining_dictionary_ = true; 528 obtaining_dictionary_ = true;
529 fetcher_->Start(); 529 fetcher_->Start();
530 } 530 }
531 531
532 void SpellChecker::OnURLFetchComplete(const URLFetcher* source, 532 void SpellChecker::OnURLFetchComplete(const URLFetcher* source,
533 const GURL& url, 533 const GURL& url,
534 const URLRequestStatus& status, 534 const URLRequestStatus& status,
535 int response_code, 535 int response_code,
536 const ResponseCookies& cookies, 536 const ResponseCookies& cookies,
537 const std::string& data) { 537 const std::string& data) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 hunspell_->add(custom_words_.front().c_str()); 647 hunspell_->add(custom_words_.front().c_str());
648 custom_words_.pop(); 648 custom_words_.pop();
649 } 649 }
650 650
651 // Balances AddRef() in Initialize(). 651 // Balances AddRef() in Initialize().
652 Release(); 652 Release();
653 } 653 }
654 654
655 void SpellChecker::DoDictionaryDownload() { 655 void SpellChecker::DoDictionaryDownload() {
656 // Download the dictionary file. 656 // Download the dictionary file.
657 if (file_loop_ && url_request_context_) { 657 if (file_loop_ && request_context_getter_) {
658 if (!tried_to_download_dictionary_file_) { 658 if (!tried_to_download_dictionary_file_) {
659 FilePath dictionary_file_name_app = GetVersionedFileName(language_, 659 FilePath dictionary_file_name_app = GetVersionedFileName(language_,
660 given_dictionary_directory_); 660 given_dictionary_directory_);
661 StartDictionaryDownload(dictionary_file_name_app); 661 StartDictionaryDownload(dictionary_file_name_app);
662 tried_to_download_dictionary_file_ = true; 662 tried_to_download_dictionary_file_ = true;
663 } else { 663 } else {
664 // Don't try to download a dictionary more than once. 664 // Don't try to download a dictionary more than once.
665 tried_to_init_ = true; 665 tried_to_init_ = true;
666 } 666 }
667 } else { 667 } else {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 890
891 // Populate the vector of WideStrings. 891 // Populate the vector of WideStrings.
892 for (int i = 0; i < number_of_suggestions; i++) { 892 for (int i = 0; i < number_of_suggestions; i++) {
893 if (i < kMaxSuggestions) 893 if (i < kMaxSuggestions)
894 optional_suggestions->push_back(UTF8ToUTF16(suggestions[i])); 894 optional_suggestions->push_back(UTF8ToUTF16(suggestions[i]));
895 free(suggestions[i]); 895 free(suggestions[i]);
896 } 896 }
897 if (suggestions != NULL) 897 if (suggestions != NULL)
898 free(suggestions); 898 free(suggestions);
899 } 899 }
OLDNEW
« no previous file with comments | « chrome/browser/spellchecker.h ('k') | chrome/browser/sync/glue/http_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698