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

Side by Side Diff: chrome/browser/spellchecker/spelling_service_client.cc

Issue 100823007: Stop doing unnecessary UTF-8 to UTF-16 conversions in JSONWriter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 7 years 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 | Annotate | Revision Log
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 "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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 std::string language_code; 64 std::string language_code;
65 std::string country_code; 65 std::string country_code;
66 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( 66 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale(
67 pref->GetString(prefs::kSpellCheckDictionary), 67 pref->GetString(prefs::kSpellCheckDictionary),
68 &language_code, 68 &language_code,
69 &country_code); 69 &country_code);
70 70
71 // Format the JSON request to be sent to the Spelling service. 71 // Format the JSON request to be sent to the Spelling service.
72 std::string encoded_text; 72 std::string encoded_text;
73 base::JsonDoubleQuote(text, false, &encoded_text); 73 base::EscapeJSONString(text, false, &encoded_text);
Mark Mentovai 2013/12/06 15:35:12 Here.
Robert Sesek 2013/12/09 19:52:09 Done.
74 74
75 static const char kSpellingRequest[] = 75 static const char kSpellingRequest[] =
76 "{" 76 "{"
77 "\"method\":\"spelling.check\"," 77 "\"method\":\"spelling.check\","
78 "\"apiVersion\":\"v%d\"," 78 "\"apiVersion\":\"v%d\","
79 "\"params\":{" 79 "\"params\":{"
80 "\"text\":\"%s\"," 80 "\"text\":\"%s\","
81 "\"language\":\"%s\"," 81 "\"language\":\"%s\","
82 "\"originCountry\":\"%s\"," 82 "\"originCountry\":\"%s\","
83 "\"key\":%s" 83 "\"key\":%s"
84 "}" 84 "}"
85 "}"; 85 "}";
86 std::string api_key = base::GetDoubleQuotedJson(google_apis::GetAPIKey()); 86 std::string api_key = base::GetQuotedJSONString(google_apis::GetAPIKey());
87 std::string request = base::StringPrintf( 87 std::string request = base::StringPrintf(
88 kSpellingRequest, 88 kSpellingRequest,
89 type, 89 type,
90 encoded_text.c_str(), 90 encoded_text.c_str(),
91 language_code.c_str(), 91 language_code.c_str(),
92 country_code.c_str(), 92 country_code.c_str(),
93 api_key.c_str()); 93 api_key.c_str());
94 94
95 GURL url = GURL(kSpellingServiceURL); 95 GURL url = GURL(kSpellingServiceURL);
96 net::URLFetcher* fetcher = CreateURLFetcher(url); 96 net::URLFetcher* fetcher = CreateURLFetcher(url);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 fetcher->GetResponseAsString(&data); 255 fetcher->GetResponseAsString(&data);
256 success = ParseResponse(data, &results); 256 success = ParseResponse(data, &results);
257 } 257 }
258 callback_data->callback.Run(success, callback_data->text, results); 258 callback_data->callback.Run(success, callback_data->text, results);
259 spellcheck_fetchers_.erase(fetcher.get()); 259 spellcheck_fetchers_.erase(fetcher.get());
260 } 260 }
261 261
262 net::URLFetcher* SpellingServiceClient::CreateURLFetcher(const GURL& url) { 262 net::URLFetcher* SpellingServiceClient::CreateURLFetcher(const GURL& url) {
263 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); 263 return net::URLFetcher::Create(url, net::URLFetcher::POST, this);
264 } 264 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698