Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: chrome/browser/spellchecker/spellcheck_service.cc

Issue 2828313002: Convert render process component common Spellcheck IPC to mojo (Closed)
Patch Set: Build fix. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_service.h" 5 #include "chrome/browser/spellchecker/spellcheck_service.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/supports_user_data.h" 11 #include "base/supports_user_data.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/spellchecker/spellcheck_factory.h" 14 #include "chrome/browser/spellchecker/spellcheck_factory.h"
15 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" 15 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "components/prefs/pref_member.h" 17 #include "components/prefs/pref_member.h"
18 #include "components/prefs/pref_service.h" 18 #include "components/prefs/pref_service.h"
19 #include "components/spellcheck/browser/pref_names.h" 19 #include "components/spellcheck/browser/pref_names.h"
20 #include "components/spellcheck/browser/spellcheck_host_metrics.h" 20 #include "components/spellcheck/browser/spellcheck_host_metrics.h"
21 #include "components/spellcheck/browser/spellcheck_platform.h" 21 #include "components/spellcheck/browser/spellcheck_platform.h"
22 #include "components/spellcheck/browser/spelling_service_client.h" 22 #include "components/spellcheck/browser/spelling_service_client.h"
23 #include "components/spellcheck/common/spellcheck_bdict_language.h" 23 #include "components/spellcheck/common/spellcheck.mojom.h"
24 #include "components/spellcheck/common/spellcheck_common.h" 24 #include "components/spellcheck/common/spellcheck_common.h"
25 #include "components/spellcheck/common/spellcheck_messages.h"
26 #include "components/spellcheck/spellcheck_build_features.h" 25 #include "components/spellcheck/spellcheck_build_features.h"
27 #include "components/user_prefs/user_prefs.h" 26 #include "components/user_prefs/user_prefs.h"
28 #include "content/public/browser/browser_context.h" 27 #include "content/public/browser/browser_context.h"
29 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/notification_types.h" 30 #include "content/public/browser/notification_types.h"
32 #include "content/public/browser/render_process_host.h" 31 #include "content/public/browser/render_process_host.h"
33 #include "content/public/browser/storage_partition.h" 32 #include "content/public/browser/storage_partition.h"
34 #include "ipc/ipc_platform_file.h"
35 33
36 using content::BrowserThread; 34 using content::BrowserThread;
37 35
38 // TODO(rlp): I do not like globals, but keeping these for now during 36 // TODO(rlp): I do not like globals, but keeping these for now during
39 // transition. 37 // transition.
40 // An event used by browser tests to receive status events from this class and 38 // An event used by browser tests to receive status events from this class and
41 // its derived classes. 39 // its derived classes.
42 base::WaitableEvent* g_status_event = NULL; 40 base::WaitableEvent* g_status_event = NULL;
43 SpellcheckService::EventType g_status_type = 41 SpellcheckService::EventType g_status_type =
44 SpellcheckService::BDICT_NOTINITIALIZED; 42 SpellcheckService::BDICT_NOTINITIALIZED;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 OnUseSpellingServiceChanged(); 165 OnUseSpellingServiceChanged();
168 } 166 }
169 167
170 void SpellcheckService::InitForRenderer(content::RenderProcessHost* process) { 168 void SpellcheckService::InitForRenderer(content::RenderProcessHost* process) {
171 DCHECK_CURRENTLY_ON(BrowserThread::UI); 169 DCHECK_CURRENTLY_ON(BrowserThread::UI);
172 170
173 content::BrowserContext* context = process->GetBrowserContext(); 171 content::BrowserContext* context = process->GetBrowserContext();
174 if (SpellcheckServiceFactory::GetForContext(context) != this) 172 if (SpellcheckServiceFactory::GetForContext(context) != this)
175 return; 173 return;
176 174
177 PrefService* prefs = user_prefs::UserPrefs::Get(context); 175 const PrefService* prefs = user_prefs::UserPrefs::Get(context);
178 std::vector<SpellCheckBDictLanguage> bdict_languages; 176 std::vector<spellcheck::mojom::SpellCheckBDictLanguagePtr> dictionaries;
179 177
180 for (const auto& hunspell_dictionary : hunspell_dictionaries_) { 178 for (const auto& hunspell_dictionary : hunspell_dictionaries_) {
181 bdict_languages.push_back(SpellCheckBDictLanguage()); 179 dictionaries.push_back(spellcheck::mojom::SpellCheckBDictLanguage::New(
182 bdict_languages.back().language = hunspell_dictionary->GetLanguage(); 180 hunspell_dictionary->GetDictionaryFile().Duplicate(),
183 bdict_languages.back().file = 181 hunspell_dictionary->GetLanguage()));
184 hunspell_dictionary->GetDictionaryFile().IsValid()
185 ? IPC::GetPlatformFileForTransit(
186 hunspell_dictionary->GetDictionaryFile().GetPlatformFile(),
187 false)
188 : IPC::InvalidPlatformFileForTransit();
189 } 182 }
190 183
191 bool enabled = 184 bool enable = prefs->GetBoolean(spellcheck::prefs::kEnableSpellcheck) &&
192 prefs->GetBoolean(spellcheck::prefs::kEnableSpellcheck) && 185 !dictionaries.empty();
193 !bdict_languages.empty(); 186
194 process->Send(new SpellCheckMsg_Init( 187 std::vector<std::string> custom_words;
195 bdict_languages, 188 if (enable) {
196 enabled ? custom_dictionary_->GetWords() : std::set<std::string>())); 189 custom_words.assign(custom_dictionary_->GetWords().begin(),
197 process->Send(new SpellCheckMsg_EnableSpellCheck(enabled)); 190 custom_dictionary_->GetWords().end());
191 }
192
193 spellcheck::mojom::SpellCheckerPtr spellchecker;
194 content::BindInterface(process, &spellchecker);
195 spellchecker->Initialize(std::move(dictionaries), custom_words, enable);
198 } 196 }
199 197
200 SpellCheckHostMetrics* SpellcheckService::GetMetrics() const { 198 SpellCheckHostMetrics* SpellcheckService::GetMetrics() const {
201 return metrics_.get(); 199 return metrics_.get();
202 } 200 }
203 201
204 SpellcheckCustomDictionary* SpellcheckService::GetCustomDictionary() { 202 SpellcheckCustomDictionary* SpellcheckService::GetCustomDictionary() {
205 return custom_dictionary_.get(); 203 return custom_dictionary_.get();
206 } 204 }
207 205
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 const content::NotificationDetails& details) { 248 const content::NotificationDetails& details) {
251 DCHECK_EQ(content::NOTIFICATION_RENDERER_PROCESS_CREATED, type); 249 DCHECK_EQ(content::NOTIFICATION_RENDERER_PROCESS_CREATED, type);
252 InitForRenderer(content::Source<content::RenderProcessHost>(source).ptr()); 250 InitForRenderer(content::Source<content::RenderProcessHost>(source).ptr());
253 } 251 }
254 252
255 void SpellcheckService::OnCustomDictionaryLoaded() { 253 void SpellcheckService::OnCustomDictionaryLoaded() {
256 InitForAllRenderers(); 254 InitForAllRenderers();
257 } 255 }
258 256
259 void SpellcheckService::OnCustomDictionaryChanged( 257 void SpellcheckService::OnCustomDictionaryChanged(
260 const SpellcheckCustomDictionary::Change& dictionary_change) { 258 const SpellcheckCustomDictionary::Change& change) {
261 for (content::RenderProcessHost::iterator i( 259 DCHECK_CURRENTLY_ON(BrowserThread::UI);
262 content::RenderProcessHost::AllHostsIterator()); 260
263 !i.IsAtEnd(); i.Advance()) { 261 auto process_hosts(content::RenderProcessHost::AllHostsIterator());
264 i.GetCurrentValue()->Send(new SpellCheckMsg_CustomDictionaryChanged( 262
265 dictionary_change.to_add(), 263 const std::vector<std::string> additions(change.to_add().begin(),
266 dictionary_change.to_remove())); 264 change.to_add().end());
265 const std::vector<std::string> deletions(change.to_remove().begin(),
266 change.to_remove().end());
267 while (!process_hosts.IsAtEnd()) {
268 spellcheck::mojom::SpellCheckerPtr spellchecker;
269 content::BindInterface(process_hosts.GetCurrentValue(), &spellchecker);
270 spellchecker->CustomDictionaryChanged(additions, deletions);
271 process_hosts.Advance();
267 } 272 }
268 } 273 }
269 274
270 void SpellcheckService::OnHunspellDictionaryInitialized( 275 void SpellcheckService::OnHunspellDictionaryInitialized(
271 const std::string& language) { 276 const std::string& language) {
272 InitForAllRenderers(); 277 InitForAllRenderers();
273 } 278 }
274 279
275 void SpellcheckService::OnHunspellDictionaryDownloadBegin( 280 void SpellcheckService::OnHunspellDictionaryDownloadBegin(
276 const std::string& language) { 281 const std::string& language) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 347
343 for (const auto& dictionary : dictionaries) { 348 for (const auto& dictionary : dictionaries) {
344 if (std::find(accept_languages.begin(), accept_languages.end(), 349 if (std::find(accept_languages.begin(), accept_languages.end(),
345 dictionary) != accept_languages.end()) { 350 dictionary) != accept_languages.end()) {
346 filtered_dictionaries.push_back(dictionary); 351 filtered_dictionaries.push_back(dictionary);
347 } 352 }
348 } 353 }
349 354
350 dictionaries_pref.SetValue(filtered_dictionaries); 355 dictionaries_pref.SetValue(filtered_dictionaries);
351 } 356 }
OLDNEW
« no previous file with comments | « chrome/browser/spellchecker/spellcheck_service.h ('k') | chrome/browser/spellchecker/spellcheck_service_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698