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

Side by Side Diff: components/password_manager/core/browser/affiliation_fetch_throttler.h

Issue 807503002: Implement throttling logic for fetching affiliation information. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@aff_database
Patch Set: Addressed first round of comments. Created 5 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCH_THROTTLER_H_
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCH_THROTTLER_H_
7
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "net/base/network_change_notifier.h"
13
14 namespace base {
15 class TickClock;
16 class SingleThreadTaskRunner;
17 } // namespace base
18
19 namespace net {
20 class BackoffEntry;
21 } // namespace net
22
23 namespace password_manager {
24
25 class AffiliationFetchThrottlerDelegate;
26
27 // Implements the throttling logic that AffiliationBackend will use when it
28 // needs to issue requests over the network to fetch affiliation information.
29 //
30 // Essentially, the logic consists of exponential backoff in case of network and
31 // server errors, plus the additional constraint that no requests will be issued
32 // in the first place while there is known to be no network connectivity.
33 class AffiliationFetchThrottler
34 : public net::NetworkChangeNotifier::ConnectionTypeObserver {
35 public:
36 // Creates an instance that will use |tick_clock| as its tick source, and will
37 // post to |task_runner| to call the |delegate|'s OnSendNetworkRequest().
38 AffiliationFetchThrottler(
39 AffiliationFetchThrottlerDelegate* delegate,
40 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
mmenke 2015/01/16 21:28:35 const scoped_reftr<...>&, to avoid an extra ref co
engedy 2015/01/19 18:13:11 Done.
41 scoped_ptr<base::TickClock> tick_clock);
42 ~AffiliationFetchThrottler() override;
43
44 // Signals to the throttling logic that a network request is needed, and that
45 // OnCanSendNetworkRequest() should be called as soon as the request can be
46 // sent. Calls to this method will be ignored while a request is in flight.
47 void SignalNetworkRequestNeeded();
48
49 // Informs the back-off logic that the in-flight network request has been
50 // completed, either with |success| or not.
51 void InformOfNetworkRequestComplete(bool success);
52
53 protected:
mmenke 2015/01/16 21:28:35 I think these can all be private.
engedy 2015/01/19 18:13:11 Done.
54 enum State { IDLE, FETCH_NEEDED, FETCH_IN_FLIGHT };
55
56 // Ensures that OnBackoffDelayExpiredCallback() is scheduled to be called back
57 // once the |exponential_backoff_| delay expires.
58 void EnsureCallbackIsScheduled();
59
60 // Called back when the |exponential_backoff_| delay expires.
61 void OnBackoffDelayExpiredCallback();
62
63 // net::NetworkChangeNotifier::ConnectionTypeObserver:
64 void OnConnectionTypeChanged(
65 net::NetworkChangeNotifier::ConnectionType type) override;
66
67 private:
68 AffiliationFetchThrottlerDelegate* delegate_;
69 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
70
71 State state_;
72 bool has_network_connectivity_;
73 bool is_fetch_scheduled_;
74 scoped_ptr<base::TickClock> tick_clock_;
75 scoped_ptr<net::BackoffEntry> exponential_backoff_;
76 base::WeakPtrFactory<AffiliationFetchThrottler> weak_ptr_factory_;
77
78 DISALLOW_COPY_AND_ASSIGN(AffiliationFetchThrottler);
79 };
80
81 } // namespace password_manager
82
83 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCH_THROTTLER_ H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698