OLD | NEW |
---|---|
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 <io.h> | 5 #include <io.h> |
6 | 6 |
7 #include "chrome/browser/spellchecker.h" | 7 #include "chrome/browser/spellchecker.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 } | 503 } |
504 | 504 |
505 private: | 505 private: |
506 void Run() { | 506 void Run() { |
507 // Add the word with a new line. Note that, although this would mean an | 507 // Add the word with a new line. Note that, although this would mean an |
508 // extra line after the list of words, this is potentially harmless and | 508 // extra line after the list of words, this is potentially harmless and |
509 // faster, compared to verifying everytime whether to append a new line | 509 // faster, compared to verifying everytime whether to append a new line |
510 // or not. | 510 // or not. |
511 word_ += "\n"; | 511 word_ += "\n"; |
512 FILE* f = file_util::OpenFile(file_name_, "a+"); | 512 FILE* f = file_util::OpenFile(file_name_, "a+"); |
513 fputs(word_.c_str(), f); | 513 if (f != NULL) |
Patrick Johnson
2008/10/17 18:13:15
This looks like a good fix, but won't the silent f
| |
514 fputs(word_.c_str(), f); | |
514 file_util::CloseFile(f); | 515 file_util::CloseFile(f); |
515 } | 516 } |
516 | 517 |
517 std::string file_name_; | 518 std::string file_name_; |
518 std::string word_; | 519 std::string word_; |
519 }; | 520 }; |
520 | 521 |
521 void SpellChecker::AddWord(const std::wstring& word) { | 522 void SpellChecker::AddWord(const std::wstring& word) { |
522 // Check if the |hunspell_| has been initialized at all. | 523 // Check if the |hunspell_| has been initialized at all. |
523 Initialize(); | 524 Initialize(); |
524 | 525 |
525 // Add the word to hunspell. | 526 // Add the word to hunspell. |
526 std::string word_to_add = WideToUTF8(word); | 527 std::string word_to_add = WideToUTF8(word); |
527 if (!word_to_add.empty()) | 528 if (!word_to_add.empty()) |
528 hunspell_->put_word(word_to_add.c_str()); | 529 hunspell_->put_word(word_to_add.c_str()); |
529 | 530 |
530 // Now add the word to the custom dictionary file in the file loop. | 531 // Now add the word to the custom dictionary file in the file loop. |
531 if (file_loop_) { | 532 if (file_loop_) { |
532 file_loop_->PostTask(FROM_HERE, new AddWordToCustomDictionaryTask( | 533 file_loop_->PostTask(FROM_HERE, new AddWordToCustomDictionaryTask( |
533 custom_dictionary_file_name_, word)); | 534 custom_dictionary_file_name_, word)); |
534 } else { // just run it in this thread. | 535 } else { // just run it in this thread. |
535 Task* write_word_task = new AddWordToCustomDictionaryTask( | 536 Task* write_word_task = new AddWordToCustomDictionaryTask( |
536 custom_dictionary_file_name_, word); | 537 custom_dictionary_file_name_, word); |
537 write_word_task->Run(); | 538 write_word_task->Run(); |
538 } | 539 } |
539 } | 540 } |
OLD | NEW |