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/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/string_escape.h" | 8 #include "base/json/string_escape.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 std::vector<SpellCheckResult> results; | 115 std::vector<SpellCheckResult> results; |
116 if (source->GetResponseCode() / 100 == 2) { | 116 if (source->GetResponseCode() / 100 == 2) { |
117 std::string data; | 117 std::string data; |
118 source->GetResponseAsString(&data); | 118 source->GetResponseAsString(&data); |
119 success = ParseResponse(data, &results); | 119 success = ParseResponse(data, &results); |
120 } | 120 } |
121 callback_.Run(tag_, success, results); | 121 callback_.Run(tag_, success, results); |
122 } | 122 } |
123 | 123 |
124 net::URLFetcher* SpellingServiceClient::CreateURLFetcher(const GURL& url) { | 124 net::URLFetcher* SpellingServiceClient::CreateURLFetcher(const GURL& url) { |
125 return content::URLFetcher::Create(url, content::URLFetcher::POST, this); | 125 return content::URLFetcher::Create(url, net::URLFetcher::POST, this); |
126 } | 126 } |
127 | 127 |
128 bool SpellingServiceClient::ParseResponse( | 128 bool SpellingServiceClient::ParseResponse( |
129 const std::string& data, | 129 const std::string& data, |
130 std::vector<SpellCheckResult>* results) { | 130 std::vector<SpellCheckResult>* results) { |
131 // When this JSON-RPC call finishes successfully, the Spelling service returns | 131 // When this JSON-RPC call finishes successfully, the Spelling service returns |
132 // an JSON object listed below. | 132 // an JSON object listed below. |
133 // * result - an envelope object representing the result from the APIARY | 133 // * result - an envelope object representing the result from the APIARY |
134 // server, which is the JSON-API front-end for the Spelling service. This | 134 // server, which is the JSON-API front-end for the Spelling service. This |
135 // object consists of the following variable: | 135 // object consists of the following variable: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 if (!suggestions->GetDictionary(0, &suggestion) || | 195 if (!suggestions->GetDictionary(0, &suggestion) || |
196 !suggestion->GetString("suggestion", &replacement)) { | 196 !suggestion->GetString("suggestion", &replacement)) { |
197 return false; | 197 return false; |
198 } | 198 } |
199 SpellCheckResult result( | 199 SpellCheckResult result( |
200 SpellCheckResult::SPELLING, start, length, replacement); | 200 SpellCheckResult::SPELLING, start, length, replacement); |
201 results->push_back(result); | 201 results->push_back(result); |
202 } | 202 } |
203 return true; | 203 return true; |
204 } | 204 } |
OLD | NEW |