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