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

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

Issue 2747313002: PasswordProtectionService verdict cache management (Closed)
Patch Set: comments addressed partially Created 3 years, 9 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 "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
43 // thread. If verdict is not available or is expired, return
44 // VERDICT_TYPE_UNSPECIFIED.
45 LoginReputationClientResponse::VerdictType GetCachedVerdict(
46 const HostContentSettingsMap* settings,
47 const GURL& url);
48
49 // Stores |verdict| in |settings| based on |url|, |verdict| and
50 // |receive_time|.
51 void CacheVerdict(const GURL& url,
52 LoginReputationClientResponse* verdict,
53 const base::Time& receive_time,
54 HostContentSettingsMap* settings);
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 class PasswordProtectionServiceTest;
69 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest,
70 TestParseVerdictEntry);
71 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest,
72 TestUrlMatchCacheExpression);
73 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest,
74 TestSetGetAndClearCachedVerdict);
75
76 // Overridden from history::HistoryServiceObserver.
77 void OnURLsDeleted(history::HistoryService* history_service,
78 bool all_history,
79 bool expired,
80 const history::URLRows& deleted_rows,
81 const std::set<GURL>& favicon_urls) override;
82
83 // Posted to UI thread by OnURLsDeleted(..). This function cleans up password
84 // protection content settings related to deleted URLs.
85 void RemoveContentSettingsOnURLsDeleted(bool all_history,
86 const history::URLRows& deleted_rows,
87 HostContentSettingsMap* setting_map);
88
89 static bool ParseVerdictEntry(const base::DictionaryValue* verdict_entry,
90 int* out_cache_creation_time,
91 int* out_cache_duration,
92 int* out_verdict_type);
93
94 static bool HostPathVariantsMatchCacheExpression(
95 const std::vector<std::string>& hosts,
96 const std::vector<std::string>& paths,
97 const base::StringPiece& cache_expression);
98
99 static bool IsCacheExpired(int cache_creation_time, int cache_duration);
100
40 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; 101 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
41 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; 102 base::WeakPtrFactory<PasswordProtectionService> weak_factory_;
42 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); 103 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService);
43 }; 104 };
44 105
45 } // namespace safe_browsing 106 } // namespace safe_browsing
46 107
47 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_ 108 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698