Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: components/spellcheck/browser/spelling_service_client.cc

Issue 2421333002: Protobuf for Traffic Annotation and first use by a URLFetcher. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/spellcheck/browser/spelling_service_client.h" 5 #include "components/spellcheck/browser/spelling_service_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 "\"originCountry\":\"%s\"," 95 "\"originCountry\":\"%s\","
96 "\"key\":%s" 96 "\"key\":%s"
97 "}" 97 "}"
98 "}"; 98 "}";
99 std::string api_key = base::GetQuotedJSONString(google_apis::GetAPIKey()); 99 std::string api_key = base::GetQuotedJSONString(google_apis::GetAPIKey());
100 std::string request = base::StringPrintf( 100 std::string request = base::StringPrintf(
101 kSpellingRequest, type, encoded_text.c_str(), language_code.c_str(), 101 kSpellingRequest, type, encoded_text.c_str(), language_code.c_str(),
102 country_code.c_str(), api_key.c_str()); 102 country_code.c_str(), api_key.c_str());
103 103
104 GURL url = GURL(kSpellingServiceURL); 104 GURL url = GURL(kSpellingServiceURL);
105 net::URLFetcher* fetcher = CreateURLFetcher(url).release(); 105
106 // Create traffic annotation tag.
107 net::NetworkTrafficAnnotationTag traffic_annotation =
108 net::DefineNetworkTrafficAnnotation("spellcheck_lookup", R"(
109 semantics {
110 sender: "spellcheck"
111 description: "Sends the text a user types into a text field in the "
112 "content area of the browser. Also sends a misspelled "
113 "word, if a user right-clicks on it."
battre 2016/10/17 14:58:45 Looking at this again, I think that we need to des
Ramin Halavati 2016/10/18 06:57:56 Done.
114 trigger: "User types something or asks to correct a misspelled word."
battre 2016/10/17 14:58:45 trigger: User types text into a text field or asks
Ramin Halavati 2016/10/18 06:57:56 Done.
115 data: "Text a user has typed into a text field. No user identifier "
116 "is sent along with the text."
117 destination: GOOGLE_OWNED_SERVICE
118 }
119 policy {
120 cookies_allowed: false
121 setting: "You can disable 'Use a web service to help resolve "
122 "spelling errors.' in Chrome's settings under Advanced."
battre 2016/10/17 14:58:45 You can enable or disable this feature via '...' .
Ramin Halavati 2016/10/18 06:57:56 Done.
123 policy: "SpellCheckServiceEnabled: "
battre 2016/10/17 14:58:45 nit: no space after colon
Ramin Halavati 2016/10/18 06:57:56 Done.
124 " policy_options: MANDATORY"
125 " value: false"
126 })");
127
128 net::URLFetcher* fetcher =
129 CreateURLFetcher(url, traffic_annotation).release();
106 data_use_measurement::DataUseUserData::AttachToFetcher( 130 data_use_measurement::DataUseUserData::AttachToFetcher(
107 fetcher, data_use_measurement::DataUseUserData::SPELL_CHECKER); 131 fetcher, data_use_measurement::DataUseUserData::SPELL_CHECKER);
108 fetcher->SetRequestContext( 132 fetcher->SetRequestContext(
109 content::BrowserContext::GetDefaultStoragePartition(context) 133 content::BrowserContext::GetDefaultStoragePartition(context)
110 ->GetURLRequestContext()); 134 ->GetURLRequestContext());
111 fetcher->SetUploadData("application/json", request); 135 fetcher->SetUploadData("application/json", request);
112 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 136 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
113 net::LOAD_DO_NOT_SAVE_COOKIES); 137 net::LOAD_DO_NOT_SAVE_COOKIES);
114 spellcheck_fetchers_[fetcher] = base::MakeUnique<TextCheckCallbackData>( 138 spellcheck_fetchers_[fetcher] = base::MakeUnique<TextCheckCallbackData>(
115 base::WrapUnique(fetcher), callback, text); 139 base::WrapUnique(fetcher), callback, text);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 source->GetResponseAsString(&data); 286 source->GetResponseAsString(&data);
263 success = ParseResponse(data, &results); 287 success = ParseResponse(data, &results);
264 } 288 }
265 289
266 // The callback may release the last (transitive) dependency on |this|. It 290 // The callback may release the last (transitive) dependency on |this|. It
267 // MUST be the last function called. 291 // MUST be the last function called.
268 callback_data->callback.Run(success, callback_data->text, results); 292 callback_data->callback.Run(success, callback_data->text, results);
269 } 293 }
270 294
271 std::unique_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher( 295 std::unique_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher(
272 const GURL& url) { 296 const GURL& url,
273 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); 297 net::NetworkTrafficAnnotationTag traffic_annotation) {
298 return net::URLFetcher::Create(url, net::URLFetcher::POST, this,
299 traffic_annotation);
274 } 300 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698