| 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 21 matching lines...) Expand all Loading... |
| 32 class GURL; | 32 class GURL; |
| 33 class HostContentSettingsMap; | 33 class HostContentSettingsMap; |
| 34 | 34 |
| 35 namespace safe_browsing { | 35 namespace safe_browsing { |
| 36 | 36 |
| 37 class SafeBrowsingDatabaseManager; | 37 class SafeBrowsingDatabaseManager; |
| 38 class PasswordProtectionRequest; | 38 class PasswordProtectionRequest; |
| 39 | 39 |
| 40 extern const base::Feature kPasswordFieldOnFocusPinging; | 40 extern const base::Feature kPasswordFieldOnFocusPinging; |
| 41 extern const base::Feature kProtectedPasswordEntryPinging; | 41 extern const base::Feature kProtectedPasswordEntryPinging; |
| 42 extern const base::Feature kPasswordProtectionInterstitial; |
| 42 extern const char kPasswordOnFocusRequestOutcomeHistogramName[]; | 43 extern const char kPasswordOnFocusRequestOutcomeHistogramName[]; |
| 43 extern const char kPasswordEntryRequestOutcomeHistogramName[]; | 44 extern const char kPasswordEntryRequestOutcomeHistogramName[]; |
| 44 | 45 |
| 45 // 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 |
| 46 // class per profile. Therefore, every PasswordProtectionService instance is | 47 // class per profile. Therefore, every PasswordProtectionService instance is |
| 47 // associated with a unique HistoryService instance and a unique | 48 // associated with a unique HistoryService instance and a unique |
| 48 // HostContentSettingsMap instance. | 49 // HostContentSettingsMap instance. |
| 49 class PasswordProtectionService : public history::HistoryServiceObserver { | 50 class PasswordProtectionService : public history::HistoryServiceObserver { |
| 50 public: | 51 public: |
| 51 // The outcome of the request. These values are used for UMA. | 52 // The outcome of the request. These values are used for UMA. |
| 52 // DO NOT CHANGE THE ORDERING OF THESE VALUES. | 53 // DO NOT CHANGE THE ORDERING OF THESE VALUES. |
| 53 enum RequestOutcome { | 54 enum RequestOutcome { |
| 54 UNKNOWN = 0, | 55 UNKNOWN = 0, |
| 55 SUCCEEDED = 1, | 56 SUCCEEDED = 1, |
| 56 CANCELED = 2, | 57 CANCELED = 2, |
| 57 TIMEDOUT = 3, | 58 TIMEDOUT = 3, |
| 58 MATCHED_WHITELIST = 4, | 59 MATCHED_WHITELIST = 4, |
| 59 RESPONSE_ALREADY_CACHED = 5, | 60 RESPONSE_ALREADY_CACHED = 5, |
| 60 DEPRECATED_NO_EXTENDED_REPORTING = 6, | 61 DEPRECATED_NO_EXTENDED_REPORTING = 6, |
| 61 DISABLED_DUE_TO_INCOGNITO = 7, | 62 DISABLED_DUE_TO_INCOGNITO = 7, |
| 62 REQUEST_MALFORMED = 8, | 63 REQUEST_MALFORMED = 8, |
| 63 FETCH_FAILED = 9, | 64 FETCH_FAILED = 9, |
| 64 RESPONSE_MALFORMED = 10, | 65 RESPONSE_MALFORMED = 10, |
| 65 SERVICE_DESTROYED = 11, | 66 SERVICE_DESTROYED = 11, |
| 66 DISABLED_DUE_TO_FEATURE_DISABLED = 12, | 67 DISABLED_DUE_TO_FEATURE_DISABLED = 12, |
| 67 DISABLED_DUE_TO_USER_POPULATION = 13, | 68 DISABLED_DUE_TO_USER_POPULATION = 13, |
| 68 URL_NOT_VALID_FOR_REPUTATION_COMPUTING = 14, | 69 URL_NOT_VALID_FOR_REPUTATION_COMPUTING = 14, |
| 69 MAX_OUTCOME | 70 MAX_OUTCOME |
| 70 }; | 71 }; |
| 72 |
| 71 PasswordProtectionService( | 73 PasswordProtectionService( |
| 72 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, | 74 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, |
| 73 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 75 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 74 history::HistoryService* history_service, | 76 history::HistoryService* history_service, |
| 75 HostContentSettingsMap* host_content_settings_map); | 77 HostContentSettingsMap* host_content_settings_map); |
| 76 | 78 |
| 77 ~PasswordProtectionService() override; | 79 ~PasswordProtectionService() override; |
| 78 | 80 |
| 79 base::WeakPtr<PasswordProtectionService> GetWeakPtr() { | 81 base::WeakPtr<PasswordProtectionService> GetWeakPtr() { |
| 80 return weak_factory_.GetWeakPtr(); | 82 return weak_factory_.GetWeakPtr(); |
| 81 } | 83 } |
| 82 | 84 |
| 83 // Looks up |settings| to find the cached verdict response. If verdict is not | 85 // Looks up |settings| to find the cached verdict response. If verdict is not |
| 84 // available or is expired, return VERDICT_TYPE_UNSPECIFIED. Can be called on | 86 // available or is expired, return VERDICT_TYPE_UNSPECIFIED. Can be called on |
| 85 // any thread. | 87 // any thread. |
| 86 LoginReputationClientResponse::VerdictType GetCachedVerdict( | 88 LoginReputationClientResponse::VerdictType GetCachedVerdict( |
| 87 const GURL& url, | 89 const GURL& url, |
| 88 LoginReputationClientResponse* out_response); | 90 LoginReputationClientResponse* out_response); |
| 89 | 91 |
| 90 // Stores |verdict| in |settings| based on |url|, |verdict| and | 92 // Stores |verdict| in |settings| based on |url|, |verdict| and |
| 91 // |receive_time|. | 93 // |receive_time|. |
| 92 void CacheVerdict(const GURL& url, | 94 virtual void CacheVerdict(const GURL& url, |
| 93 LoginReputationClientResponse* verdict, | 95 LoginReputationClientResponse* verdict, |
| 94 const base::Time& receive_time); | 96 const base::Time& receive_time); |
| 95 | 97 |
| 96 // Removes all the expired verdicts from cache. | 98 // Removes all the expired verdicts from cache. |
| 97 void CleanUpExpiredVerdicts(); | 99 void CleanUpExpiredVerdicts(); |
| 98 | 100 |
| 99 // Creates an instance of PasswordProtectionRequest and call Start() on that | 101 // Creates an instance of PasswordProtectionRequest and call Start() on that |
| 100 // instance. This function also insert this request object in |requests_| for | 102 // instance. This function also insert this request object in |requests_| for |
| 101 // record keeping. | 103 // record keeping. |
| 102 void StartRequest(content::WebContents* web_contents, | 104 void StartRequest(content::WebContents* web_contents, |
| 103 const GURL& main_frame_url, | 105 const GURL& main_frame_url, |
| 104 const GURL& password_form_action, | 106 const GURL& password_form_action, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 134 // Chrome can send password protection ping if it is allowed by Finch config | 136 // Chrome can send password protection ping if it is allowed by Finch config |
| 135 // and if Safe Browsing can compute reputation of |main_frame_url| (e.g. | 137 // and if Safe Browsing can compute reputation of |main_frame_url| (e.g. |
| 136 // Safe Browsing is not able to compute reputation of a private IP or | 138 // Safe Browsing is not able to compute reputation of a private IP or |
| 137 // a local host.) | 139 // a local host.) |
| 138 bool CanSendPing(const base::Feature& feature, const GURL& main_frame_url); | 140 bool CanSendPing(const base::Feature& feature, const GURL& main_frame_url); |
| 139 | 141 |
| 140 // Called by a PasswordProtectionRequest instance when it finishes to remove | 142 // Called by a PasswordProtectionRequest instance when it finishes to remove |
| 141 // itself from |requests_|. | 143 // itself from |requests_|. |
| 142 virtual void RequestFinished( | 144 virtual void RequestFinished( |
| 143 PasswordProtectionRequest* request, | 145 PasswordProtectionRequest* request, |
| 146 bool already_cached, |
| 144 std::unique_ptr<LoginReputationClientResponse> response); | 147 std::unique_ptr<LoginReputationClientResponse> response); |
| 145 | 148 |
| 146 // Cancels all requests in |requests_|, empties it, and releases references to | 149 // Cancels all requests in |requests_|, empties it, and releases references to |
| 147 // the requests. | 150 // the requests. |
| 148 void CancelPendingRequests(); | 151 void CancelPendingRequests(); |
| 149 | 152 |
| 150 // Gets the total number of verdict (no matter expired or not) we cached for | 153 // Gets the total number of verdict (no matter expired or not) we cached for |
| 151 // current active profile. | 154 // current active profile. |
| 152 virtual int GetStoredVerdictCount(); | 155 virtual int GetStoredVerdictCount(); |
| 153 | 156 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 174 | 177 |
| 175 virtual bool IsExtendedReporting() = 0; | 178 virtual bool IsExtendedReporting() = 0; |
| 176 | 179 |
| 177 virtual bool IsIncognito() = 0; | 180 virtual bool IsIncognito() = 0; |
| 178 | 181 |
| 179 virtual bool IsPingingEnabled(const base::Feature& feature, | 182 virtual bool IsPingingEnabled(const base::Feature& feature, |
| 180 RequestOutcome* reason) = 0; | 183 RequestOutcome* reason) = 0; |
| 181 | 184 |
| 182 virtual bool IsHistorySyncEnabled() = 0; | 185 virtual bool IsHistorySyncEnabled() = 0; |
| 183 | 186 |
| 187 virtual void ShowPhishingInterstitial(const GURL& phishing_url, |
| 188 const std::string& token, |
| 189 content::WebContents* web_contents) = 0; |
| 190 |
| 184 void CheckCsdWhitelistOnIOThread(const GURL& url, bool* check_result); | 191 void CheckCsdWhitelistOnIOThread(const GURL& url, bool* check_result); |
| 185 | 192 |
| 186 HostContentSettingsMap* content_settings() const { return content_settings_; } | 193 HostContentSettingsMap* content_settings() const { return content_settings_; } |
| 187 | 194 |
| 188 private: | 195 private: |
| 189 friend class PasswordProtectionServiceTest; | 196 friend class PasswordProtectionServiceTest; |
| 190 friend class TestPasswordProtectionService; | 197 friend class TestPasswordProtectionService; |
| 191 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, | 198 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, |
| 192 TestParseInvalidVerdictEntry); | 199 TestParseInvalidVerdictEntry); |
| 193 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, | 200 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 // we need CancelableTaskTracker to cancel tasks posted to IO thread. | 266 // we need CancelableTaskTracker to cancel tasks posted to IO thread. |
| 260 base::CancelableTaskTracker tracker_; | 267 base::CancelableTaskTracker tracker_; |
| 261 | 268 |
| 262 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; | 269 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; |
| 263 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); | 270 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); |
| 264 }; | 271 }; |
| 265 | 272 |
| 266 } // namespace safe_browsing | 273 } // namespace safe_browsing |
| 267 | 274 |
| 268 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV
ICE_H_ | 275 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV
ICE_H_ |
| OLD | NEW |