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

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

Issue 2911293003: Reland: Cache protected password entry and password on focus ping separately. (Closed)
Patch Set: Fix Crashes by Using GetDictionaryWithoutPathExpansion Created 3 years, 6 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 <set> 8 #include <set>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 extern const base::Feature kPasswordProtectionInterstitial; 42 extern const base::Feature kPasswordProtectionInterstitial;
43 extern const char kPasswordOnFocusRequestOutcomeHistogramName[]; 43 extern const char kPasswordOnFocusRequestOutcomeHistogramName[];
44 extern const char kPasswordEntryRequestOutcomeHistogramName[]; 44 extern const char kPasswordEntryRequestOutcomeHistogramName[];
45 45
46 // Manage password protection pings and verdicts. There is one instance of this 46 // Manage password protection pings and verdicts. There is one instance of this
47 // class per profile. Therefore, every PasswordProtectionService instance is 47 // class per profile. Therefore, every PasswordProtectionService instance is
48 // associated with a unique HistoryService instance and a unique 48 // associated with a unique HistoryService instance and a unique
49 // HostContentSettingsMap instance. 49 // HostContentSettingsMap instance.
50 class PasswordProtectionService : public history::HistoryServiceObserver { 50 class PasswordProtectionService : public history::HistoryServiceObserver {
51 public: 51 public:
52 using TriggerType = LoginReputationClientRequest::TriggerType;
52 // The outcome of the request. These values are used for UMA. 53 // The outcome of the request. These values are used for UMA.
53 // DO NOT CHANGE THE ORDERING OF THESE VALUES. 54 // DO NOT CHANGE THE ORDERING OF THESE VALUES.
54 enum RequestOutcome { 55 enum RequestOutcome {
55 UNKNOWN = 0, 56 UNKNOWN = 0,
56 SUCCEEDED = 1, 57 SUCCEEDED = 1,
57 CANCELED = 2, 58 CANCELED = 2,
58 TIMEDOUT = 3, 59 TIMEDOUT = 3,
59 MATCHED_WHITELIST = 4, 60 MATCHED_WHITELIST = 4,
60 RESPONSE_ALREADY_CACHED = 5, 61 RESPONSE_ALREADY_CACHED = 5,
61 DEPRECATED_NO_EXTENDED_REPORTING = 6, 62 DEPRECATED_NO_EXTENDED_REPORTING = 6,
(...skipping 18 matching lines...) Expand all
80 81
81 base::WeakPtr<PasswordProtectionService> GetWeakPtr() { 82 base::WeakPtr<PasswordProtectionService> GetWeakPtr() {
82 return weak_factory_.GetWeakPtr(); 83 return weak_factory_.GetWeakPtr();
83 } 84 }
84 85
85 // Looks up |settings| to find the cached verdict response. If verdict is not 86 // Looks up |settings| to find the cached verdict response. If verdict is not
86 // available or is expired, return VERDICT_TYPE_UNSPECIFIED. Can be called on 87 // available or is expired, return VERDICT_TYPE_UNSPECIFIED. Can be called on
87 // any thread. 88 // any thread.
88 LoginReputationClientResponse::VerdictType GetCachedVerdict( 89 LoginReputationClientResponse::VerdictType GetCachedVerdict(
89 const GURL& url, 90 const GURL& url,
91 TriggerType trigger_type,
90 LoginReputationClientResponse* out_response); 92 LoginReputationClientResponse* out_response);
91 93
92 // Stores |verdict| in |settings| based on |url|, |verdict| and 94 // Stores |verdict| in |settings| based on its |trigger_type|, |url|,
93 // |receive_time|. 95 // |verdict| and |receive_time|.
94 virtual void CacheVerdict(const GURL& url, 96 virtual void CacheVerdict(const GURL& url,
97 TriggerType trigger_type,
95 LoginReputationClientResponse* verdict, 98 LoginReputationClientResponse* verdict,
96 const base::Time& receive_time); 99 const base::Time& receive_time);
97 100
98 // Removes all the expired verdicts from cache. 101 // Removes all the expired verdicts from cache.
99 void CleanUpExpiredVerdicts(); 102 void CleanUpExpiredVerdicts();
100 103
101 // Creates an instance of PasswordProtectionRequest and call Start() on that 104 // Creates an instance of PasswordProtectionRequest and call Start() on that
102 // instance. This function also insert this request object in |requests_| for 105 // instance. This function also insert this request object in |requests_| for
103 // record keeping. 106 // record keeping.
104 void StartRequest(content::WebContents* web_contents, 107 void StartRequest(content::WebContents* web_contents,
105 const GURL& main_frame_url, 108 const GURL& main_frame_url,
106 const GURL& password_form_action, 109 const GURL& password_form_action,
107 const GURL& password_form_frame_url, 110 const GURL& password_form_frame_url,
108 const std::string& saved_domain, 111 const std::string& saved_domain,
109 LoginReputationClientRequest::TriggerType type, 112 TriggerType trigger_type,
110 bool password_field_exists); 113 bool password_field_exists);
111 114
112 virtual void MaybeStartPasswordFieldOnFocusRequest( 115 virtual void MaybeStartPasswordFieldOnFocusRequest(
113 content::WebContents* web_contents, 116 content::WebContents* web_contents,
114 const GURL& main_frame_url, 117 const GURL& main_frame_url,
115 const GURL& password_form_action, 118 const GURL& password_form_action,
116 const GURL& password_form_frame_url); 119 const GURL& password_form_frame_url);
117 120
118 virtual void MaybeStartProtectedPasswordEntryRequest( 121 virtual void MaybeStartProtectedPasswordEntryRequest(
119 content::WebContents* web_contents, 122 content::WebContents* web_contents,
(...skipping 25 matching lines...) Expand all
145 // itself from |requests_|. 148 // itself from |requests_|.
146 virtual void RequestFinished( 149 virtual void RequestFinished(
147 PasswordProtectionRequest* request, 150 PasswordProtectionRequest* request,
148 bool already_cached, 151 bool already_cached,
149 std::unique_ptr<LoginReputationClientResponse> response); 152 std::unique_ptr<LoginReputationClientResponse> response);
150 153
151 // Cancels all requests in |requests_|, empties it, and releases references to 154 // Cancels all requests in |requests_|, empties it, and releases references to
152 // the requests. 155 // the requests.
153 void CancelPendingRequests(); 156 void CancelPendingRequests();
154 157
155 // Gets the total number of verdict (no matter expired or not) we cached for 158 // Gets the total number of verdicts of the specified |trigger_type| we cached
156 // current active profile. 159 // for this profile. This counts both expired and active verdicts.
157 virtual int GetStoredVerdictCount(); 160 virtual int GetStoredVerdictCount(TriggerType trigger_type);
158 161
159 scoped_refptr<net::URLRequestContextGetter> request_context_getter() { 162 scoped_refptr<net::URLRequestContextGetter> request_context_getter() {
160 return request_context_getter_; 163 return request_context_getter_;
161 } 164 }
162 165
163 // Returns the URL where PasswordProtectionRequest instances send requests. 166 // Returns the URL where PasswordProtectionRequest instances send requests.
164 static GURL GetPasswordProtectionRequestUrl(); 167 static GURL GetPasswordProtectionRequestUrl();
165 168
166 // Gets the request timeout in milliseconds. 169 // Gets the request timeout in milliseconds.
167 static int GetRequestTimeoutInMS(); 170 static int GetRequestTimeoutInMS();
168 171
169 // Obtains referrer chain of |event_url| and |event_tab_id| and adds this 172 // Obtains referrer chain of |event_url| and |event_tab_id| and adds this
170 // info into |frame|. 173 // info into |frame|.
171 virtual void FillReferrerChain( 174 virtual void FillReferrerChain(
172 const GURL& event_url, 175 const GURL& event_url,
173 int event_tab_id, // -1 if tab id is not available. 176 int event_tab_id, // -1 if tab id is not available.
174 LoginReputationClientRequest::Frame* frame) = 0; 177 LoginReputationClientRequest::Frame* frame) = 0;
175 178
176 void FillUserPopulation( 179 void FillUserPopulation(TriggerType trigger_type,
177 const LoginReputationClientRequest::TriggerType& request_type, 180 LoginReputationClientRequest* request_proto);
178 LoginReputationClientRequest* request_proto);
179 181
180 virtual bool IsExtendedReporting() = 0; 182 virtual bool IsExtendedReporting() = 0;
181 183
182 virtual bool IsIncognito() = 0; 184 virtual bool IsIncognito() = 0;
183 185
184 virtual bool IsPingingEnabled(const base::Feature& feature, 186 virtual bool IsPingingEnabled(const base::Feature& feature,
185 RequestOutcome* reason) = 0; 187 RequestOutcome* reason) = 0;
186 188
187 virtual bool IsHistorySyncEnabled() = 0; 189 virtual bool IsHistorySyncEnabled() = 0;
188 190
(...skipping 27 matching lines...) Expand all
216 const std::set<GURL>& favicon_urls) override; 218 const std::set<GURL>& favicon_urls) override;
217 219
218 void HistoryServiceBeingDeleted( 220 void HistoryServiceBeingDeleted(
219 history::HistoryService* history_service) override; 221 history::HistoryService* history_service) override;
220 222
221 // Posted to UI thread by OnURLsDeleted(..). This function cleans up password 223 // Posted to UI thread by OnURLsDeleted(..). This function cleans up password
222 // protection content settings related to deleted URLs. 224 // protection content settings related to deleted URLs.
223 void RemoveContentSettingsOnURLsDeleted(bool all_history, 225 void RemoveContentSettingsOnURLsDeleted(bool all_history,
224 const history::URLRows& deleted_rows); 226 const history::URLRows& deleted_rows);
225 227
228 // Helper function called by RemoveContentSettingsOnURLsDeleted(..). It
229 // calculate the number of verdicts of |type| that associate with |url|.
230 int GetVerdictCountForURL(const GURL& url, TriggerType type);
231
232 // Remove verdict of |type| from |cache_dictionary|. Return false if no
233 // verdict removed, true otherwise.
234 bool RemoveExpiredVerdicts(TriggerType type,
235 base::DictionaryValue* cache_dictionary);
236
226 static bool ParseVerdictEntry(base::DictionaryValue* verdict_entry, 237 static bool ParseVerdictEntry(base::DictionaryValue* verdict_entry,
227 int* out_verdict_received_time, 238 int* out_verdict_received_time,
228 LoginReputationClientResponse* out_verdict); 239 LoginReputationClientResponse* out_verdict);
229 240
230 static bool PathVariantsMatchCacheExpression( 241 static bool PathVariantsMatchCacheExpression(
231 const std::vector<std::string>& generated_paths, 242 const std::vector<std::string>& generated_paths,
232 const std::string& cache_expression_path); 243 const std::string& cache_expression_path);
233 244
234 static bool IsCacheExpired(int cache_creation_time, int cache_duration); 245 static bool IsCacheExpired(int cache_creation_time, int cache_duration);
235 246
236 static void GeneratePathVariantsWithoutQuery(const GURL& url, 247 static void GeneratePathVariantsWithoutQuery(const GURL& url,
237 std::vector<std::string>* paths); 248 std::vector<std::string>* paths);
238 249
239 static std::string GetCacheExpressionPath( 250 static std::string GetCacheExpressionPath(
240 const std::string& cache_expression); 251 const std::string& cache_expression);
241 252
242 static std::unique_ptr<base::DictionaryValue> CreateDictionaryFromVerdict( 253 static std::unique_ptr<base::DictionaryValue> CreateDictionaryFromVerdict(
243 const LoginReputationClientResponse* verdict, 254 const LoginReputationClientResponse* verdict,
244 const base::Time& receive_time); 255 const base::Time& receive_time);
245 256
246 static void RecordNoPingingReason(const base::Feature& feature, 257 static void RecordNoPingingReason(const base::Feature& feature,
247 RequestOutcome reason); 258 RequestOutcome reason);
248 // Number of verdict stored for this profile. 259 // Number of verdict stored for this profile for password on focus pings.
249 int stored_verdict_count_; 260 int stored_verdict_count_password_on_focus_;
261
262 // Number of verdict stored for this profile for protected password entry
263 // pings.
264 int stored_verdict_count_password_entry_;
250 265
251 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; 266 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
252 267
253 // The context we use to issue network requests. This request_context_getter 268 // The context we use to issue network requests. This request_context_getter
254 // is obtained from SafeBrowsingService so that we can use the Safe Browsing 269 // is obtained from SafeBrowsingService so that we can use the Safe Browsing
255 // cookie store. 270 // cookie store.
256 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 271 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
257 272
258 // Set of pending PasswordProtectionRequests. 273 // Set of pending PasswordProtectionRequests.
259 std::set<scoped_refptr<PasswordProtectionRequest>> requests_; 274 std::set<scoped_refptr<PasswordProtectionRequest>> requests_;
260 275
261 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> 276 ScopedObserver<history::HistoryService, history::HistoryServiceObserver>
262 history_service_observer_; 277 history_service_observer_;
263 278
264 // Content settings map associated with this instance. 279 // Content settings map associated with this instance.
265 HostContentSettingsMap* content_settings_; 280 HostContentSettingsMap* content_settings_;
266 281
267 // Weakptr can only cancel task if it is posted to the same thread. Therefore, 282 // Weakptr can only cancel task if it is posted to the same thread. Therefore,
268 // we need CancelableTaskTracker to cancel tasks posted to IO thread. 283 // we need CancelableTaskTracker to cancel tasks posted to IO thread.
269 base::CancelableTaskTracker tracker_; 284 base::CancelableTaskTracker tracker_;
270 285
271 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; 286 base::WeakPtrFactory<PasswordProtectionService> weak_factory_;
272 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); 287 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService);
273 }; 288 };
274 289
275 } // namespace safe_browsing 290 } // namespace safe_browsing
276 291
277 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_ 292 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698