| 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 <unordered_set> |
| 9 |
| 10 #include "base/callback.h" |
| 8 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 9 #include "base/macros.h" | 12 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 12 #include "base/values.h" | 15 #include "base/values.h" |
| 13 #include "components/content_settings/core/browser/host_content_settings_map.h" | 16 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 14 #include "components/history/core/browser/history_service_observer.h" | 17 #include "components/history/core/browser/history_service_observer.h" |
| 15 #include "components/safe_browsing/csd.pb.h" | 18 #include "components/safe_browsing/csd.pb.h" |
| 19 #include "net/url_request/url_request_context_getter.h" |
| 16 | 20 |
| 17 namespace history { | 21 namespace history { |
| 18 class HistoryService; | 22 class HistoryService; |
| 19 } | 23 } |
| 20 | 24 |
| 21 class GURL; | 25 class GURL; |
| 22 | 26 |
| 23 namespace safe_browsing { | 27 namespace safe_browsing { |
| 24 | 28 |
| 25 class SafeBrowsingDatabaseManager; | 29 class SafeBrowsingDatabaseManager; |
| 30 class PasswordProtectionRequest; |
| 26 | 31 |
| 27 class PasswordProtectionService : history::HistoryServiceObserver { | 32 class PasswordProtectionService : history::HistoryServiceObserver { |
| 28 public: | 33 public: |
| 29 explicit PasswordProtectionService( | 34 using CheckCsdWhitelistCallback = base::Callback<void(bool)>; |
| 30 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager); | 35 |
| 36 PasswordProtectionService( |
| 37 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, |
| 38 scoped_refptr<net::URLRequestContextGetter> request_context_getter); |
| 31 | 39 |
| 32 ~PasswordProtectionService() override; | 40 ~PasswordProtectionService() override; |
| 33 | 41 |
| 34 // Checks if |url| matches CSD whitelist and record UMA metric accordingly. | 42 // Checks if |url| matches CSD whitelist and record UMA metric accordingly. |
| 35 // Currently called by PasswordReuseDetectionManager on UI thread. | 43 // Currently called by PasswordReuseDetectionManager on UI thread. |
| 36 void RecordPasswordReuse(const GURL& url); | 44 void RecordPasswordReuse(const GURL& url); |
| 37 | 45 |
| 46 void CheckCsdWhitelistOnIOThread(const GURL& url, |
| 47 const CheckCsdWhitelistCallback& callback); |
| 48 |
| 38 base::WeakPtr<PasswordProtectionService> GetWeakPtr() { | 49 base::WeakPtr<PasswordProtectionService> GetWeakPtr() { |
| 39 return weak_factory_.GetWeakPtr(); | 50 return weak_factory_.GetWeakPtr(); |
| 40 } | 51 } |
| 41 | 52 |
| 42 // Looks up |settings|, and returns the verdict of |url|. Can be called on any | 53 // Looks up |settings| to find the cached verdict response. If verdict is not |
| 43 // thread. If verdict is not available or is expired, return | 54 // available or is expired, return VERDICT_TYPE_UNSPECIFIED. Can be called on |
| 44 // VERDICT_TYPE_UNSPECIFIED. | 55 // any thread. |
| 45 LoginReputationClientResponse::VerdictType GetCachedVerdict( | 56 LoginReputationClientResponse::VerdictType GetCachedVerdict( |
| 46 const HostContentSettingsMap* settings, | 57 const HostContentSettingsMap* settings, |
| 47 const GURL& url); | 58 const GURL& url, |
| 59 LoginReputationClientResponse* out_response); |
| 48 | 60 |
| 49 // Stores |verdict| in |settings| based on |url|, |verdict| and | 61 // Stores |verdict| in |settings| based on |url|, |verdict| and |
| 50 // |receive_time|. | 62 // |receive_time|. |
| 51 void CacheVerdict(const GURL& url, | 63 void CacheVerdict(const GURL& url, |
| 52 LoginReputationClientResponse* verdict, | 64 LoginReputationClientResponse* verdict, |
| 53 const base::Time& receive_time, | 65 const base::Time& receive_time, |
| 54 HostContentSettingsMap* settings); | 66 HostContentSettingsMap* settings); |
| 55 | 67 |
| 68 // Creates an instance of PasswordProtectionRequest and call Start() on that |
| 69 // instance. This function also insert this request object in |requests_| for |
| 70 // record keeping. |
| 71 void StartRequest(const GURL& main_frame_url, |
| 72 LoginReputationClientRequest::TriggerType type, |
| 73 bool is_extended_reporting, |
| 74 bool is_incognito); |
| 75 |
| 76 // Called by a PasswordProtectionRequest instance when it finishes to remove |
| 77 // itself from |requests_|. |
| 78 virtual void RequestFinished( |
| 79 PasswordProtectionRequest* request, |
| 80 std::unique_ptr<LoginReputationClientResponse> response); |
| 81 |
| 82 // Cancels all requests in |requests_|, empties it, and releases references to |
| 83 // the requests. |
| 84 void CancelPendingRequests(); |
| 85 |
| 86 // Gets the total number of verdict (no matter expired or not) we cached for |
| 87 // current active profile. |
| 88 virtual size_t GetStoredVerdictCount(); |
| 89 |
| 90 scoped_refptr<net::URLRequestContextGetter> request_context_getter() { |
| 91 return request_context_getter_; |
| 92 } |
| 93 |
| 94 // Returns the URL where PasswordProtectionRequest instances send requests. |
| 95 static GURL GetPasswordProtectionRequestUrl(); |
| 96 |
| 97 // Gets the request timeout in milliseconds. |
| 98 static int GetRequestTimeoutInMS(); |
| 99 |
| 56 protected: | 100 protected: |
| 57 // Called on UI thread. | 101 friend class PasswordProtectionRequest; |
| 102 |
| 58 // Increases "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist" UMA | 103 // Increases "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist" UMA |
| 59 // metric based on input. | 104 // metric based on input. |
| 60 void OnMatchCsdWhiteListResult(bool match_whitelist); | 105 void OnMatchCsdWhiteListResult(bool match_whitelist); |
| 61 | 106 |
| 62 // Gets HostContentSettingMap for current active profile; | 107 // Gets HostContentSettingMap for current active profile; |
| 63 // TODO(jialiul): make this a pure virtual function when we have a derived | 108 // TODO(jialiul): make this a pure virtual function when we have a derived |
| 64 // class ready in chrome/browser/safe_browsing directory. | 109 // class ready in chrome/browser/safe_browsing directory. |
| 65 virtual HostContentSettingsMap* GetSettingMapForActiveProfile(); | 110 virtual HostContentSettingsMap* GetSettingMapForActiveProfile(); |
| 66 | 111 |
| 67 private: | 112 private: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 static void GeneratePathVariantsWithoutQuery(const GURL& url, | 152 static void GeneratePathVariantsWithoutQuery(const GURL& url, |
| 108 std::vector<std::string>* paths); | 153 std::vector<std::string>* paths); |
| 109 | 154 |
| 110 static std::string GetCacheExpressionPath( | 155 static std::string GetCacheExpressionPath( |
| 111 const std::string& cache_expression); | 156 const std::string& cache_expression); |
| 112 | 157 |
| 113 static std::unique_ptr<base::DictionaryValue> CreateDictionaryFromVerdict( | 158 static std::unique_ptr<base::DictionaryValue> CreateDictionaryFromVerdict( |
| 114 const LoginReputationClientResponse* verdict, | 159 const LoginReputationClientResponse* verdict, |
| 115 const base::Time& receive_time); | 160 const base::Time& receive_time); |
| 116 | 161 |
| 162 // Stored verdict count for each HostContentSettingsMap. |
| 163 std::unordered_map<HostContentSettingsMap*, size_t> stored_verdict_counts_; |
| 164 |
| 165 // The context we use to issue network requests. This request_context_getter |
| 166 // is obtained from SafeBrowsingService so that we can use the Safe Browsing |
| 167 // cookie store. |
| 168 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 169 |
| 170 // Set of pending PasswordProtectionRequests. |
| 171 std::unordered_set<std::unique_ptr<PasswordProtectionRequest>> requests_; |
| 172 |
| 117 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 173 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 118 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; | 174 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; |
| 119 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); | 175 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); |
| 120 }; | 176 }; |
| 121 | 177 |
| 122 } // namespace safe_browsing | 178 } // namespace safe_browsing |
| 123 | 179 |
| 124 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV
ICE_H_ | 180 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV
ICE_H_ |
| OLD | NEW |