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/renderer/spellchecker/hunspell_engine.h" | 5 #include "chrome/renderer/spellchecker/hunspell_engine.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | |
9 #include <algorithm> | 8 #include <algorithm> |
10 #include <iterator> | 9 #include <iterator> |
| 10 #include <utility> |
11 | 11 |
12 #include "base/files/memory_mapped_file.h" | 12 #include "base/files/memory_mapped_file.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "chrome/common/spellcheck_common.h" | 14 #include "chrome/common/spellcheck_common.h" |
15 #include "chrome/common/spellcheck_messages.h" | 15 #include "chrome/common/spellcheck_messages.h" |
16 #include "content/public/renderer/render_thread.h" | 16 #include "content/public/renderer/render_thread.h" |
17 #include "third_party/hunspell/src/hunspell/hunspell.hxx" | 17 #include "third_party/hunspell/src/hunspell/hunspell.hxx" |
18 | 18 |
19 using content::RenderThread; | 19 using content::RenderThread; |
20 | 20 |
(...skipping 25 matching lines...) Expand all Loading... |
46 // Wait till we check the first word before doing any initializing. | 46 // Wait till we check the first word before doing any initializing. |
47 } | 47 } |
48 | 48 |
49 HunspellEngine::~HunspellEngine() { | 49 HunspellEngine::~HunspellEngine() { |
50 } | 50 } |
51 | 51 |
52 void HunspellEngine::Init(base::File file) { | 52 void HunspellEngine::Init(base::File file) { |
53 initialized_ = true; | 53 initialized_ = true; |
54 hunspell_.reset(); | 54 hunspell_.reset(); |
55 bdict_file_.reset(); | 55 bdict_file_.reset(); |
56 file_ = file.Pass(); | 56 file_ = std::move(file); |
57 hunspell_enabled_ = file_.IsValid(); | 57 hunspell_enabled_ = file_.IsValid(); |
58 // Delay the actual initialization of hunspell until it is needed. | 58 // Delay the actual initialization of hunspell until it is needed. |
59 } | 59 } |
60 | 60 |
61 void HunspellEngine::InitializeHunspell() { | 61 void HunspellEngine::InitializeHunspell() { |
62 if (hunspell_.get()) | 62 if (hunspell_.get()) |
63 return; | 63 return; |
64 | 64 |
65 bdict_file_.reset(new base::MemoryMappedFile); | 65 bdict_file_.reset(new base::MemoryMappedFile); |
66 | 66 |
67 if (bdict_file_->Initialize(file_.Pass())) { | 67 if (bdict_file_->Initialize(std::move(file_))) { |
68 hunspell_.reset(new Hunspell(bdict_file_->data(), bdict_file_->length())); | 68 hunspell_.reset(new Hunspell(bdict_file_->data(), bdict_file_->length())); |
69 } else { | 69 } else { |
70 NOTREACHED() << "Could not mmap spellchecker dictionary."; | 70 NOTREACHED() << "Could not mmap spellchecker dictionary."; |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 bool HunspellEngine::CheckSpelling(const base::string16& word_to_check, | 74 bool HunspellEngine::CheckSpelling(const base::string16& word_to_check, |
75 int tag) { | 75 int tag) { |
76 // Assume all words that cannot be checked are valid. Since Chrome can't | 76 // Assume all words that cannot be checked are valid. Since Chrome can't |
77 // offer suggestions on them, either, there's no point in flagging them to | 77 // offer suggestions on them, either, there's no point in flagging them to |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // Don't initialize if hunspell is disabled. | 131 // Don't initialize if hunspell is disabled. |
132 if (file_.IsValid()) | 132 if (file_.IsValid()) |
133 InitializeHunspell(); | 133 InitializeHunspell(); |
134 | 134 |
135 return !initialized_; | 135 return !initialized_; |
136 } | 136 } |
137 | 137 |
138 bool HunspellEngine::IsEnabled() { | 138 bool HunspellEngine::IsEnabled() { |
139 return hunspell_enabled_; | 139 return hunspell_enabled_; |
140 } | 140 } |
OLD | NEW |