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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 GURL url = GURL(kSpellingServiceURL); | 93 GURL url = GURL(kSpellingServiceURL); |
94 fetcher_.reset(CreateURLFetcher(url)); | 94 fetcher_.reset(CreateURLFetcher(url)); |
95 fetcher_->SetRequestContext(profile->GetRequestContext()); | 95 fetcher_->SetRequestContext(profile->GetRequestContext()); |
96 fetcher_->SetUploadData("application/json", request); | 96 fetcher_->SetUploadData("application/json", request); |
97 fetcher_->SetLoadFlags( | 97 fetcher_->SetLoadFlags( |
98 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); | 98 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); |
99 fetcher_->Start(); | 99 fetcher_->Start(); |
100 tag_ = tag; | 100 tag_ = tag; |
101 text_ = text; | 101 text_ = text; |
102 callback_ = callback; | 102 callback_ = callback; |
103 type_ = type; | |
groby-ooo-7-16
2012/12/21 22:18:13
Since tag_ and type_ are only needed when we run t
rpetterson
2013/01/04 00:05:34
Done.
| |
103 return true; | 104 return true; |
104 } | 105 } |
105 | 106 |
106 bool SpellingServiceClient::IsAvailable(Profile* profile, ServiceType type) { | 107 bool SpellingServiceClient::IsAvailable(Profile* profile, ServiceType type) { |
107 const PrefService* pref = profile->GetPrefs(); | 108 const PrefService* pref = profile->GetPrefs(); |
108 if (!pref->GetBoolean(prefs::kEnableContinuousSpellcheck) || | 109 if (!pref->GetBoolean(prefs::kEnableContinuousSpellcheck) || |
109 !pref->GetBoolean(prefs::kSpellCheckUseSpellingService)) | 110 !pref->GetBoolean(prefs::kSpellCheckUseSpellingService)) |
110 return false; | 111 return false; |
111 | 112 |
112 // If the locale for spelling has not been set, the user has not decided to | 113 // If the locale for spelling has not been set, the user has not decided to |
(...skipping 26 matching lines...) Expand all Loading... | |
139 void SpellingServiceClient::OnURLFetchComplete( | 140 void SpellingServiceClient::OnURLFetchComplete( |
140 const net::URLFetcher* source) { | 141 const net::URLFetcher* source) { |
141 scoped_ptr<net::URLFetcher> clean_up_fetcher(fetcher_.release()); | 142 scoped_ptr<net::URLFetcher> clean_up_fetcher(fetcher_.release()); |
142 bool success = false; | 143 bool success = false; |
143 std::vector<SpellCheckResult> results; | 144 std::vector<SpellCheckResult> results; |
144 if (source->GetResponseCode() / 100 == 2) { | 145 if (source->GetResponseCode() / 100 == 2) { |
145 std::string data; | 146 std::string data; |
146 source->GetResponseAsString(&data); | 147 source->GetResponseAsString(&data); |
147 success = ParseResponse(data, &results); | 148 success = ParseResponse(data, &results); |
148 } | 149 } |
149 callback_.Run(tag_, success, text_, results); | 150 callback_.Run(tag_, success, type_, text_, results); |
150 } | 151 } |
151 | 152 |
152 net::URLFetcher* SpellingServiceClient::CreateURLFetcher(const GURL& url) { | 153 net::URLFetcher* SpellingServiceClient::CreateURLFetcher(const GURL& url) { |
153 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); | 154 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); |
154 } | 155 } |
155 | 156 |
156 bool SpellingServiceClient::ParseResponse( | 157 bool SpellingServiceClient::ParseResponse( |
157 const std::string& data, | 158 const std::string& data, |
158 std::vector<SpellCheckResult>* results) { | 159 std::vector<SpellCheckResult>* results) { |
159 // When this JSON-RPC call finishes successfully, the Spelling service returns | 160 // When this JSON-RPC call finishes successfully, the Spelling service returns |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 if (!suggestions->GetDictionary(0, &suggestion) || | 224 if (!suggestions->GetDictionary(0, &suggestion) || |
224 !suggestion->GetString("suggestion", &replacement)) { | 225 !suggestion->GetString("suggestion", &replacement)) { |
225 return false; | 226 return false; |
226 } | 227 } |
227 SpellCheckResult result( | 228 SpellCheckResult result( |
228 SpellCheckResult::SPELLING, start, length, replacement); | 229 SpellCheckResult::SPELLING, start, length, replacement); |
229 results->push_back(result); | 230 results->push_back(result); |
230 } | 231 } |
231 return true; | 232 return true; |
232 } | 233 } |
OLD | NEW |