Index: components/spellcheck/browser/spelling_service_client.cc |
diff --git a/chrome/browser/spellchecker/spelling_service_client.cc b/components/spellcheck/browser/spelling_service_client.cc |
similarity index 88% |
copy from chrome/browser/spellchecker/spelling_service_client.cc |
copy to components/spellcheck/browser/spelling_service_client.cc |
index be81257ea7a97823b2a64b041d2cb6ce70ace399..031361a04fd6d32f1ef2d8685bfae9338c575ba5 100644 |
--- a/chrome/browser/spellchecker/spelling_service_client.cc |
+++ b/components/spellcheck/browser/spelling_service_client.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/spellchecker/spelling_service_client.h" |
+#include "components/spellcheck/browser/spelling_service_client.h" |
#include <stddef.h> |
@@ -16,9 +16,9 @@ |
#include "base/strings/stringprintf.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/values.h" |
-#include "chrome/common/pref_names.h" |
#include "components/data_use_measurement/core/data_use_user_data.h" |
#include "components/prefs/pref_service.h" |
+#include "components/spellcheck/browser/pref_names.h" |
#include "components/spellcheck/common/spellcheck_common.h" |
#include "components/spellcheck/common/spellcheck_result.h" |
#include "components/user_prefs/user_prefs.h" |
@@ -46,8 +46,7 @@ const char* const kValidLanguages[] = {"en", "es", "fi", "da"}; |
} // namespace |
-SpellingServiceClient::SpellingServiceClient() { |
-} |
+SpellingServiceClient::SpellingServiceClient() {} |
SpellingServiceClient::~SpellingServiceClient() { |
base::STLDeleteContainerPairPointers(spellcheck_fetchers_.begin(), |
@@ -69,7 +68,8 @@ bool SpellingServiceClient::RequestTextCheck( |
DCHECK(pref); |
std::string dictionary; |
- pref->GetList(prefs::kSpellCheckDictionaries)->GetString(0, &dictionary); |
+ pref->GetList(spellcheck::prefs::kSpellCheckDictionaries) |
+ ->GetString(0, &dictionary); |
std::string language_code; |
std::string country_code; |
@@ -100,45 +100,41 @@ bool SpellingServiceClient::RequestTextCheck( |
"}"; |
std::string api_key = base::GetQuotedJSONString(google_apis::GetAPIKey()); |
std::string request = base::StringPrintf( |
- kSpellingRequest, |
- type, |
- encoded_text.c_str(), |
- language_code.c_str(), |
- country_code.c_str(), |
- api_key.c_str()); |
+ kSpellingRequest, type, encoded_text.c_str(), language_code.c_str(), |
+ country_code.c_str(), api_key.c_str()); |
GURL url = GURL(kSpellingServiceURL); |
net::URLFetcher* fetcher = CreateURLFetcher(url).release(); |
data_use_measurement::DataUseUserData::AttachToFetcher( |
fetcher, data_use_measurement::DataUseUserData::SPELL_CHECKER); |
fetcher->SetRequestContext( |
- content::BrowserContext::GetDefaultStoragePartition(context)-> |
- GetURLRequestContext()); |
+ content::BrowserContext::GetDefaultStoragePartition(context) |
+ ->GetURLRequestContext()); |
fetcher->SetUploadData("application/json", request); |
- fetcher->SetLoadFlags( |
- net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); |
+ fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
+ net::LOAD_DO_NOT_SAVE_COOKIES); |
spellcheck_fetchers_[fetcher] = new TextCheckCallbackData(callback, text); |
fetcher->Start(); |
return true; |
} |
-bool SpellingServiceClient::IsAvailable( |
- content::BrowserContext* context, |
- ServiceType type) { |
+bool SpellingServiceClient::IsAvailable(content::BrowserContext* context, |
+ ServiceType type) { |
const PrefService* pref = user_prefs::UserPrefs::Get(context); |
DCHECK(pref); |
// If prefs don't allow spellchecking, if the context is off the record, or if |
// multilingual spellchecking is enabled the spelling service should be |
// unavailable. |
- if (!pref->GetBoolean(prefs::kEnableContinuousSpellcheck) || |
- !pref->GetBoolean(prefs::kSpellCheckUseSpellingService) || |
+ if (!pref->GetBoolean(spellcheck::prefs::kEnableContinuousSpellcheck) || |
+ !pref->GetBoolean(spellcheck::prefs::kSpellCheckUseSpellingService) || |
context->IsOffTheRecord()) |
return false; |
// If the locale for spelling has not been set, the user has not decided to |
// use spellcheck so we don't do anything remote (suggest or spelling). |
std::string locale; |
- pref->GetList(prefs::kSpellCheckDictionaries)->GetString(0, &locale); |
+ pref->GetList(spellcheck::prefs::kSpellCheckDictionaries) |
+ ->GetString(0, &locale); |
if (locale.empty()) |
return false; |
@@ -239,8 +235,8 @@ bool SpellingServiceClient::ParseResponse( |
!suggestion->GetString("suggestion", &replacement)) { |
return false; |
} |
- SpellCheckResult result( |
- SpellCheckResult::SPELLING, start, length, replacement); |
+ SpellCheckResult result(SpellCheckResult::SPELLING, start, length, |
+ replacement); |
results->push_back(result); |
} |
return true; |
@@ -249,15 +245,11 @@ bool SpellingServiceClient::ParseResponse( |
SpellingServiceClient::TextCheckCallbackData::TextCheckCallbackData( |
TextCheckCompleteCallback callback, |
base::string16 text) |
- : callback(callback), |
- text(text) { |
-} |
+ : callback(callback), text(text) {} |
-SpellingServiceClient::TextCheckCallbackData::~TextCheckCallbackData() { |
-} |
+SpellingServiceClient::TextCheckCallbackData::~TextCheckCallbackData() {} |
-void SpellingServiceClient::OnURLFetchComplete( |
- const net::URLFetcher* source) { |
+void SpellingServiceClient::OnURLFetchComplete(const net::URLFetcher* source) { |
DCHECK(spellcheck_fetchers_[source]); |
std::unique_ptr<const net::URLFetcher> fetcher(source); |
std::unique_ptr<TextCheckCallbackData> callback_data( |