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

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

Issue 2747313002: PasswordProtectionService verdict cache management (Closed)
Patch Set: Cache verdict based on hostname 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 TestParseInvalidVerdictEntry);
71 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest,
72 TestParseValidVerdictEntry);
73 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest,
74 TestPathVariantsMatchCacheExpression);
75 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest,
76 TestPathMatchCacheExpressionExactly);
77 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest,
78 TestCleanUpCachedVerdicts);
79
80 // Overridden from history::HistoryServiceObserver.
81 void OnURLsDeleted(history::HistoryService* history_service,
82 bool all_history,
83 bool expired,
84 const history::URLRows& deleted_rows,
85 const std::set<GURL>& favicon_urls) override;
86
87 // Posted to UI thread by OnURLsDeleted(..). This function cleans up password
88 // protection content settings related to deleted URLs.
89 void RemoveContentSettingsOnURLsDeleted(bool all_history,
90 const history::URLRows& deleted_rows,
91 HostContentSettingsMap* setting_map);
92
93 static bool ParseVerdictEntry(base::DictionaryValue* verdict_entry,
94 int* out_verdict_received_time,
95 LoginReputationClientResponse* out_verdict);
96
97 static bool PathMatchCacheExpressionExactly(
98 const std::vector<std::string>& generated_paths,
99 const std::string& cache_expression_path);
100
101 static bool PathVariantsMatchCacheExpression(
102 const std::vector<std::string>& generated_paths,
103 const std::string& cache_expression_path);
104
105 static bool IsCacheExpired(int cache_creation_time, int cache_duration);
106
107 static void GeneratePathVariantsWithoutQuery(const GURL& url,
108 std::vector<std::string>* paths);
109
110 static std::string GetCacheExpressionPath(
111 const std::string& cache_expression);
112
113 static std::unique_ptr<base::DictionaryValue> CreateDictionaryFromVerdict(
114 const LoginReputationClientResponse* verdict,
115 const base::Time& receive_time);
116
40 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; 117 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
41 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; 118 base::WeakPtrFactory<PasswordProtectionService> weak_factory_;
42 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); 119 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService);
43 }; 120 };
44 121
45 } // namespace safe_browsing 122 } // namespace safe_browsing
46 123
47 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_ 124 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698