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

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

Issue 2227973002: Add request throttler to thumbnail fetching for articles on mobile NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_SERVICE_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/callback_forward.h" 15 #include "base/callback_forward.h"
16 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/timer/timer.h" 18 #include "base/timer/timer.h"
19 #include "components/image_fetcher/image_fetcher_delegate.h" 19 #include "components/image_fetcher/image_fetcher_delegate.h"
20 #include "components/ntp_snippets/category.h" 20 #include "components/ntp_snippets/category.h"
21 #include "components/ntp_snippets/category_factory.h" 21 #include "components/ntp_snippets/category_factory.h"
22 #include "components/ntp_snippets/category_status.h" 22 #include "components/ntp_snippets/category_status.h"
23 #include "components/ntp_snippets/content_suggestion.h" 23 #include "components/ntp_snippets/content_suggestion.h"
24 #include "components/ntp_snippets/content_suggestions_provider.h" 24 #include "components/ntp_snippets/content_suggestions_provider.h"
25 #include "components/ntp_snippets/ntp_snippet.h" 25 #include "components/ntp_snippets/ntp_snippet.h"
26 #include "components/ntp_snippets/ntp_snippets_fetcher.h" 26 #include "components/ntp_snippets/ntp_snippets_fetcher.h"
27 #include "components/ntp_snippets/ntp_snippets_scheduler.h" 27 #include "components/ntp_snippets/ntp_snippets_scheduler.h"
28 #include "components/ntp_snippets/ntp_snippets_status_service.h" 28 #include "components/ntp_snippets/ntp_snippets_status_service.h"
29 #include "components/ntp_snippets/request_throttler.h"
29 #include "components/suggestions/suggestions_service.h" 30 #include "components/suggestions/suggestions_service.h"
30 #include "components/sync_driver/sync_service_observer.h" 31 #include "components/sync_driver/sync_service_observer.h"
31 32
32 class PrefRegistrySimple; 33 class PrefRegistrySimple;
33 class PrefService; 34 class PrefService;
34 class SigninManagerBase; 35 class SigninManagerBase;
35 36
36 namespace base { 37 namespace base {
37 class RefCountedMemory; 38 class RefCountedMemory;
38 class Value; 39 class Value;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // Returns whether the service is ready. While this is false, the list of 91 // Returns whether the service is ready. While this is false, the list of
91 // snippets will be empty, and all modifications to it (fetch, dismiss, etc) 92 // snippets will be empty, and all modifications to it (fetch, dismiss, etc)
92 // will be ignored. 93 // will be ignored.
93 bool ready() const { return state_ == State::READY; } 94 bool ready() const { return state_ == State::READY; }
94 95
95 // Returns whether the service is initialized. While this is false, some 96 // Returns whether the service is initialized. While this is false, some
96 // calls may trigger DCHECKs. 97 // calls may trigger DCHECKs.
97 bool initialized() const { return ready() || state_ == State::DISABLED; } 98 bool initialized() const { return ready() || state_ == State::DISABLED; }
98 99
99 // Fetches snippets from the server and adds them to the current ones. 100 // Fetches snippets from the server and adds them to the current ones.
100 // Requests can be marked more important by setting |force_request| to true 101 // Requests can be marked more important by setting |interactive_request| to
101 // (such request might circumvent the daily quota for requests, etc.) Useful 102 // true (such request might circumvent the daily quota for requests, etc.)
102 // for requests triggered by the user. 103 // Useful for requests triggered by the user.
103 void FetchSnippets(bool force_request); 104 void FetchSnippets(bool interactive_request);
104 105
105 // Fetches snippets from the server for specified hosts (overriding 106 // Fetches snippets from the server for specified hosts (overriding
106 // suggestions from the suggestion service) and adds them to the current ones. 107 // suggestions from the suggestion service) and adds them to the current ones.
107 // Only called from chrome://snippets-internals, DO NOT USE otherwise! 108 // Only called from chrome://snippets-internals, DO NOT USE otherwise!
108 // Ignored while |loaded()| is false. 109 // Ignored while |loaded()| is false.
109 void FetchSnippetsFromHosts(const std::set<std::string>& hosts, 110 void FetchSnippetsFromHosts(const std::set<std::string>& hosts,
110 bool force_request); 111 bool interactive_request);
111 112
112 // Available snippets. 113 // Available snippets.
113 const NTPSnippet::PtrVector& snippets() const { return snippets_; } 114 const NTPSnippet::PtrVector& snippets() const { return snippets_; }
114 115
115 // Returns the list of snippets previously dismissed by the user (that are 116 // Returns the list of snippets previously dismissed by the user (that are
116 // not expired yet). 117 // not expired yet).
117 const NTPSnippet::PtrVector& dismissed_snippets() const { 118 const NTPSnippet::PtrVector& dismissed_snippets() const {
118 return dismissed_snippets_; 119 return dismissed_snippets_;
119 } 120 }
120 121
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 301
301 // The service that provides events and data about the signin and sync state. 302 // The service that provides events and data about the signin and sync state.
302 std::unique_ptr<NTPSnippetsStatusService> snippets_status_service_; 303 std::unique_ptr<NTPSnippetsStatusService> snippets_status_service_;
303 304
304 // Set to true if FetchSnippets is called before the database has been loaded. 305 // Set to true if FetchSnippets is called before the database has been loaded.
305 // The fetch will be executed after the database load finishes. 306 // The fetch will be executed after the database load finishes.
306 bool fetch_after_load_; 307 bool fetch_after_load_;
307 308
308 const Category provided_category_; 309 const Category provided_category_;
309 310
311 // Request throttler for limiting requests to thumbnail images.
312 RequestThrottler thumbnail_requests_throttler_;
313
310 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); 314 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService);
311 }; 315 };
312 316
313 } // namespace ntp_snippets 317 } // namespace ntp_snippets
314 318
315 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 319 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698