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

Side by Side Diff: net/http/http_broken_alternative_services_manager.h

Issue 2898983006: Fix and refactor HttpServerPropertiesImpl's alternative services brokenness expiration behavior (Closed)
Patch Set: Created 3 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
(Empty)
1 // Copyright (c) 2017 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 NET_HTTP_HTTP_BROKEN_ALTERNATIVE_SERVICES_MANAGER_H_
6 #define NET_HTTP_HTTP_BROKEN_ALTERNATIVE_SERVICES_MANAGER_H_
7
8 #include <list>
9 #include <unordered_map>
10
11 #include "base/memory/weak_ptr.h"
12 #include "base/timer/timer.h"
13 #include "net/http/http_server_properties.h"
14
15 namespace net {
16
17 struct AlternativeServiceHash {
18 size_t operator()(const net::AlternativeService& entry) const {
19 return entry.protocol ^ std::hash<std::string>()(entry.host) ^ entry.port;
20 }
21 };
22
23 class NET_EXPORT HttpBrokenAlternativeServicesManager {
Ryan Hamilton 2017/05/25 03:03:50 nit: This class name is a bit of a mouthful, how '
wangyix1 2017/05/26 01:14:24 Done.
24 public:
25 // Interface for retrieving the current time as base::TimeTicks
26 class NET_EXPORT Clock {
27 public:
28 virtual ~Clock() {}
29 virtual base::TimeTicks Now() const = 0;
30 };
31
32 class NET_EXPORT DefaultClock : public Clock {
Ryan Hamilton 2017/05/25 03:03:50 nit: You could consider adding static method to cl
wangyix1 2017/05/26 01:14:24 Done.
33 public:
34 static DefaultClock* GetInstance();
35 DefaultClock() {}
36 ~DefaultClock() override {}
37 base::TimeTicks Now() const override;
38
39 private:
40 DISALLOW_COPY_AND_ASSIGN(DefaultClock);
41 };
42
43 // Delegate for owner to be notified when the brokenness of an
44 // AlternativeService expires.
45 class NET_EXPORT Delegate {
46 public:
47 virtual void OnExpireBrokenAlternativeService(
48 const AlternativeService& expired_alternative_service) = 0;
Ryan Hamilton 2017/05/25 03:03:50 Should we also have virtual ~Delegate() {}?
wangyix1 2017/05/26 01:14:24 Done.
49 };
50
51 HttpBrokenAlternativeServicesManager(Delegate* delegate, Clock* clock);
Ryan Hamilton 2017/05/25 03:03:50 nit: Comment, please, and note the ownership/lifet
wangyix1 2017/05/26 01:14:24 Done.
52
53 ~HttpBrokenAlternativeServicesManager();
54
55 void MarkAlternativeServiceBroken(
Ryan Hamilton 2017/05/25 03:03:50 nit: comments for all these methods, please.
wangyix1 2017/05/26 01:14:24 Done.
56 const AlternativeService& alternative_service);
57 void MarkAlternativeServiceRecentlyBroken(
58 const AlternativeService& alternative_service);
59 bool IsAlternativeServiceBroken(
60 const AlternativeService& alternative_service) const;
61 bool WasAlternativeServiceRecentlyBroken(
62 const AlternativeService& alternative_service);
63 void ConfirmAlternativeService(const AlternativeService& alternative_service);
64
65 static base::TimeDelta ComputeBrokenAltSvcExpirationDelayForTest(
66 int broken_count);
Ryan Hamilton 2017/05/25 03:03:50 Can we just put this in a test.cc file instead?
wangyix1 2017/05/26 01:14:24 Done.
67
68 private:
69 friend class HttpServerPropertiesImplPeer;
Ryan Hamilton 2017/05/25 03:03:50 We should see if we can get rid of this friend-nes
wangyix1 2017/05/26 01:14:24 Done.
70
71 struct BrokenAltSvcExpireInfo {
Ryan Hamilton 2017/05/25 03:03:50 nit: comment.
wangyix1 2017/05/26 01:14:24 Done.
72 BrokenAltSvcExpireInfo(const AlternativeService& alt_svc,
73 base::TimeTicks expire)
74 : alternative_service(alt_svc), expiration(expire) {}
75 AlternativeService alternative_service;
Ryan Hamilton 2017/05/25 03:03:50 nit: newline before
wangyix1 2017/05/26 01:14:24 Done.
76 base::TimeTicks expiration;
77 };
78
79 typedef std::list<BrokenAltSvcExpireInfo> BrokenAlternativeServiceList;
80
81 typedef std::unordered_map<AlternativeService,
82 BrokenAlternativeServiceList::iterator,
83 AlternativeServiceHash>
84 BrokenAlternativeServiceMap;
85
86 // Inserts |alternative_service| and its |expiration| time into
87 // |broken_alternative_service_list_| and |broken_alternative_service_map_|.
88 // |it| is the position in |broken_alternative_service_list_| where it was
89 // inserted.
90 bool AddToBrokenAlternativeServiceListAndMap(
91 const AlternativeService& alternative_service,
92 base::TimeTicks expiration,
93 BrokenAlternativeServiceList::iterator* it);
94
95 void ExpireBrokenAlternateProtocolMappings();
96 void ScheduleBrokenAlternateProtocolMappingsExpiration();
97
98 Delegate* delegate_;
Ryan Hamilton 2017/05/25 03:03:50 nit: // Unowned.
wangyix1 2017/05/26 01:14:24 Done.
99
100 BrokenAlternativeServiceMap broken_alternative_service_map_;
101 BrokenAlternativeServiceList broken_alternative_service_list_;
102 RecentlyBrokenAlternativeServices recently_broken_alternative_services_;
103
104 Clock* clock_; // Unowned
105
106 // Used for scheduling the task that expires the brokenness of alternative
107 // services.
108 base::OneShotTimer timer_;
Ryan Hamilton 2017/05/25 03:03:50 nit: how 'bout expiration_timer_?
wangyix1 2017/05/26 01:14:24 Done.
109
110 base::WeakPtrFactory<HttpBrokenAlternativeServicesManager> weak_ptr_factory_;
111
112 DISALLOW_COPY_AND_ASSIGN(HttpBrokenAlternativeServicesManager);
Ryan Hamilton 2017/05/25 03:03:50 nit: I think the new hotness is using = delete for
wangyix1 2017/05/26 01:14:24 Done.
113 };
114
115 } // namespace net
116
117 #endif // NET_HTTP_HTTP_BROKEN_ALTERNATIVE_SERVICES_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698