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 <unordered_set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/scoped_observer.h" | 15 #include "base/scoped_observer.h" |
| 16 #include "base/task/cancelable_task_tracker.h" | |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "components/history/core/browser/history_service_observer.h" | 18 #include "components/history/core/browser/history_service_observer.h" |
| 18 #include "components/safe_browsing/csd.pb.h" | 19 #include "components/safe_browsing/csd.pb.h" |
| 19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 21 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" | |
| 20 | 22 |
| 21 namespace history { | 23 namespace history { |
| 22 class HistoryService; | 24 class HistoryService; |
| 23 } | 25 } |
| 24 | 26 |
| 25 class GURL; | 27 class GURL; |
| 26 class HostContentSettingsMap; | 28 class HostContentSettingsMap; |
| 27 | 29 |
| 28 namespace safe_browsing { | 30 namespace safe_browsing { |
| 29 | 31 |
| 30 class SafeBrowsingDatabaseManager; | 32 class SafeBrowsingDatabaseManager; |
| 31 class PasswordProtectionRequest; | 33 class PasswordProtectionRequest; |
| 32 | 34 |
| 35 using PasswordFormList = google::protobuf::RepeatedPtrField< | |
| 36 LoginReputationClientRequest::Frame::Form>; | |
| 37 | |
| 38 // The PasswordProtectionFrame struct encapsulates information about a render | |
| 39 // frame that has password form(s). | |
| 40 struct PasswordProtectionFrame { | |
| 41 int render_frame_routing_id; | |
| 42 int parent_frame_routing_id; | |
| 43 GURL last_committed_url; | |
| 44 std::unique_ptr<PasswordFormList> password_forms; | |
| 45 | |
| 46 PasswordProtectionFrame() = delete; | |
| 47 | |
| 48 ~PasswordProtectionFrame(); | |
| 49 }; | |
| 50 | |
| 51 using PasswordProtectionFrames = | |
|
lpz
2017/04/18 14:43:27
Perhaps PasswordProtectionFrameList? For a while I
Jialiu Lin
2017/04/18 20:38:04
Sure. Done.
| |
| 52 std::vector<std::unique_ptr<PasswordProtectionFrame>>; | |
| 53 | |
| 33 // Manage password protection pings and verdicts. There is one instance of this | 54 // Manage password protection pings and verdicts. There is one instance of this |
| 34 // class per profile. Therefore, every PasswordProtectionService instance is | 55 // class per profile. Therefore, every PasswordProtectionService instance is |
| 35 // associated with a unique HistoryService instance and a unique | 56 // associated with a unique HistoryService instance and a unique |
| 36 // HostContentSettingsMap instance. | 57 // HostContentSettingsMap instance. |
| 37 class PasswordProtectionService : history::HistoryServiceObserver { | 58 class PasswordProtectionService : public history::HistoryServiceObserver { |
| 38 public: | 59 public: |
| 39 using CheckCsdWhitelistCallback = base::Callback<void(bool)>; | |
| 40 | |
| 41 PasswordProtectionService( | 60 PasswordProtectionService( |
| 42 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, | 61 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, |
| 43 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 62 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 44 history::HistoryService* history_service, | 63 history::HistoryService* history_service, |
| 45 HostContentSettingsMap* host_content_settings_map); | 64 HostContentSettingsMap* host_content_settings_map); |
| 46 | 65 |
| 47 ~PasswordProtectionService() override; | 66 ~PasswordProtectionService() override; |
| 48 | 67 |
| 49 base::WeakPtr<PasswordProtectionService> GetWeakPtr() { | 68 base::WeakPtr<PasswordProtectionService> GetWeakPtr() { |
| 50 return weak_factory_.GetWeakPtr(); | 69 return weak_factory_.GetWeakPtr(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 63 | 82 |
| 64 // Stores |verdict| in |settings| based on |url|, |verdict| and | 83 // Stores |verdict| in |settings| based on |url|, |verdict| and |
| 65 // |receive_time|. | 84 // |receive_time|. |
| 66 void CacheVerdict(const GURL& url, | 85 void CacheVerdict(const GURL& url, |
| 67 LoginReputationClientResponse* verdict, | 86 LoginReputationClientResponse* verdict, |
| 68 const base::Time& receive_time); | 87 const base::Time& receive_time); |
| 69 | 88 |
| 70 // Creates an instance of PasswordProtectionRequest and call Start() on that | 89 // Creates an instance of PasswordProtectionRequest and call Start() on that |
| 71 // instance. This function also insert this request object in |requests_| for | 90 // instance. This function also insert this request object in |requests_| for |
| 72 // record keeping. | 91 // record keeping. |
| 73 void StartRequest(const GURL& main_frame_url, | 92 void StartRequest( |
| 74 LoginReputationClientRequest::TriggerType type); | 93 const GURL& main_frame_url, |
| 94 LoginReputationClientRequest::TriggerType type, | |
| 95 std::unique_ptr<PasswordProtectionFrames> pending_password_frames); | |
| 96 | |
| 97 void MaybeStartLowReputationRequest( | |
| 98 const GURL& main_frame_url, | |
| 99 std::unique_ptr<PasswordProtectionFrames> pending_password_frames); | |
| 100 | |
| 101 const scoped_refptr<SafeBrowsingDatabaseManager> database_manager(); | |
| 75 | 102 |
| 76 protected: | 103 protected: |
| 77 friend class PasswordProtectionRequest; | 104 friend class PasswordProtectionRequest; |
| 78 | 105 |
| 79 // Called by a PasswordProtectionRequest instance when it finishes to remove | 106 // Called by a PasswordProtectionRequest instance when it finishes to remove |
| 80 // itself from |requests_|. | 107 // itself from |requests_|. |
| 81 virtual void RequestFinished( | 108 virtual void RequestFinished( |
| 82 PasswordProtectionRequest* request, | 109 PasswordProtectionRequest* request, |
| 83 std::unique_ptr<LoginReputationClientResponse> response); | 110 std::unique_ptr<LoginReputationClientResponse> response); |
| 84 | 111 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 106 const GURL& event_url, | 133 const GURL& event_url, |
| 107 int event_tab_id, // -1 if tab id is not available. | 134 int event_tab_id, // -1 if tab id is not available. |
| 108 LoginReputationClientRequest::Frame* frame) = 0; | 135 LoginReputationClientRequest::Frame* frame) = 0; |
| 109 | 136 |
| 110 virtual bool IsExtendedReporting() = 0; | 137 virtual bool IsExtendedReporting() = 0; |
| 111 virtual bool IsIncognito() = 0; | 138 virtual bool IsIncognito() = 0; |
| 112 | 139 |
| 113 // If we can send ping to Safe Browsing backend. | 140 // If we can send ping to Safe Browsing backend. |
| 114 virtual bool IsPingingEnabled() = 0; | 141 virtual bool IsPingingEnabled() = 0; |
| 115 | 142 |
| 116 void CheckCsdWhitelistOnIOThread(const GURL& url, | 143 void CheckCsdWhitelistOnIOThread(const GURL& url, bool* check_result); |
| 117 const CheckCsdWhitelistCallback& callback); | |
| 118 | 144 |
| 119 // Increases "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist" UMA | 145 // Increases "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist" UMA |
| 120 // metric based on input. | 146 // metric based on input. |
| 121 void OnMatchCsdWhiteListResult(bool match_whitelist); | 147 void OnMatchCsdWhiteListResult(const bool* match_whitelist); |
| 122 | 148 |
| 123 private: | 149 private: |
| 124 friend class PasswordProtectionServiceTest; | 150 friend class PasswordProtectionServiceTest; |
| 151 friend class TestPasswordProtectionService; | |
| 125 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, | 152 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, |
| 126 TestParseInvalidVerdictEntry); | 153 TestParseInvalidVerdictEntry); |
| 127 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, | 154 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, |
| 128 TestParseValidVerdictEntry); | 155 TestParseValidVerdictEntry); |
| 129 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, | 156 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, |
| 130 TestPathVariantsMatchCacheExpression); | 157 TestPathVariantsMatchCacheExpression); |
| 131 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, | 158 FRIEND_TEST_ALL_PREFIXES(PasswordProtectionServiceTest, |
| 132 TestCleanUpCachedVerdicts); | 159 TestCleanUpCachedVerdicts); |
| 133 | 160 |
| 134 // Overridden from history::HistoryServiceObserver. | 161 // Overridden from history::HistoryServiceObserver. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 int stored_verdict_count_; | 197 int stored_verdict_count_; |
| 171 | 198 |
| 172 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 199 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 173 | 200 |
| 174 // The context we use to issue network requests. This request_context_getter | 201 // The context we use to issue network requests. This request_context_getter |
| 175 // is obtained from SafeBrowsingService so that we can use the Safe Browsing | 202 // is obtained from SafeBrowsingService so that we can use the Safe Browsing |
| 176 // cookie store. | 203 // cookie store. |
| 177 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 204 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 178 | 205 |
| 179 // Set of pending PasswordProtectionRequests. | 206 // Set of pending PasswordProtectionRequests. |
| 180 std::unordered_set<std::unique_ptr<PasswordProtectionRequest>> requests_; | 207 std::set<scoped_refptr<PasswordProtectionRequest>> requests_; |
| 181 | 208 |
| 182 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | 209 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
| 183 history_service_observer_; | 210 history_service_observer_; |
| 184 | 211 |
| 185 // Content settings map associated with this instance. | 212 // Content settings map associated with this instance. |
| 186 HostContentSettingsMap* content_settings_; | 213 HostContentSettingsMap* content_settings_; |
| 187 | 214 |
| 215 // Weakptr can only cancel task if it is posted to the same thread. Therefore, | |
| 216 // we need CancelableTaskTracker to cancel tasks posted to IO thread. | |
| 217 base::CancelableTaskTracker tracker_; | |
| 218 | |
| 188 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; | 219 base::WeakPtrFactory<PasswordProtectionService> weak_factory_; |
| 189 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); | 220 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); |
| 190 }; | 221 }; |
| 191 | 222 |
| 192 } // namespace safe_browsing | 223 } // namespace safe_browsing |
| 193 | 224 |
| 194 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_ | 225 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERV ICE_H_ |
| OLD | NEW |