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