| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spellcheck_hunspell_dictionary.h" | 5 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/memory_mapped_file.h" | 8 #include "base/files/memory_mapped_file.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 hunspell::BDict::Verify(reinterpret_cast<const char*>(map.data()), | 94 hunspell::BDict::Verify(reinterpret_cast<const char*>(map.data()), |
| 95 map.length()); | 95 map.length()); |
| 96 } | 96 } |
| 97 if (bdict_is_valid) { | 97 if (bdict_is_valid) { |
| 98 file->descriptor = base::CreatePlatformFile( | 98 file->descriptor = base::CreatePlatformFile( |
| 99 file->path, | 99 file->path, |
| 100 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_OPEN, | 100 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_OPEN, |
| 101 NULL, | 101 NULL, |
| 102 NULL); | 102 NULL); |
| 103 } else { | 103 } else { |
| 104 file_util::Delete(file->path, false); | 104 base::Delete(file->path, false); |
| 105 } | 105 } |
| 106 | 106 |
| 107 return file.Pass(); | 107 return file.Pass(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Gets the default location for the dictionary file. The default place where | 110 // Gets the default location for the dictionary file. The default place where |
| 111 // the spellcheck dictionary resides is chrome::DIR_APP_DICTIONARIES. | 111 // the spellcheck dictionary resides is chrome::DIR_APP_DICTIONARIES. |
| 112 // Returns a scoped pointer to avoid leaking the file descriptor if the caller | 112 // Returns a scoped pointer to avoid leaking the file descriptor if the caller |
| 113 // has been destroyed. | 113 // has been destroyed. |
| 114 scoped_ptr<DictionaryFile> InitializeDictionaryLocation( | 114 scoped_ptr<DictionaryFile> InitializeDictionaryLocation( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 141 PathService::Get(chrome::DIR_USER_DATA, &dict_dir); | 141 PathService::Get(chrome::DIR_USER_DATA, &dict_dir); |
| 142 base::FilePath fallback_file_path = | 142 base::FilePath fallback_file_path = |
| 143 dict_dir.Append(path.BaseName()); | 143 dict_dir.Append(path.BaseName()); |
| 144 bytes_written = | 144 bytes_written = |
| 145 file_util::WriteFile(fallback_file_path, data->data(), data->length()); | 145 file_util::WriteFile(fallback_file_path, data->data(), data->length()); |
| 146 if (bytes_written == data->length()) | 146 if (bytes_written == data->length()) |
| 147 success = true; | 147 success = true; |
| 148 #endif | 148 #endif |
| 149 | 149 |
| 150 if (!success) { | 150 if (!success) { |
| 151 file_util::Delete(path, false); | 151 base::Delete(path, false); |
| 152 return false; | 152 return false; |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 return true; | 156 return true; |
| 157 } | 157 } |
| 158 | 158 |
| 159 } // namespace | 159 } // namespace |
| 160 | 160 |
| 161 SpellcheckHunspellDictionary::SpellcheckHunspellDictionary( | 161 SpellcheckHunspellDictionary::SpellcheckHunspellDictionary( |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 void SpellcheckHunspellDictionary::InformListenersOfInitialization() { | 355 void SpellcheckHunspellDictionary::InformListenersOfInitialization() { |
| 356 FOR_EACH_OBSERVER(Observer, observers_, OnHunspellDictionaryInitialized()); | 356 FOR_EACH_OBSERVER(Observer, observers_, OnHunspellDictionaryInitialized()); |
| 357 } | 357 } |
| 358 | 358 |
| 359 void SpellcheckHunspellDictionary::InformListenersOfDownloadFailure() { | 359 void SpellcheckHunspellDictionary::InformListenersOfDownloadFailure() { |
| 360 download_status_ = DOWNLOAD_FAILED; | 360 download_status_ = DOWNLOAD_FAILED; |
| 361 FOR_EACH_OBSERVER(Observer, | 361 FOR_EACH_OBSERVER(Observer, |
| 362 observers_, | 362 observers_, |
| 363 OnHunspellDictionaryDownloadFailure()); | 363 OnHunspellDictionaryDownloadFailure()); |
| 364 } | 364 } |
| OLD | NEW |