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 "base/gtest_prod_util.h" | |
| 8 #include "base/macros.h" | 9 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/values.h" | |
| 13 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
| 14 #include "components/history/core/browser/history_service_observer.h" | |
| 15 #include "components/safe_browsing/csd.pb.h" | |
| 16 | |
| 17 namespace history { | |
| 18 class HistoryService; | |
| 19 } | |
| 11 | 20 |
| 12 class GURL; | 21 class GURL; |
| 13 | 22 |
| 14 namespace safe_browsing { | 23 namespace safe_browsing { |
| 15 | 24 |
| 16 class SafeBrowsingDatabaseManager; | 25 class SafeBrowsingDatabaseManager; |
| 17 | 26 |
| 18 class PasswordProtectionService { | 27 class PasswordProtectionService : history::HistoryServiceObserver { |
| 19 public: | 28 public: |
| 20 explicit PasswordProtectionService( | 29 explicit PasswordProtectionService( |
| 21 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager); | 30 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager); |
| 22 | 31 |
| 23 virtual ~PasswordProtectionService(); | 32 ~PasswordProtectionService() override; |
| 24 | 33 |
| 25 // Check if |url| matches CSD whitelist and record UMA metric accordingly. | 34 // Checks if |url| matches CSD whitelist and record UMA metric accordingly. |
| 26 // Currently called by PasswordReuseDetectionManager on UI thread. | 35 // Currently called by PasswordReuseDetectionManager on UI thread. |
| 27 void RecordPasswordReuse(const GURL& url); | 36 void RecordPasswordReuse(const GURL& url); |
| 28 | 37 |
| 29 base::WeakPtr<PasswordProtectionService> GetWeakPtr() { | 38 base::WeakPtr<PasswordProtectionService> GetWeakPtr() { |
| 30 return weak_factory_.GetWeakPtr(); | 39 return weak_factory_.GetWeakPtr(); |
| 31 } | 40 } |
| 32 | 41 |
| 42 // 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.
| |
| 43 // thread. If verdict is not available or is expired, return | |
| 44 // VERDICT_TYPE_UNSPECIFIED. | |
| 45 LoginReputationClientResponse::VerdictType GetCachedVerdict( | |
| 46 HostContentSettingsMap* settings, | |
| 47 const GURL& url); | |
| 48 | |
| 49 // Stores |verdict| in |settings| based on |url|, |verdict| and | |
| 50 // |receive_time|. | |
| 51 void CacheVerdict(HostContentSettingsMap* settings, | |
| 52 const GURL& url, | |
| 53 LoginReputationClientResponse* verdict, | |
| 54 const base::Time& receive_time); | |
| 55 | |
| 33 protected: | 56 protected: |
| 34 // Called on UI thread. | 57 // Called on UI thread. |
| 35 // Increases "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist" UMA | 58 // Increases "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist" UMA |
| 36 // metric based on input. | 59 // metric based on input. |
| 37 void OnMatchCsdWhiteListResult(bool match_whitelist); | 60 void OnMatchCsdWhiteListResult(bool match_whitelist); |
| 38 | 61 |
| 62 // Gets HostContentSettingMap for current active profile; | |
| 63 // TODO(jialiul): make this a pure virtual function when we have a derived | |
| 64 // class ready in chrome/browser/safe_browsing directory. | |
| 65 virtual HostContentSettingsMap* GetSettingMapForActiveProfile(); | |
| 66 | |
| 39 private: | 67 private: |
| 68 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, | |
| 69 TestParseVerdictEntry); | |
| 70 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, | |
| 71 TestUrlMatchCacheExpression); | |
| 72 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, | |
| 73 TestSetGetAndClearCachedVerdict); | |
| 74 // Overridden from history::HistoryServiceObserver. | |
|
lpz
2017/03/15 15:14:58
nit:empty line above?
Jialiu Lin
2017/03/15 17:47:31
Done.
| |
| 75 void OnURLsDeleted(history::HistoryService* history_service, | |
| 76 bool all_history, | |
| 77 bool expired, | |
| 78 const history::URLRows& deleted_rows, | |
| 79 const std::set<GURL>& favicon_urls) override; | |
| 80 | |
| 81 // Posted to UI thread by OnURLsDeleted(..). This function cleans up password | |
| 82 // protection content settings related to deleted URLs. | |
| 83 void RemoveContentSettingsOnURLsDeleted(HostContentSettingsMap* setting_map, | |
| 84 bool all_history, | |
| 85 const history::URLRows& deleted_rows); | |
| 86 | |
| 87 // static | |
|
lpz
2017/03/15 15:14:58
nit: useless comment?
Jialiu Lin
2017/03/15 17:47:31
Done.
| |
| 88 static bool ParseVerdictEntry(base::DictionaryValue* verdict_entry, | |
| 89 int* out_cache_creation_time, | |
| 90 int* out_cache_duration, | |
| 91 int* out_verdict_type); | |
| 92 | |
| 93 static bool UrlMatchCacheExpression(const GURL& url, | |
| 94 const std::string& cache_expression); | |
| 95 | |
| 96 static bool IsCacheExpired(int cache_creation_time, int cache_duration); | |
| 97 | |
| 40 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 98 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 41 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; | 99 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; |
| 42 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); | 100 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); |
| 43 }; | 101 }; |
| 44 | 102 |
| 45 } // namespace safe_browsing | 103 } // namespace safe_browsing |
| 46 | 104 |
| 47 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_ | 105 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_ |
| OLD | NEW |