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/spelling_service_client.h" | 5 #include "chrome/browser/spellchecker/spelling_service_client.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 104 } |
105 | 105 |
106 bool SpellingServiceClient::IsAvailable(Profile* profile, ServiceType type) { | 106 bool SpellingServiceClient::IsAvailable(Profile* profile, ServiceType type) { |
107 const PrefService* pref = profile->GetPrefs(); | 107 const PrefService* pref = profile->GetPrefs(); |
108 if (!pref->GetBoolean(prefs::kEnableSpellCheck) || | 108 if (!pref->GetBoolean(prefs::kEnableSpellCheck) || |
109 !pref->GetBoolean(prefs::kSpellCheckUseSpellingService)) | 109 !pref->GetBoolean(prefs::kSpellCheckUseSpellingService)) |
110 return false; | 110 return false; |
111 | 111 |
112 // The spellchecking service should be avilable only when asynchronous | 112 // The spellchecking service should be avilable only when asynchronous |
113 // spellchecking is enabled because this service depends on it. | 113 // spellchecking is enabled because this service depends on it. |
114 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
115 if (command_line->HasSwitch(switches::kDisableAsynchronousSpellChecking)) | |
116 return type == SUGGEST; | |
117 | 114 |
118 // Enable the suggest service only on languages not supported by the | 115 // Enable the suggest service only on languages not supported by the |
119 // spellcheck service. When this client calls the spellcheck service, it | 116 // spellcheck service. When this client calls the spellcheck service, it |
120 // returns not only spellcheck results but also spelling suggestions provided | 117 // returns not only spellcheck results but also spelling suggestions provided |
121 // by the suggest service. That is, it is not useful to use the suggest | 118 // by the suggest service. That is, it is not useful to use the suggest |
122 // service when this client can use the spellcheck service. | 119 // service when this client can use the spellcheck service. |
123 std::string locale = pref->GetString(prefs::kSpellCheckDictionary); | 120 std::string locale = pref->GetString(prefs::kSpellCheckDictionary); |
| 121 |
| 122 // This means we are in a test. |
| 123 if (locale.empty()) return false; |
| 124 |
| 125 // Otherwise only suggest is currently valid. |
| 126 return type == SUGGEST; |
| 127 |
124 #if defined(OS_MACOSX) | 128 #if defined(OS_MACOSX) |
125 bool spellcheck_available = locale.empty(); | 129 bool spellcheck_available = locale.empty(); |
126 #else | 130 #else |
127 bool spellcheck_available = locale.empty() || !locale.compare(0, 2, "en"); | 131 bool spellcheck_available = locale.empty() || !locale.compare(0, 2, "en"); |
128 #endif | 132 #endif |
129 return type == SUGGEST ? !spellcheck_available : spellcheck_available; | 133 return type == SUGGEST ? !spellcheck_available : spellcheck_available; |
130 } | 134 } |
131 | 135 |
132 void SpellingServiceClient::OnURLFetchComplete( | 136 void SpellingServiceClient::OnURLFetchComplete( |
133 const net::URLFetcher* source) { | 137 const net::URLFetcher* source) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 if (!suggestions->GetDictionary(0, &suggestion) || | 220 if (!suggestions->GetDictionary(0, &suggestion) || |
217 !suggestion->GetString("suggestion", &replacement)) { | 221 !suggestion->GetString("suggestion", &replacement)) { |
218 return false; | 222 return false; |
219 } | 223 } |
220 SpellCheckResult result( | 224 SpellCheckResult result( |
221 SpellCheckResult::SPELLING, start, length, replacement); | 225 SpellCheckResult::SPELLING, start, length, replacement); |
222 results->push_back(result); | 226 results->push_back(result); |
223 } | 227 } |
224 return true; | 228 return true; |
225 } | 229 } |
OLD | NEW |