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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 scoped_ptr<DictionaryFile> OpenDictionaryFile( | 73 scoped_ptr<DictionaryFile> OpenDictionaryFile( |
74 scoped_ptr<DictionaryFile> file) { | 74 scoped_ptr<DictionaryFile> file) { |
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
76 | 76 |
77 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
78 // Check if the dictionary exists in the fallback location. If so, use it | 78 // Check if the dictionary exists in the fallback location. If so, use it |
79 // rather than downloading anew. | 79 // rather than downloading anew. |
80 base::FilePath user_dir; | 80 base::FilePath user_dir; |
81 PathService::Get(chrome::DIR_USER_DATA, &user_dir); | 81 PathService::Get(chrome::DIR_USER_DATA, &user_dir); |
82 base::FilePath fallback = user_dir.Append(file->path.BaseName()); | 82 base::FilePath fallback = user_dir.Append(file->path.BaseName()); |
83 if (!file_util::PathExists(file->path) && file_util::PathExists(fallback)) | 83 if (!base::PathExists(file->path) && base::PathExists(fallback)) |
84 file->path = fallback; | 84 file->path = fallback; |
85 #endif | 85 #endif |
86 | 86 |
87 // Read the dictionary file and scan its data to check for corruption. The | 87 // Read the dictionary file and scan its data to check for corruption. The |
88 // scoping closes the memory-mapped file before it is opened or deleted. | 88 // scoping closes the memory-mapped file before it is opened or deleted. |
89 bool bdict_is_valid; | 89 bool bdict_is_valid; |
90 { | 90 { |
91 base::MemoryMappedFile map; | 91 base::MemoryMappedFile map; |
92 bdict_is_valid = file_util::PathExists(file->path) && | 92 bdict_is_valid = base::PathExists(file->path) && |
93 map.Initialize(file->path) && | 93 map.Initialize(file->path) && |
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); |
(...skipping 252 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 |