Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 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 |type|, |url|, |verdict| and |
| 93 // |receive_time|. | 95 // |receive_time|. |
| 94 virtual void CacheVerdict(const GURL& url, | 96 virtual void CacheVerdict(const GURL& url, |
| 97 TriggerType 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 type); |
|
lpz
2017/06/08 15:18:33
nit: type -> trigger_type or verdict_type or reque
Jialiu Lin
2017/06/08 20:47:30
Done.
| |
| 110 | 113 |
| 111 virtual void MaybeStartPasswordFieldOnFocusRequest( | 114 virtual void MaybeStartPasswordFieldOnFocusRequest( |
| 112 content::WebContents* web_contents, | 115 content::WebContents* web_contents, |
| 113 const GURL& main_frame_url, | 116 const GURL& main_frame_url, |
| 114 const GURL& password_form_action, | 117 const GURL& password_form_action, |
| 115 const GURL& password_form_frame_url); | 118 const GURL& password_form_frame_url); |
| 116 | 119 |
| 117 virtual void MaybeStartProtectedPasswordEntryRequest( | 120 virtual void MaybeStartProtectedPasswordEntryRequest( |
| 118 content::WebContents* web_contents, | 121 content::WebContents* web_contents, |
| 119 const GURL& main_frame_url, | 122 const GURL& main_frame_url, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 143 // itself from |requests_|. | 146 // itself from |requests_|. |
| 144 virtual void RequestFinished( | 147 virtual void RequestFinished( |
| 145 PasswordProtectionRequest* request, | 148 PasswordProtectionRequest* request, |
| 146 bool already_cached, | 149 bool already_cached, |
| 147 std::unique_ptr<LoginReputationClientResponse> response); | 150 std::unique_ptr<LoginReputationClientResponse> response); |
| 148 | 151 |
| 149 // Cancels all requests in |requests_|, empties it, and releases references to | 152 // Cancels all requests in |requests_|, empties it, and releases references to |
| 150 // the requests. | 153 // the requests. |
| 151 void CancelPendingRequests(); | 154 void CancelPendingRequests(); |
| 152 | 155 |
| 153 // Gets the total number of verdict (no matter expired or not) we cached for | 156 // Gets the total number of verdicts of the specified |type| (no matter |
|
lpz
2017/06/08 15:18:33
nit: i find the wording a bit awkward, consider:
Jialiu Lin
2017/06/08 20:47:30
Done.
| |
| 154 // current active profile. | 157 // expired or not) we cached for current active profile. |
| 155 virtual int GetStoredVerdictCount(); | 158 virtual int GetStoredVerdictCount(TriggerType type); |
| 156 | 159 |
| 157 scoped_refptr<net::URLRequestContextGetter> request_context_getter() { | 160 scoped_refptr<net::URLRequestContextGetter> request_context_getter() { |
| 158 return request_context_getter_; | 161 return request_context_getter_; |
| 159 } | 162 } |
| 160 | 163 |
| 161 // Returns the URL where PasswordProtectionRequest instances send requests. | 164 // Returns the URL where PasswordProtectionRequest instances send requests. |
| 162 static GURL GetPasswordProtectionRequestUrl(); | 165 static GURL GetPasswordProtectionRequestUrl(); |
| 163 | 166 |
| 164 // Gets the request timeout in milliseconds. | 167 // Gets the request timeout in milliseconds. |
| 165 static int GetRequestTimeoutInMS(); | 168 static int GetRequestTimeoutInMS(); |
| 166 | 169 |
| 167 // Obtains referrer chain of |event_url| and |event_tab_id| and adds this | 170 // Obtains referrer chain of |event_url| and |event_tab_id| and adds this |
| 168 // info into |frame|. | 171 // info into |frame|. |
| 169 virtual void FillReferrerChain( | 172 virtual void FillReferrerChain( |
| 170 const GURL& event_url, | 173 const GURL& event_url, |
| 171 int event_tab_id, // -1 if tab id is not available. | 174 int event_tab_id, // -1 if tab id is not available. |
| 172 LoginReputationClientRequest::Frame* frame) = 0; | 175 LoginReputationClientRequest::Frame* frame) = 0; |
| 173 | 176 |
| 174 void FillUserPopulation( | 177 void FillUserPopulation(TriggerType request_type, |
| 175 const LoginReputationClientRequest::TriggerType& request_type, | 178 LoginReputationClientRequest* request_proto); |
| 176 LoginReputationClientRequest* request_proto); | |
| 177 | 179 |
| 178 virtual bool IsExtendedReporting() = 0; | 180 virtual bool IsExtendedReporting() = 0; |
| 179 | 181 |
| 180 virtual bool IsIncognito() = 0; | 182 virtual bool IsIncognito() = 0; |
| 181 | 183 |
| 182 virtual bool IsPingingEnabled(const base::Feature& feature, | 184 virtual bool IsPingingEnabled(const base::Feature& feature, |
| 183 RequestOutcome* reason) = 0; | 185 RequestOutcome* reason) = 0; |
| 184 | 186 |
| 185 virtual bool IsHistorySyncEnabled() = 0; | 187 virtual bool IsHistorySyncEnabled() = 0; |
| 186 | 188 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 214 const std::set<GURL>& favicon_urls) override; | 216 const std::set<GURL>& favicon_urls) override; |
| 215 | 217 |
| 216 void HistoryServiceBeingDeleted( | 218 void HistoryServiceBeingDeleted( |
| 217 history::HistoryService* history_service) override; | 219 history::HistoryService* history_service) override; |
| 218 | 220 |
| 219 // Posted to UI thread by OnURLsDeleted(..). This function cleans up password | 221 // Posted to UI thread by OnURLsDeleted(..). This function cleans up password |
| 220 // protection content settings related to deleted URLs. | 222 // protection content settings related to deleted URLs. |
| 221 void RemoveContentSettingsOnURLsDeleted(bool all_history, | 223 void RemoveContentSettingsOnURLsDeleted(bool all_history, |
| 222 const history::URLRows& deleted_rows); | 224 const history::URLRows& deleted_rows); |
| 223 | 225 |
| 226 // Helper function called by RemoveContentSettingsOnURLsDeleted(..). It | |
| 227 // calculate the number of verdicts of |type| that associate with |url|. | |
| 228 int GetVerdictCountForURL(const GURL& url, TriggerType type); | |
| 229 | |
| 230 // Remove verdict of |type| from |cache_dict|. Return false if no verdict | |
| 231 // removed, true otherwise. | |
| 232 bool RemoveExpiredVerdicts(TriggerType type, | |
| 233 base::DictionaryValue* cache_dict); | |
| 234 | |
| 224 static bool ParseVerdictEntry(base::DictionaryValue* verdict_entry, | 235 static bool ParseVerdictEntry(base::DictionaryValue* verdict_entry, |
| 225 int* out_verdict_received_time, | 236 int* out_verdict_received_time, |
| 226 LoginReputationClientResponse* out_verdict); | 237 LoginReputationClientResponse* out_verdict); |
| 227 | 238 |
| 228 static bool PathVariantsMatchCacheExpression( | 239 static bool PathVariantsMatchCacheExpression( |
| 229 const std::vector<std::string>& generated_paths, | 240 const std::vector<std::string>& generated_paths, |
| 230 const std::string& cache_expression_path); | 241 const std::string& cache_expression_path); |
| 231 | 242 |
| 232 static bool IsCacheExpired(int cache_creation_time, int cache_duration); | 243 static bool IsCacheExpired(int cache_creation_time, int cache_duration); |
| 233 | 244 |
| 234 static void GeneratePathVariantsWithoutQuery(const GURL& url, | 245 static void GeneratePathVariantsWithoutQuery(const GURL& url, |
| 235 std::vector<std::string>* paths); | 246 std::vector<std::string>* paths); |
| 236 | 247 |
| 237 static std::string GetCacheExpressionPath( | 248 static std::string GetCacheExpressionPath( |
| 238 const std::string& cache_expression); | 249 const std::string& cache_expression); |
| 239 | 250 |
| 240 static std::unique_ptr<base::DictionaryValue> CreateDictionaryFromVerdict( | 251 static std::unique_ptr<base::DictionaryValue> CreateDictionaryFromVerdict( |
| 241 const LoginReputationClientResponse* verdict, | 252 const LoginReputationClientResponse* verdict, |
| 242 const base::Time& receive_time); | 253 const base::Time& receive_time); |
| 243 | 254 |
| 244 static void RecordNoPingingReason(const base::Feature& feature, | 255 static void RecordNoPingingReason(const base::Feature& feature, |
| 245 RequestOutcome reason); | 256 RequestOutcome reason); |
| 246 // Number of verdict stored for this profile. | 257 // Number of verdict stored for this profile for password on focus pings. |
| 247 int stored_verdict_count_; | 258 int stored_verdict_count_password_on_focus_; |
| 259 | |
| 260 // Number of verdict stored for this profile for protected password entry | |
| 261 // pings. | |
| 262 int stored_verdict_count_password_entry_; | |
|
lpz
2017/06/08 15:18:33
do you foresee having other verdict types that wil
Jialiu Lin
2017/06/08 20:47:30
Acknowledged.
No, these are the only two pings.
| |
| 248 | 263 |
| 249 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 264 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 250 | 265 |
| 251 // The context we use to issue network requests. This request_context_getter | 266 // The context we use to issue network requests. This request_context_getter |
| 252 // is obtained from SafeBrowsingService so that we can use the Safe Browsing | 267 // is obtained from SafeBrowsingService so that we can use the Safe Browsing |
| 253 // cookie store. | 268 // cookie store. |
| 254 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 269 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 255 | 270 |
| 256 // Set of pending PasswordProtectionRequests. | 271 // Set of pending PasswordProtectionRequests. |
| 257 std::set<scoped_refptr<PasswordProtectionRequest>> requests_; | 272 std::set<scoped_refptr<PasswordProtectionRequest>> requests_; |
| 258 | 273 |
| 259 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | 274 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
| 260 history_service_observer_; | 275 history_service_observer_; |
| 261 | 276 |
| 262 // Content settings map associated with this instance. | 277 // Content settings map associated with this instance. |
| 263 HostContentSettingsMap* content_settings_; | 278 HostContentSettingsMap* content_settings_; |
| 264 | 279 |
| 265 // Weakptr can only cancel task if it is posted to the same thread. Therefore, | 280 // Weakptr can only cancel task if it is posted to the same thread. Therefore, |
| 266 // we need CancelableTaskTracker to cancel tasks posted to IO thread. | 281 // we need CancelableTaskTracker to cancel tasks posted to IO thread. |
| 267 base::CancelableTaskTracker tracker_; | 282 base::CancelableTaskTracker tracker_; |
| 268 | 283 |
| 269 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; | 284 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; |
| 270 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); | 285 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); |
| 271 }; | 286 }; |
| 272 | 287 |
| 273 } // namespace safe_browsing | 288 } // namespace safe_browsing |
| 274 | 289 |
| 275 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_ | 290 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_ |
| OLD | NEW |