| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_message_filter.h" | 5 #include "chrome/browser/spellchecker/spellcheck_message_filter.h" |
| 6 | 6 |
| 7 #include "chrome/browser/prefs/pref_service.h" | 7 #include "chrome/browser/prefs/pref_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 9 #include "chrome/browser/spellchecker/spellcheck_host.h" | 10 #include "chrome/browser/spellchecker/spellcheck_host.h" |
| 10 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" | 11 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
| 11 #include "chrome/common/spellcheck_messages.h" | 12 #include "chrome/common/spellcheck_messages.h" |
| 12 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 13 | 14 |
| 14 using content::BrowserThread; | 15 using content::BrowserThread; |
| 15 | 16 |
| 16 SpellCheckMessageFilter::SpellCheckMessageFilter(int render_process_id) | 17 SpellCheckMessageFilter::SpellCheckMessageFilter(int render_process_id) |
| 17 : render_process_id_(render_process_id) { | 18 : render_process_id_(render_process_id) { |
| 18 } | 19 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 43 void SpellCheckMessageFilter::OnSpellCheckerRequestDictionary() { | 44 void SpellCheckMessageFilter::OnSpellCheckerRequestDictionary() { |
| 44 content::RenderProcessHost* host = | 45 content::RenderProcessHost* host = |
| 45 content::RenderProcessHost::FromID(render_process_id_); | 46 content::RenderProcessHost::FromID(render_process_id_); |
| 46 if (!host) | 47 if (!host) |
| 47 return; // Teardown. | 48 return; // Teardown. |
| 48 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | 49 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
| 49 // The renderer has requested that we initialize its spellchecker. This should | 50 // The renderer has requested that we initialize its spellchecker. This should |
| 50 // generally only be called once per session, as after the first call, all | 51 // generally only be called once per session, as after the first call, all |
| 51 // future renderers will be passed the initialization information on startup | 52 // future renderers will be passed the initialization information on startup |
| 52 // (or when the dictionary changes in some way). | 53 // (or when the dictionary changes in some way). |
| 53 if (profile->GetSpellCheckHost()) { | 54 SpellCheckHost* spell_check_host = |
| 55 SpellCheckFactory::GetHostForProfile(profile); |
| 56 |
| 57 if (spell_check_host) { |
| 54 // The spellchecker initialization already started and finished; just send | 58 // The spellchecker initialization already started and finished; just send |
| 55 // it to the renderer. | 59 // it to the renderer. |
| 56 profile->GetSpellCheckHost()->InitForRenderer(host); | 60 spell_check_host->InitForRenderer(host); |
| 57 } else { | 61 } else { |
| 58 // We may have gotten multiple requests from different renderers. We don't | 62 // We may have gotten multiple requests from different renderers. We don't |
| 59 // want to initialize multiple times in this case, so we set |force| to | 63 // want to initialize multiple times in this case, so we set |force| to |
| 60 // false. | 64 // false. |
| 61 profile->ReinitializeSpellCheckHost(false); | 65 SpellCheckFactory::ReinitializeSpellCheckHost(profile, false); |
| 62 } | 66 } |
| 63 } | 67 } |
| 64 | 68 |
| 65 void SpellCheckMessageFilter::OnNotifyChecked(const string16& word, | 69 void SpellCheckMessageFilter::OnNotifyChecked(const string16& word, |
| 66 bool misspelled) { | 70 bool misspelled) { |
| 67 content::RenderProcessHost* host = | 71 content::RenderProcessHost* host = |
| 68 content::RenderProcessHost::FromID(render_process_id_); | 72 content::RenderProcessHost::FromID(render_process_id_); |
| 69 if (!host) | 73 if (!host) |
| 70 return; // Teardown. | 74 return; // Teardown. |
| 71 // Delegates to SpellCheckHost which tracks the stats of our spellchecker. | 75 // Delegates to SpellCheckHost which tracks the stats of our spellchecker. |
| 72 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | 76 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
| 73 SpellCheckHost* spellcheck_host = profile->GetSpellCheckHost(); | 77 SpellCheckHost* spellcheck_host = |
| 78 SpellCheckFactory::GetHostForProfile(profile); |
| 74 if (spellcheck_host && spellcheck_host->GetMetrics()) | 79 if (spellcheck_host && spellcheck_host->GetMetrics()) |
| 75 spellcheck_host->GetMetrics()->RecordCheckedWordStats(word, misspelled); | 80 spellcheck_host->GetMetrics()->RecordCheckedWordStats(word, misspelled); |
| 76 } | 81 } |
| OLD | NEW |