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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "chrome/common/spellcheck_common.h" | 19 #include "chrome/common/spellcheck_common.h" |
20 #include "chrome/common/spellcheck_result.h" | 20 #include "chrome/common/spellcheck_result.h" |
21 #include "components/data_use_measurement/core/data_use_user_data.h" | |
22 #include "components/user_prefs/user_prefs.h" | 21 #include "components/user_prefs/user_prefs.h" |
23 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
24 #include "google_apis/google_api_keys.h" | 23 #include "google_apis/google_api_keys.h" |
25 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
26 #include "net/url_request/url_fetcher.h" | 25 #include "net/url_request/url_fetcher.h" |
27 #include "url/gurl.h" | 26 #include "url/gurl.h" |
28 | 27 |
29 namespace { | 28 namespace { |
30 | 29 |
31 // The URL for requesting spell checking and sending user feedback. | 30 // The URL for requesting spell checking and sending user feedback. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 std::string request = base::StringPrintf( | 98 std::string request = base::StringPrintf( |
100 kSpellingRequest, | 99 kSpellingRequest, |
101 type, | 100 type, |
102 encoded_text.c_str(), | 101 encoded_text.c_str(), |
103 language_code.c_str(), | 102 language_code.c_str(), |
104 country_code.c_str(), | 103 country_code.c_str(), |
105 api_key.c_str()); | 104 api_key.c_str()); |
106 | 105 |
107 GURL url = GURL(kSpellingServiceURL); | 106 GURL url = GURL(kSpellingServiceURL); |
108 net::URLFetcher* fetcher = CreateURLFetcher(url).release(); | 107 net::URLFetcher* fetcher = CreateURLFetcher(url).release(); |
109 data_use_measurement::DataUseUserData::AttachToFetcher( | |
110 fetcher, data_use_measurement::DataUseUserData::SPELL_CHECKER); | |
111 fetcher->SetRequestContext(context->GetRequestContext()); | 108 fetcher->SetRequestContext(context->GetRequestContext()); |
112 fetcher->SetUploadData("application/json", request); | 109 fetcher->SetUploadData("application/json", request); |
113 fetcher->SetLoadFlags( | 110 fetcher->SetLoadFlags( |
114 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); | 111 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); |
115 spellcheck_fetchers_[fetcher] = new TextCheckCallbackData(callback, text); | 112 spellcheck_fetchers_[fetcher] = new TextCheckCallbackData(callback, text); |
116 fetcher->Start(); | 113 fetcher->Start(); |
117 return true; | 114 return true; |
118 } | 115 } |
119 | 116 |
120 bool SpellingServiceClient::IsAvailable( | 117 bool SpellingServiceClient::IsAvailable( |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 264 |
268 // The callback may release the last (transitive) dependency on |this|. It | 265 // The callback may release the last (transitive) dependency on |this|. It |
269 // MUST be the last function called. | 266 // MUST be the last function called. |
270 callback_data->callback.Run(success, callback_data->text, results); | 267 callback_data->callback.Run(success, callback_data->text, results); |
271 } | 268 } |
272 | 269 |
273 scoped_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher( | 270 scoped_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher( |
274 const GURL& url) { | 271 const GURL& url) { |
275 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); | 272 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); |
276 } | 273 } |
OLD | NEW |