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

Side by Side Diff: components/safe_browsing/password_protection/password_protection_service.h

Issue 2817533004: Improve PasswordProtectionService and PasswordProtectionRequest (Closed)
Patch Set: rebase Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERVICE _H_ 5 #ifndef COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERVICE _H_
6 #define COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERVICE _H_ 6 #define COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERVICE _H_
7 7
8 #include <unordered_set> 8 #include <set>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/scoped_observer.h" 15 #include "base/scoped_observer.h"
16 #include "base/task/cancelable_task_tracker.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "components/history/core/browser/history_service_observer.h" 18 #include "components/history/core/browser/history_service_observer.h"
18 #include "components/safe_browsing/csd.pb.h" 19 #include "components/safe_browsing/csd.pb.h"
19 #include "net/url_request/url_request_context_getter.h" 20 #include "net/url_request/url_request_context_getter.h"
21 #include "third_party/protobuf/src/google/protobuf/repeated_field.h"
20 22
21 namespace history { 23 namespace history {
22 class HistoryService; 24 class HistoryService;
23 } 25 }
24 26
25 class GURL; 27 class GURL;
26 class HostContentSettingsMap; 28 class HostContentSettingsMap;
27 29
28 namespace safe_browsing { 30 namespace safe_browsing {
29 31
30 class SafeBrowsingDatabaseManager; 32 class SafeBrowsingDatabaseManager;
31 class PasswordProtectionRequest; 33 class PasswordProtectionRequest;
34 struct PasswordProtectionFrame;
Nathan Parker 2017/04/17 20:28:02 nit: You can remove this like if you move the "usi
Jialiu Lin 2017/04/18 00:58:27 Done.
35
36 using PasswordFormList = google::protobuf::RepeatedPtrField<
37 LoginReputationClientRequest::Frame::Form>;
38
39 using PasswordProtectionFrames =
40 std::vector<std::unique_ptr<PasswordProtectionFrame>>;
41
42 // The PasswordProtectionFrame struct encapsulates information about a render
43 // frame that has password form(s).
44 struct PasswordProtectionFrame {
45 int render_frame_routing_id;
46 int parent_frame_routing_id;
47 GURL last_committed_url;
48 std::unique_ptr<PasswordFormList> password_forms;
49
50 PasswordProtectionFrame();
51
52 ~PasswordProtectionFrame();
53 };
32 54
33 // Manage password protection pings and verdicts. There is one instance of this 55 // Manage password protection pings and verdicts. There is one instance of this
34 // class per profile. Therefore, every PasswordProtectionService instance is 56 // class per profile. Therefore, every PasswordProtectionService instance is
35 // associated with a unique HistoryService instance and a unique 57 // associated with a unique HistoryService instance and a unique
36 // HostContentSettingsMap instance. 58 // HostContentSettingsMap instance.
37 class PasswordProtectionService : history::HistoryServiceObserver { 59 class PasswordProtectionService : public history::HistoryServiceObserver {
38 public: 60 public:
39 using CheckCsdWhitelistCallback = base::Callback<void(bool)>;
40
41 PasswordProtectionService( 61 PasswordProtectionService(
42 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, 62 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
43 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 63 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
44 history::HistoryService* history_service, 64 history::HistoryService* history_service,
45 HostContentSettingsMap* host_content_settings_map); 65 HostContentSettingsMap* host_content_settings_map);
46 66
47 ~PasswordProtectionService() override; 67 ~PasswordProtectionService() override;
48 68
49 base::WeakPtr<PasswordProtectionService> GetWeakPtr() { 69 base::WeakPtr<PasswordProtectionService> GetWeakPtr() {
50 return weak_factory_.GetWeakPtr(); 70 return weak_factory_.GetWeakPtr();
(...skipping 12 matching lines...) Expand all
63 83
64 // Stores |verdict| in |settings| based on |url|, |verdict| and 84 // Stores |verdict| in |settings| based on |url|, |verdict| and
65 // |receive_time|. 85 // |receive_time|.
66 void CacheVerdict(const GURL& url, 86 void CacheVerdict(const GURL& url,
67 LoginReputationClientResponse* verdict, 87 LoginReputationClientResponse* verdict,
68 const base::Time& receive_time); 88 const base::Time& receive_time);
69 89
70 // Creates an instance of PasswordProtectionRequest and call Start() on that 90 // Creates an instance of PasswordProtectionRequest and call Start() on that
71 // instance. This function also insert this request object in |requests_| for 91 // instance. This function also insert this request object in |requests_| for
72 // record keeping. 92 // record keeping.
73 void StartRequest(const GURL& main_frame_url, 93 void StartRequest(
74 LoginReputationClientRequest::TriggerType type); 94 const GURL& main_frame_url,
95 LoginReputationClientRequest::TriggerType type,
96 std::unique_ptr<PasswordProtectionFrames> pending_password_frames);
97
98 void MaybeStartLowReputationRequest(
99 const GURL& main_frame_url,
100 std::unique_ptr<PasswordProtectionFrames> pending_password_frames);
101
102 scoped_refptr<SafeBrowsingDatabaseManager> database_manager();
Nathan Parker 2017/04/17 20:28:02 nit: const;
Jialiu Lin 2017/04/18 00:58:27 Done.
75 103
76 protected: 104 protected:
77 friend class PasswordProtectionRequest; 105 friend class PasswordProtectionRequest;
78 106
79 // Called by a PasswordProtectionRequest instance when it finishes to remove 107 // Called by a PasswordProtectionRequest instance when it finishes to remove
80 // itself from |requests_|. 108 // itself from |requests_|.
81 virtual void RequestFinished( 109 virtual void RequestFinished(
82 PasswordProtectionRequest* request, 110 PasswordProtectionRequest* request,
83 std::unique_ptr<LoginReputationClientResponse> response); 111 std::unique_ptr<LoginReputationClientResponse> response);
84 112
(...skipping 21 matching lines...) Expand all
106 const GURL& event_url, 134 const GURL& event_url,
107 int event_tab_id, // -1 if tab id is not available. 135 int event_tab_id, // -1 if tab id is not available.
108 LoginReputationClientRequest::Frame* frame) = 0; 136 LoginReputationClientRequest::Frame* frame) = 0;
109 137
110 virtual bool IsExtendedReporting() = 0; 138 virtual bool IsExtendedReporting() = 0;
111 virtual bool IsIncognito() = 0; 139 virtual bool IsIncognito() = 0;
112 140
113 // If we can send ping to Safe Browsing backend. 141 // If we can send ping to Safe Browsing backend.
114 virtual bool IsPingingEnabled() = 0; 142 virtual bool IsPingingEnabled() = 0;
115 143
116 void CheckCsdWhitelistOnIOThread(const GURL& url, 144 void CheckCsdWhitelistOnIOThread(const GURL& url, bool* check_result);
117 const CheckCsdWhitelistCallback& callback);
118 145
119 // Increases "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist" UMA 146 // Increases "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist" UMA
120 // metric based on input. 147 // metric based on input.
121 void OnMatchCsdWhiteListResult(bool match_whitelist); 148 void OnMatchCsdWhiteListResult(const bool* match_whitelist);
122 149
123 private: 150 private:
124 friend class PasswordProtectionServiceTest; 151 friend class PasswordProtectionServiceTest;
152 friend class TestPasswordProtectionService;
125 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, 153 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest,
126 TestParseInvalidVerdictEntry); 154 TestParseInvalidVerdictEntry);
127 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, 155 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest,
128 TestParseValidVerdictEntry); 156 TestParseValidVerdictEntry);
129 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, 157 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest,
130 TestPathVariantsMatchCacheExpression); 158 TestPathVariantsMatchCacheExpression);
131 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, 159 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest,
132 TestCleanUpCachedVerdicts); 160 TestCleanUpCachedVerdicts);
133 161
134 // Overridden from history::HistoryServiceObserver. 162 // Overridden from history::HistoryServiceObserver.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 int stored_verdict_count_; 198 int stored_verdict_count_;
171 199
172 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; 200 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
173 201
174 // The context we use to issue network requests. This request_context_getter 202 // The context we use to issue network requests. This request_context_getter
175 // is obtained from SafeBrowsingService so that we can use the Safe Browsing 203 // is obtained from SafeBrowsingService so that we can use the Safe Browsing
176 // cookie store. 204 // cookie store.
177 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 205 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
178 206
179 // Set of pending PasswordProtectionRequests. 207 // Set of pending PasswordProtectionRequests.
180 std::unordered_set<std::unique_ptr<PasswordProtectionRequest>> requests_; 208 std::set<scoped_refptr<PasswordProtectionRequest>> requests_;
181 209
182 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> 210 ScopedObserver<history::HistoryService, history::HistoryServiceObserver>
183 history_service_observer_; 211 history_service_observer_;
184 212
185 // Content settings map associated with this instance. 213 // Content settings map associated with this instance.
186 HostContentSettingsMap* content_settings_; 214 HostContentSettingsMap* content_settings_;
187 215
216 // Weakptr can only cancel task if it is posted to the same thread. Therefore,
217 // we need CancelableTaskTracker to cancel tasks posted to IO thread.
218 base::CancelableTaskTracker tracker_;
219
188 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; 220 base::WeakPtrFactory<PasswordProtectionService> weak_factory_;
189 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); 221 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService);
190 }; 222 };
191 223
192 } // namespace safe_browsing 224 } // namespace safe_browsing
193 225
194 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_ 226 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698