| 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; |
| 124 #if defined(OS_MACOSX) | 127 #if defined(OS_MACOSX) |
| 125 bool spellcheck_available = locale.empty(); | 128 bool spellcheck_available = locale.empty(); |
| 126 #else | 129 #else |
| 127 bool spellcheck_available = locale.empty() || !locale.compare(0, 2, "en"); | 130 bool spellcheck_available = locale.empty() || !locale.compare(0, 2, "en"); |
| 128 #endif | 131 #endif |
| 129 return type == SUGGEST ? !spellcheck_available : spellcheck_available; | 132 return type == SUGGEST ? !spellcheck_available : spellcheck_available; |
| 130 } | 133 } |
| 131 | 134 |
| 132 void SpellingServiceClient::OnURLFetchComplete( | 135 void SpellingServiceClient::OnURLFetchComplete( |
| 133 const net::URLFetcher* source) { | 136 const net::URLFetcher* source) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 if (!suggestions->GetDictionary(0, &suggestion) || | 219 if (!suggestions->GetDictionary(0, &suggestion) || |
| 217 !suggestion->GetString("suggestion", &replacement)) { | 220 !suggestion->GetString("suggestion", &replacement)) { |
| 218 return false; | 221 return false; |
| 219 } | 222 } |
| 220 SpellCheckResult result( | 223 SpellCheckResult result( |
| 221 SpellCheckResult::SPELLING, start, length, replacement); | 224 SpellCheckResult::SPELLING, start, length, replacement); |
| 222 results->push_back(result); | 225 results->push_back(result); |
| 223 } | 226 } |
| 224 return true; | 227 return true; |
| 225 } | 228 } |
| OLD | NEW |