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

Side by Side Diff: components/ntp_snippets/ntp_snippets_fetcher.cc

Issue 1937003002: Track NTP snippets data usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tracker-enum
Patch Set: Created 4 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ntp_snippets/ntp_snippets_fetcher.h" 5 #include "components/ntp_snippets/ntp_snippets_fetcher.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/task_runner_util.h" 13 #include "base/task_runner_util.h"
14 #include "components/data_use_measurement/core/data_use_user_data.h"
14 #include "google_apis/google_api_keys.h" 15 #include "google_apis/google_api_keys.h"
15 #include "net/base/load_flags.h" 16 #include "net/base/load_flags.h"
16 #include "net/http/http_request_headers.h" 17 #include "net/http/http_request_headers.h"
17 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
18 #include "net/http/http_status_code.h" 19 #include "net/http/http_status_code.h"
19 #include "net/url_request/url_fetcher.h" 20 #include "net/url_request/url_fetcher.h"
20 21
21 using net::URLFetcher; 22 using net::URLFetcher;
22 using net::URLRequestContextGetter; 23 using net::URLRequestContextGetter;
23 using net::HttpRequestHeaders; 24 using net::HttpRequestHeaders;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // TODO(treib): What to do if there's already a pending request? 90 // TODO(treib): What to do if there's already a pending request?
90 const std::string& key = is_stable_channel_ 91 const std::string& key = is_stable_channel_
91 ? google_apis::GetAPIKey() 92 ? google_apis::GetAPIKey()
92 : google_apis::GetNonStableAPIKey(); 93 : google_apis::GetNonStableAPIKey();
93 std::string url = 94 std::string url =
94 base::StringPrintf(kContentSnippetsServerFormat, key.c_str()); 95 base::StringPrintf(kContentSnippetsServerFormat, key.c_str());
95 url_fetcher_ = URLFetcher::Create(GURL(url), URLFetcher::POST, this); 96 url_fetcher_ = URLFetcher::Create(GURL(url), URLFetcher::POST, this);
96 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); 97 url_fetcher_->SetRequestContext(url_request_context_getter_.get());
97 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 98 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
98 net::LOAD_DO_NOT_SAVE_COOKIES); 99 net::LOAD_DO_NOT_SAVE_COOKIES);
100 data_use_measurement::DataUseUserData::AttachToFetcher(
101 url_fetcher_.get(), data_use_measurement::DataUseUserData::NTP_SNIPPETS);
99 HttpRequestHeaders headers; 102 HttpRequestHeaders headers;
100 headers.SetHeader("Content-Type", "application/json; charset=UTF-8"); 103 headers.SetHeader("Content-Type", "application/json; charset=UTF-8");
101 url_fetcher_->SetExtraRequestHeaders(headers.ToString()); 104 url_fetcher_->SetExtraRequestHeaders(headers.ToString());
102 std::string host_restricts; 105 std::string host_restricts;
103 for (const std::string& host : hosts) 106 for (const std::string& host : hosts)
104 host_restricts += base::StringPrintf(kHostRestrictFormat, host.c_str()); 107 host_restricts += base::StringPrintf(kHostRestrictFormat, host.c_str());
105 url_fetcher_->SetUploadData("application/json", 108 url_fetcher_->SetUploadData("application/json",
106 base::StringPrintf(kRequestParameterFormat, 109 base::StringPrintf(kRequestParameterFormat,
107 host_restricts.c_str(), 110 host_restricts.c_str(),
108 count)); 111 count));
(...skipping 27 matching lines...) Expand all
136 139
137 } else { 140 } else {
138 bool stores_result_to_string = source->GetResponseAsString(&response); 141 bool stores_result_to_string = source->GetResponseAsString(&response);
139 DCHECK(stores_result_to_string); 142 DCHECK(stores_result_to_string);
140 } 143 }
141 144
142 callback_list_.Notify(response, message); 145 callback_list_.Notify(response, message);
143 } 146 }
144 147
145 } // namespace ntp_snippets 148 } // namespace ntp_snippets
OLDNEW
« components/ntp_snippets/BUILD.gn ('K') | « components/ntp_snippets/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698