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

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

Issue 1978513002: Getting the personalization info in chrome://snippets-internals correct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: After code review #1 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 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 SUCCESS, 58 SUCCESS,
59 EMPTY_HOSTS, 59 EMPTY_HOSTS,
60 URL_REQUEST_STATUS_ERROR, 60 URL_REQUEST_STATUS_ERROR,
61 HTTP_ERROR, 61 HTTP_ERROR,
62 JSON_PARSE_ERROR, 62 JSON_PARSE_ERROR,
63 INVALID_SNIPPET_CONTENT_ERROR, 63 INVALID_SNIPPET_CONTENT_ERROR,
64 OAUTH_TOKEN_ERROR, 64 OAUTH_TOKEN_ERROR,
65 RESULT_MAX 65 RESULT_MAX
66 }; 66 };
67 67
68 // Enum listing all possible variants of dealing with personalization. 68 // Enumeration listing all possible variants of dealing with personalization.
69 enum class Personalization { kPersonal, kNonPersonal, kBoth }; 69 enum class Personalization { kPersonal, kNonPersonal, kBoth };
70 70
71 NTPSnippetsFetcher( 71 NTPSnippetsFetcher(
72 SigninManagerBase* signin_manager, 72 SigninManagerBase* signin_manager,
73 OAuth2TokenService* oauth2_token_service, 73 OAuth2TokenService* oauth2_token_service,
74 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, 74 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
75 const ParseJSONCallback& parse_json_callback, 75 const ParseJSONCallback& parse_json_callback,
76 bool is_stable_channel); 76 bool is_stable_channel);
77 ~NTPSnippetsFetcher() override; 77 ~NTPSnippetsFetcher() override;
78 78
79 // Set a callback that is called when a new set of snippets are downloaded, 79 // Set a callback that is called when a new set of snippets are downloaded,
80 // overriding any previously set callback. 80 // overriding any previously set callback.
81 void SetCallback(const SnippetsAvailableCallback& callback); 81 void SetCallback(const SnippetsAvailableCallback& callback);
82 82
83 // Fetches snippets from the server. |hosts| restricts the results to a set of 83 // Fetches snippets from the server. |hosts| restricts the results to a set of
84 // hosts, e.g. "www.google.com". An empty host set produces an error. 84 // hosts, e.g. "www.google.com". An empty host set produces an error.
85 // 85 //
86 // If an ongoing fetch exists, it will be cancelled and a new one started, 86 // If an ongoing fetch exists, it will be cancelled and a new one started,
87 // without triggering an additional callback (i.e. not noticeable by 87 // without triggering an additional callback (i.e. not noticeable by
88 // subscriber of SetCallback()). 88 // subscriber of SetCallback()).
89 void FetchSnippetsFromHosts(const std::set<std::string>& hosts, 89 void FetchSnippetsFromHosts(const std::set<std::string>& hosts,
90 const std::string& language_code, 90 const std::string& language_code,
91 int count); 91 int count);
92 92
93 // Debug string representing the status/result of the last fetch attempt. 93 // Debug string representing the status/result of the last fetch attempt.
94 const std::string& last_status() const { return last_status_; } 94 const std::string& last_status() const { return last_status_; }
95 95
96 // Returns the last json fetched from the server. 96 // Returns the last JSON fetched from the server.
97 const std::string& last_json() const { 97 const std::string& last_json() const {
98 return last_fetch_json_; 98 return last_fetch_json_;
99 } 99 }
100 100
101 // Returns the personalization setting of the fetcher. 101 // Returns the personalization setting of the fetcher.
102 Personalization personalization() const { return personalization_; } 102 Personalization personalization() const { return personalization_; }
103 103
104 // Does the fetcher use host restriction? 104 // Does the fetcher use host restrictions?
105 bool UseHostRestriction() const; 105 bool UsesHostRestrictions() const;
106 // Does the fetcher use authentication to get personalized results? 106 // Does the fetcher use authentication to get personalized results?
107 bool UseAuthentication() const; 107 bool UsesAuthentication() const;
108 108
109 // Overrides internal clock for testing purposes. 109 // Overrides internal clock for testing purposes.
110 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { 110 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) {
111 tick_clock_ = std::move(tick_clock); 111 tick_clock_ = std::move(tick_clock);
112 } 112 }
113 113
114 private: 114 private:
115 void FetchSnippetsImpl(const GURL& url, 115 void FetchSnippetsImpl(const GURL& url,
116 const std::string& auth_header, 116 const std::string& auth_header,
117 const std::string& request); 117 const std::string& request);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // Allow for an injectable tick clock for testing. 180 // Allow for an injectable tick clock for testing.
181 std::unique_ptr<base::TickClock> tick_clock_; 181 std::unique_ptr<base::TickClock> tick_clock_;
182 182
183 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; 183 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_;
184 184
185 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); 185 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher);
186 }; 186 };
187 } // namespace ntp_snippets 187 } // namespace ntp_snippets
188 188
189 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ 189 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698