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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/affiliation_fetch_throttler.h
diff --git a/components/password_manager/core/browser/affiliation_fetch_throttler.h b/components/password_manager/core/browser/affiliation_fetch_throttler.h
new file mode 100644
index 0000000000000000000000000000000000000000..db8f01a7716b8375c117ca673633bc4ec3226c3f
--- /dev/null
+++ b/components/password_manager/core/browser/affiliation_fetch_throttler.h
@@ -0,0 +1,83 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCH_THROTTLER_H_
+#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCH_THROTTLER_H_
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "net/base/network_change_notifier.h"
+
+namespace base {
+class TickClock;
+class SingleThreadTaskRunner;
+} // namespace base
+
+namespace net {
+class BackoffEntry;
+} // namespace net
+
+namespace password_manager {
+
+class AffiliationFetchThrottlerDelegate;
+
+// Implements the throttling logic that AffiliationBackend will use when it
+// needs to issue requests over the network to fetch affiliation information.
+//
+// Essentially, the logic consists of exponential backoff in case of network and
+// server errors, plus the additional constraint that no requests will be issued
+// in the first place while there is known to be no network connectivity.
+class AffiliationFetchThrottler
+ : public net::NetworkChangeNotifier::ConnectionTypeObserver {
+ public:
+ // Creates an instance that will use |tick_clock| as its tick source, and will
+ // post to |task_runner| to call the |delegate|'s OnSendNetworkRequest().
+ AffiliationFetchThrottler(
+ AffiliationFetchThrottlerDelegate* delegate,
+ 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.
+ scoped_ptr<base::TickClock> tick_clock);
+ ~AffiliationFetchThrottler() override;
+
+ // Signals to the throttling logic that a network request is needed, and that
+ // OnCanSendNetworkRequest() should be called as soon as the request can be
+ // sent. Calls to this method will be ignored while a request is in flight.
+ void SignalNetworkRequestNeeded();
+
+ // Informs the back-off logic that the in-flight network request has been
+ // completed, either with |success| or not.
+ void InformOfNetworkRequestComplete(bool success);
+
+ protected:
mmenke 2015/01/16 21:28:35 I think these can all be private.
engedy 2015/01/19 18:13:11 Done.
+ enum State { IDLE, FETCH_NEEDED, FETCH_IN_FLIGHT };
+
+ // Ensures that OnBackoffDelayExpiredCallback() is scheduled to be called back
+ // once the |exponential_backoff_| delay expires.
+ void EnsureCallbackIsScheduled();
+
+ // Called back when the |exponential_backoff_| delay expires.
+ void OnBackoffDelayExpiredCallback();
+
+ // net::NetworkChangeNotifier::ConnectionTypeObserver:
+ void OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) override;
+
+ private:
+ AffiliationFetchThrottlerDelegate* delegate_;
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ State state_;
+ bool has_network_connectivity_;
+ bool is_fetch_scheduled_;
+ scoped_ptr<base::TickClock> tick_clock_;
+ scoped_ptr<net::BackoffEntry> exponential_backoff_;
+ base::WeakPtrFactory<AffiliationFetchThrottler> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(AffiliationFetchThrottler);
+};
+
+} // namespace password_manager
+
+#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCH_THROTTLER_H_

Powered by Google App Engine
This is Rietveld 408576698