| 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 "content/renderer/hyphenator/hyphenator.h" | 5 #include "content/renderer/hyphenator/hyphenator.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/files/memory_mapped_file.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "content/common/hyphenator_messages.h" | 12 #include "content/common/hyphenator_messages.h" |
| 13 #include "content/public/renderer/render_thread.h" | 13 #include "content/public/renderer/render_thread.h" |
| 14 #include "third_party/hyphen/hyphen.h" | 14 #include "third_party/hyphen/hyphen.h" |
| 15 #include "third_party/icu/public/common/unicode/uscript.h" | 15 #include "third_party/icu/public/common/unicode/uscript.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 | 197 |
| 198 bool Hyphenator::Initialize() { | 198 bool Hyphenator::Initialize() { |
| 199 if (dictionary_) | 199 if (dictionary_) |
| 200 return true; | 200 return true; |
| 201 | 201 |
| 202 // Attach the dictionary file to the MemoryMappedFile object. When it | 202 // Attach the dictionary file to the MemoryMappedFile object. When it |
| 203 // succeeds, this class does not have to close this file because it is closed | 203 // succeeds, this class does not have to close this file because it is closed |
| 204 // by the MemoryMappedFile class. To prevent this class from closing this | 204 // by the MemoryMappedFile class. To prevent this class from closing this |
| 205 // file, we reset its handle. | 205 // file, we reset its handle. |
| 206 rule_map_.reset(new file_util::MemoryMappedFile); | 206 rule_map_.reset(new base::MemoryMappedFile); |
| 207 if (!rule_map_->Initialize(rule_file_)) | 207 if (!rule_map_->Initialize(rule_file_)) |
| 208 return false; | 208 return false; |
| 209 rule_file_ = base::kInvalidPlatformFileValue; | 209 rule_file_ = base::kInvalidPlatformFileValue; |
| 210 | 210 |
| 211 dictionary_ = hnj_hyphen_load(rule_map_->data(), rule_map_->length()); | 211 dictionary_ = hnj_hyphen_load(rule_map_->data(), rule_map_->length()); |
| 212 return !!dictionary_; | 212 return !!dictionary_; |
| 213 } | 213 } |
| 214 | 214 |
| 215 bool Hyphenator::Attach(RenderThread* thread, const string16& locale) { | 215 bool Hyphenator::Attach(RenderThread* thread, const string16& locale) { |
| 216 if (!thread) | 216 if (!thread) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 // does not have to break text into lines.) | 271 // does not have to break text into lines.) |
| 272 if (dictionary_) { | 272 if (dictionary_) { |
| 273 hnj_hyphen_free(dictionary_); | 273 hnj_hyphen_free(dictionary_); |
| 274 dictionary_ = NULL; | 274 dictionary_ = NULL; |
| 275 } | 275 } |
| 276 rule_map_.reset(); | 276 rule_map_.reset(); |
| 277 rule_file_ = rule_file; | 277 rule_file_ = rule_file; |
| 278 } | 278 } |
| 279 | 279 |
| 280 } // namespace content | 280 } // namespace content |
| OLD | NEW |