Chromium Code Reviews| Index: components/safe_browsing/password_protection/password_protection_service.h |
| diff --git a/components/safe_browsing/password_protection/password_protection_service.h b/components/safe_browsing/password_protection/password_protection_service.h |
| index 32afe41496bd87c0877097a0864b2de69bda2a85..8becb3b594b828d1c1d040b4d753aa895b8a0f66 100644 |
| --- a/components/safe_browsing/password_protection/password_protection_service.h |
| +++ b/components/safe_browsing/password_protection/password_protection_service.h |
| @@ -5,9 +5,18 @@ |
| #ifndef COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERVICE_H_ |
| #define COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERVICE_H_ |
| +#include "base/gtest_prod_util.h" |
| #include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/weak_ptr.h" |
| +#include "base/values.h" |
| +#include "components/content_settings/core/browser/host_content_settings_map.h" |
| +#include "components/history/core/browser/history_service_observer.h" |
| +#include "components/safe_browsing/csd.pb.h" |
| + |
| +namespace history { |
| +class HistoryService; |
| +} |
| class GURL; |
| @@ -15,14 +24,14 @@ namespace safe_browsing { |
| class SafeBrowsingDatabaseManager; |
| -class PasswordProtectionService { |
| +class PasswordProtectionService : history::HistoryServiceObserver { |
| public: |
| explicit PasswordProtectionService( |
| const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager); |
| - virtual ~PasswordProtectionService(); |
| + ~PasswordProtectionService() override; |
| - // Check if |url| matches CSD whitelist and record UMA metric accordingly. |
| + // Checks if |url| matches CSD whitelist and record UMA metric accordingly. |
| // Currently called by PasswordReuseDetectionManager on UI thread. |
| void RecordPasswordReuse(const GURL& url); |
| @@ -30,13 +39,62 @@ class PasswordProtectionService { |
| return weak_factory_.GetWeakPtr(); |
| } |
| + // Looks up |settings, and returns the verdict of |url|. Can be called on any |
|
lpz
2017/03/15 15:14:58
nit: trailing | on settings
Jialiu Lin
2017/03/15 17:47:31
Done.
|
| + // thread. If verdict is not available or is expired, return |
| + // VERDICT_TYPE_UNSPECIFIED. |
| + LoginReputationClientResponse::VerdictType GetCachedVerdict( |
| + HostContentSettingsMap* settings, |
| + const GURL& url); |
| + |
| + // Stores |verdict| in |settings| based on |url|, |verdict| and |
| + // |receive_time|. |
| + void CacheVerdict(HostContentSettingsMap* settings, |
| + const GURL& url, |
| + LoginReputationClientResponse* verdict, |
| + const base::Time& receive_time); |
| + |
| protected: |
| // Called on UI thread. |
| // Increases "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist" UMA |
| // metric based on input. |
| void OnMatchCsdWhiteListResult(bool match_whitelist); |
| + // Gets HostContentSettingMap for current active profile; |
| + // TODO(jialiul): make this a pure virtual function when we have a derived |
| + // class ready in chrome/browser/safe_browsing directory. |
| + virtual HostContentSettingsMap* GetSettingMapForActiveProfile(); |
| + |
| private: |
| + FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, |
| + TestParseVerdictEntry); |
| + FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, |
| + TestUrlMatchCacheExpression); |
| + FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, |
| + TestSetGetAndClearCachedVerdict); |
| + // Overridden from history::HistoryServiceObserver. |
|
lpz
2017/03/15 15:14:58
nit:empty line above?
Jialiu Lin
2017/03/15 17:47:31
Done.
|
| + void OnURLsDeleted(history::HistoryService* history_service, |
| + bool all_history, |
| + bool expired, |
| + const history::URLRows& deleted_rows, |
| + const std::set<GURL>& favicon_urls) override; |
| + |
| + // Posted to UI thread by OnURLsDeleted(..). This function cleans up password |
| + // protection content settings related to deleted URLs. |
| + void RemoveContentSettingsOnURLsDeleted(HostContentSettingsMap* setting_map, |
| + bool all_history, |
| + const history::URLRows& deleted_rows); |
| + |
| + // static |
|
lpz
2017/03/15 15:14:58
nit: useless comment?
Jialiu Lin
2017/03/15 17:47:31
Done.
|
| + static bool ParseVerdictEntry(base::DictionaryValue* verdict_entry, |
| + int* out_cache_creation_time, |
| + int* out_cache_duration, |
| + int* out_verdict_type); |
| + |
| + static bool UrlMatchCacheExpression(const GURL& url, |
| + const std::string& cache_expression); |
| + |
| + static bool IsCacheExpired(int cache_creation_time, int cache_duration); |
| + |
| scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| base::WeakPtrFactory<PasswordProtectionService> weak_factory_; |
| DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); |