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