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

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

Issue 1863133003: [NTP Snippets] Re-fetch snippets on ML changes only when the hosts actually change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snippets_thumbnails
Patch Set: s/vector/set/ Created 4 years, 8 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_util.h" 10 #include "base/strings/string_util.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 weak_ptr_factory_(this) {} 59 weak_ptr_factory_(this) {}
60 60
61 NTPSnippetsFetcher::~NTPSnippetsFetcher() { 61 NTPSnippetsFetcher::~NTPSnippetsFetcher() {
62 } 62 }
63 63
64 scoped_ptr<NTPSnippetsFetcher::SnippetsAvailableCallbackList::Subscription> 64 scoped_ptr<NTPSnippetsFetcher::SnippetsAvailableCallbackList::Subscription>
65 NTPSnippetsFetcher::AddCallback(const SnippetsAvailableCallback& callback) { 65 NTPSnippetsFetcher::AddCallback(const SnippetsAvailableCallback& callback) {
66 return callback_list_.Add(callback); 66 return callback_list_.Add(callback);
67 } 67 }
68 68
69 void NTPSnippetsFetcher::FetchSnippets(const std::vector<std::string>& hosts) { 69 void NTPSnippetsFetcher::FetchSnippets(const std::set<std::string>& hosts) {
70 // TODO(treib): What to do if there's already a pending request? 70 // TODO(treib): What to do if there's already a pending request?
71 const std::string& key = is_stable_channel_ 71 const std::string& key = is_stable_channel_
72 ? google_apis::GetAPIKey() 72 ? google_apis::GetAPIKey()
73 : google_apis::GetNonStableAPIKey(); 73 : google_apis::GetNonStableAPIKey();
74 std::string url = 74 std::string url =
75 base::StringPrintf(kContentSnippetsServerFormat, key.c_str()); 75 base::StringPrintf(kContentSnippetsServerFormat, key.c_str());
76 url_fetcher_ = URLFetcher::Create(GURL(url), URLFetcher::POST, this); 76 url_fetcher_ = URLFetcher::Create(GURL(url), URLFetcher::POST, this);
77 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); 77 url_fetcher_->SetRequestContext(url_request_context_getter_.get());
78 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 78 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
79 net::LOAD_DO_NOT_SAVE_COOKIES); 79 net::LOAD_DO_NOT_SAVE_COOKIES);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 115
116 std::string response; 116 std::string response;
117 bool stores_result_to_string = source->GetResponseAsString(&response); 117 bool stores_result_to_string = source->GetResponseAsString(&response);
118 DCHECK(stores_result_to_string); 118 DCHECK(stores_result_to_string);
119 119
120 callback_list_.Notify(response); 120 callback_list_.Notify(response);
121 } 121 }
122 122
123 } // namespace ntp_snippets 123 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippets_fetcher.h ('k') | components/ntp_snippets/ntp_snippets_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698