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

Side by Side Diff: components/spellcheck/browser/spelling_service_client.cc

Issue 2159283003: [WIP][DO NOT LAND] Componentize spellcheck Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/spelling_service_client.h" 5 #include "components/spellcheck/browser/spelling_service_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/string_escape.h" 12 #include "base/json/string_escape.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/common/pref_names.h" 19 #include "components/spellcheck/browser/pref_names.h"
20 #include "chrome/common/spellcheck_common.h" 20 #include "components/spellcheck/common/spellcheck_common.h"
21 #include "chrome/common/spellcheck_result.h" 21 #include "components/spellcheck/common/spellcheck_result.h"
22 #include "components/data_use_measurement/core/data_use_user_data.h" 22 #include "components/data_use_measurement/core/data_use_user_data.h"
23 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
24 #include "components/user_prefs/user_prefs.h" 24 #include "components/user_prefs/user_prefs.h"
25 #include "content/public/browser/browser_context.h" 25 #include "content/public/browser/browser_context.h"
26 #include "content/public/browser/storage_partition.h" 26 #include "content/public/browser/storage_partition.h"
27 #include "google_apis/google_api_keys.h" 27 #include "google_apis/google_api_keys.h"
28 #include "net/base/load_flags.h" 28 #include "net/base/load_flags.h"
29 #include "net/url_request/url_fetcher.h" 29 #include "net/url_request/url_fetcher.h"
30 #include "url/gurl.h" 30 #include "url/gurl.h"
31 31
(...skipping 30 matching lines...) Expand all
62 DCHECK(type == SUGGEST || type == SPELLCHECK); 62 DCHECK(type == SUGGEST || type == SPELLCHECK);
63 if (!context || !IsAvailable(context, type)) { 63 if (!context || !IsAvailable(context, type)) {
64 callback.Run(false, text, std::vector<SpellCheckResult>()); 64 callback.Run(false, text, std::vector<SpellCheckResult>());
65 return false; 65 return false;
66 } 66 }
67 67
68 const PrefService* pref = user_prefs::UserPrefs::Get(context); 68 const PrefService* pref = user_prefs::UserPrefs::Get(context);
69 DCHECK(pref); 69 DCHECK(pref);
70 70
71 std::string dictionary; 71 std::string dictionary;
72 pref->GetList(prefs::kSpellCheckDictionaries)->GetString(0, &dictionary); 72 pref->GetList(spellcheck::prefs::kSpellCheckDictionaries)->GetString(0, &dicti onary);
73 73
74 std::string language_code; 74 std::string language_code;
75 std::string country_code; 75 std::string country_code;
76 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( 76 spellcheck_common::GetISOLanguageCountryCodeFromLocale(
77 dictionary, &language_code, &country_code); 77 dictionary, &language_code, &country_code);
78 78
79 // Replace typographical apostrophes with typewriter apostrophes, so that 79 // Replace typographical apostrophes with typewriter apostrophes, so that
80 // server word breaker behaves correctly. 80 // server word breaker behaves correctly.
81 const base::char16 kApostrophe = 0x27; 81 const base::char16 kApostrophe = 0x27;
82 const base::char16 kRightSingleQuotationMark = 0x2019; 82 const base::char16 kRightSingleQuotationMark = 0x2019;
83 base::string16 text_copy = text; 83 base::string16 text_copy = text;
84 std::replace(text_copy.begin(), text_copy.end(), kRightSingleQuotationMark, 84 std::replace(text_copy.begin(), text_copy.end(), kRightSingleQuotationMark,
85 kApostrophe); 85 kApostrophe);
86 86
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 123 }
124 124
125 bool SpellingServiceClient::IsAvailable( 125 bool SpellingServiceClient::IsAvailable(
126 content::BrowserContext* context, 126 content::BrowserContext* context,
127 ServiceType type) { 127 ServiceType type) {
128 const PrefService* pref = user_prefs::UserPrefs::Get(context); 128 const PrefService* pref = user_prefs::UserPrefs::Get(context);
129 DCHECK(pref); 129 DCHECK(pref);
130 // If prefs don't allow spellchecking, if the context is off the record, or if 130 // If prefs don't allow spellchecking, if the context is off the record, or if
131 // multilingual spellchecking is enabled the spelling service should be 131 // multilingual spellchecking is enabled the spelling service should be
132 // unavailable. 132 // unavailable.
133 if (!pref->GetBoolean(prefs::kEnableContinuousSpellcheck) || 133 if (!pref->GetBoolean(spellcheck::prefs::kEnableContinuousSpellcheck) ||
134 !pref->GetBoolean(prefs::kSpellCheckUseSpellingService) || 134 !pref->GetBoolean(spellcheck::prefs::kSpellCheckUseSpellingService) ||
135 context->IsOffTheRecord()) 135 context->IsOffTheRecord())
136 return false; 136 return false;
137 137
138 // If the locale for spelling has not been set, the user has not decided to 138 // If the locale for spelling has not been set, the user has not decided to
139 // use spellcheck so we don't do anything remote (suggest or spelling). 139 // use spellcheck so we don't do anything remote (suggest or spelling).
140 std::string locale; 140 std::string locale;
141 pref->GetList(prefs::kSpellCheckDictionaries)->GetString(0, &locale); 141 pref->GetList(spellcheck::prefs::kSpellCheckDictionaries)->GetString(0, &local e);
142 if (locale.empty()) 142 if (locale.empty())
143 return false; 143 return false;
144 144
145 // Finally, if all options are available, we only enable only SUGGEST 145 // Finally, if all options are available, we only enable only SUGGEST
146 // if SPELLCHECK is not available for our language because SPELLCHECK results 146 // if SPELLCHECK is not available for our language because SPELLCHECK results
147 // are a superset of SUGGEST results. 147 // are a superset of SUGGEST results.
148 for (const char* language : kValidLanguages) { 148 for (const char* language : kValidLanguages) {
149 if (!locale.compare(0, 2, language)) 149 if (!locale.compare(0, 2, language))
150 return type == SPELLCHECK; 150 return type == SPELLCHECK;
151 } 151 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 273
274 // The callback may release the last (transitive) dependency on |this|. It 274 // The callback may release the last (transitive) dependency on |this|. It
275 // MUST be the last function called. 275 // MUST be the last function called.
276 callback_data->callback.Run(success, callback_data->text, results); 276 callback_data->callback.Run(success, callback_data->text, results);
277 } 277 }
278 278
279 std::unique_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher( 279 std::unique_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher(
280 const GURL& url) { 280 const GURL& url) {
281 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); 281 return net::URLFetcher::Create(url, net::URLFetcher::POST, this);
282 } 282 }
OLDNEW
« no previous file with comments | « components/spellcheck/browser/spelling_service_client.h ('k') | components/spellcheck/browser/word_trimmer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698