| 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 #include "components/safe_browsing/password_protection/password_protection_servi
ce.h" | 5 #include "components/safe_browsing/password_protection/password_protection_servi
ce.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 15 #include "components/history/core/browser/history_service.h" |
| 14 #include "components/safe_browsing/password_protection/password_protection_reque
st.h" | 16 #include "components/safe_browsing/password_protection/password_protection_reque
st.h" |
| 15 #include "components/safe_browsing_db/database_manager.h" | 17 #include "components/safe_browsing_db/database_manager.h" |
| 16 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 18 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 #include "google_apis/google_api_keys.h" | 20 #include "google_apis/google_api_keys.h" |
| 19 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
| 20 | 22 |
| 21 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 using history::HistoryService; |
| 22 | 25 |
| 23 namespace safe_browsing { | 26 namespace safe_browsing { |
| 24 | 27 |
| 25 namespace { | 28 namespace { |
| 26 | 29 |
| 27 // Keys for storing password protection verdict into a DictionaryValue. | 30 // Keys for storing password protection verdict into a DictionaryValue. |
| 28 const char kCacheCreationTime[] = "cache_creation_time"; | 31 const char kCacheCreationTime[] = "cache_creation_time"; |
| 29 const char kVerdictProto[] = "verdict_proto"; | 32 const char kVerdictProto[] = "verdict_proto"; |
| 30 const int kRequestTimeoutMs = 10000; | 33 const int kRequestTimeoutMs = 10000; |
| 31 const char kPasswordProtectionRequestUrl[] = | 34 const char kPasswordProtectionRequestUrl[] = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 55 DCHECK(url.SchemeIsHTTPOrHTTPS()); | 58 DCHECK(url.SchemeIsHTTPOrHTTPS()); |
| 56 std::string result(url::kHttpScheme); | 59 std::string result(url::kHttpScheme); |
| 57 result.append(url::kStandardSchemeSeparator).append(url.HostNoBrackets()); | 60 result.append(url::kStandardSchemeSeparator).append(url.HostNoBrackets()); |
| 58 return GURL(result); | 61 return GURL(result); |
| 59 } | 62 } |
| 60 | 63 |
| 61 } // namespace | 64 } // namespace |
| 62 | 65 |
| 63 PasswordProtectionService::PasswordProtectionService( | 66 PasswordProtectionService::PasswordProtectionService( |
| 64 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, | 67 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, |
| 65 scoped_refptr<net::URLRequestContextGetter> request_context_getter) | 68 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 66 : request_context_getter_(request_context_getter), | 69 HistoryService* history_service, |
| 70 HostContentSettingsMap* host_content_settings_map) |
| 71 : stored_verdict_count_(-1), |
| 67 database_manager_(database_manager), | 72 database_manager_(database_manager), |
| 73 request_context_getter_(request_context_getter), |
| 74 history_service_observer_(this), |
| 75 content_settings_(host_content_settings_map), |
| 68 weak_factory_(this) { | 76 weak_factory_(this) { |
| 69 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 77 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 78 if (history_service) |
| 79 history_service_observer_.Add(history_service); |
| 70 } | 80 } |
| 71 | 81 |
| 72 PasswordProtectionService::~PasswordProtectionService() { | 82 PasswordProtectionService::~PasswordProtectionService() { |
| 73 CancelPendingRequests(); | 83 CancelPendingRequests(); |
| 84 history_service_observer_.RemoveAll(); |
| 74 weak_factory_.InvalidateWeakPtrs(); | 85 weak_factory_.InvalidateWeakPtrs(); |
| 75 } | 86 } |
| 76 | 87 |
| 77 void PasswordProtectionService::RecordPasswordReuse(const GURL& url) { | 88 void PasswordProtectionService::RecordPasswordReuse(const GURL& url) { |
| 78 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 89 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 79 DCHECK(database_manager_); | 90 DCHECK(database_manager_); |
| 80 if (!url.is_valid()) | 91 if (!url.is_valid()) |
| 81 return; | 92 return; |
| 82 | 93 |
| 83 BrowserThread::PostTask( | 94 BrowserThread::PostTask( |
| 84 BrowserThread::IO, FROM_HERE, | 95 BrowserThread::IO, FROM_HERE, |
| 85 base::Bind( | 96 base::Bind( |
| 86 &PasswordProtectionService::CheckCsdWhitelistOnIOThread, GetWeakPtr(), | 97 &PasswordProtectionService::CheckCsdWhitelistOnIOThread, GetWeakPtr(), |
| 87 url, | 98 url, |
| 88 base::Bind(&PasswordProtectionService::OnMatchCsdWhiteListResult, | 99 base::Bind(&PasswordProtectionService::OnMatchCsdWhiteListResult, |
| 89 GetWeakPtr()))); | 100 base::Unretained(this)))); |
| 90 } | 101 } |
| 91 | 102 |
| 92 void PasswordProtectionService::CheckCsdWhitelistOnIOThread( | 103 void PasswordProtectionService::CheckCsdWhitelistOnIOThread( |
| 93 const GURL& url, | 104 const GURL& url, |
| 94 const CheckCsdWhitelistCallback& callback) { | 105 const CheckCsdWhitelistCallback& callback) { |
| 95 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 106 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 96 DCHECK(database_manager_); | 107 DCHECK(database_manager_); |
| 97 bool check_result = database_manager_->MatchCsdWhitelistUrl(url); | 108 bool check_result = database_manager_->MatchCsdWhitelistUrl(url); |
| 98 DCHECK(callback); | 109 DCHECK(callback); |
| 99 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 110 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 100 base::Bind(callback, check_result)); | 111 base::Bind(callback, check_result)); |
| 101 } | 112 } |
| 102 | 113 |
| 103 LoginReputationClientResponse::VerdictType | 114 LoginReputationClientResponse::VerdictType |
| 104 PasswordProtectionService::GetCachedVerdict( | 115 PasswordProtectionService::GetCachedVerdict( |
| 105 const HostContentSettingsMap* settings, | |
| 106 const GURL& url, | 116 const GURL& url, |
| 107 LoginReputationClientResponse* out_response) { | 117 LoginReputationClientResponse* out_response) { |
| 108 DCHECK(settings); | 118 if (!url.is_valid()) |
| 109 if (!url.is_valid()) { | |
| 110 return LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED; | 119 return LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED; |
| 111 } | 120 |
| 121 DCHECK(content_settings_); |
| 112 | 122 |
| 113 GURL hostname = GetHostNameWithHTTPScheme(url); | 123 GURL hostname = GetHostNameWithHTTPScheme(url); |
| 114 std::unique_ptr<base::DictionaryValue> verdict_dictionary = | 124 std::unique_ptr<base::DictionaryValue> verdict_dictionary = |
| 115 base::DictionaryValue::From(settings->GetWebsiteSetting( | 125 base::DictionaryValue::From(content_settings_->GetWebsiteSetting( |
| 116 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 126 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 117 std::string(), nullptr)); | 127 std::string(), nullptr)); |
| 118 // Return early if there is no verdict cached for this origin. | 128 // Return early if there is no verdict cached for this origin. |
| 119 if (!verdict_dictionary.get() || verdict_dictionary->empty()) | 129 if (!verdict_dictionary.get() || verdict_dictionary->empty()) |
| 120 return LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED; | 130 return LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED; |
| 121 | 131 |
| 122 std::vector<std::string> paths; | 132 std::vector<std::string> paths; |
| 123 GeneratePathVariantsWithoutQuery(url, &paths); | 133 GeneratePathVariantsWithoutQuery(url, &paths); |
| 124 size_t max_path_depth = 0U; | 134 size_t max_path_depth = 0U; |
| 125 LoginReputationClientResponse::VerdictType most_matching_verdict = | 135 LoginReputationClientResponse::VerdictType most_matching_verdict = |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 out_response->CopyFrom(verdict); | 173 out_response->CopyFrom(verdict); |
| 164 } | 174 } |
| 165 } | 175 } |
| 166 } | 176 } |
| 167 return most_matching_verdict; | 177 return most_matching_verdict; |
| 168 } | 178 } |
| 169 | 179 |
| 170 void PasswordProtectionService::CacheVerdict( | 180 void PasswordProtectionService::CacheVerdict( |
| 171 const GURL& url, | 181 const GURL& url, |
| 172 LoginReputationClientResponse* verdict, | 182 LoginReputationClientResponse* verdict, |
| 173 const base::Time& receive_time, | 183 const base::Time& receive_time) { |
| 174 HostContentSettingsMap* settings) { | |
| 175 DCHECK(verdict); | 184 DCHECK(verdict); |
| 185 DCHECK(content_settings_); |
| 176 | 186 |
| 177 GURL hostname = GetHostNameWithHTTPScheme(url); | 187 GURL hostname = GetHostNameWithHTTPScheme(url); |
| 178 std::unique_ptr<base::DictionaryValue> verdict_dictionary = | 188 std::unique_ptr<base::DictionaryValue> verdict_dictionary = |
| 179 base::DictionaryValue::From(settings->GetWebsiteSetting( | 189 base::DictionaryValue::From(content_settings_->GetWebsiteSetting( |
| 180 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 190 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 181 std::string(), nullptr)); | 191 std::string(), nullptr)); |
| 182 | 192 |
| 183 if (!verdict_dictionary.get()) | 193 if (!verdict_dictionary.get()) |
| 184 verdict_dictionary = base::MakeUnique<base::DictionaryValue>(); | 194 verdict_dictionary = base::MakeUnique<base::DictionaryValue>(); |
| 185 | 195 |
| 186 std::unique_ptr<base::DictionaryValue> verdict_entry = | 196 std::unique_ptr<base::DictionaryValue> verdict_entry = |
| 187 CreateDictionaryFromVerdict(verdict, receive_time); | 197 CreateDictionaryFromVerdict(verdict, receive_time); |
| 188 | 198 |
| 189 // Increases stored verdict count if we haven't seen this cache expression | 199 // Increases stored verdict count if we haven't seen this cache expression |
| 190 // before. | 200 // before. |
| 191 if (!verdict_dictionary->HasKey(verdict->cache_expression())) | 201 if (!verdict_dictionary->HasKey(verdict->cache_expression())) |
| 192 stored_verdict_counts_[settings] = GetStoredVerdictCount() + 1U; | 202 stored_verdict_count_ = GetStoredVerdictCount() + 1; |
| 193 // If same cache_expression is already in this verdict_dictionary, we simply | 203 // If same cache_expression is already in this verdict_dictionary, we simply |
| 194 // override it. | 204 // override it. |
| 195 verdict_dictionary->SetWithoutPathExpansion(verdict->cache_expression(), | 205 verdict_dictionary->SetWithoutPathExpansion(verdict->cache_expression(), |
| 196 std::move(verdict_entry)); | 206 std::move(verdict_entry)); |
| 197 settings->SetWebsiteSettingDefaultScope( | 207 content_settings_->SetWebsiteSettingDefaultScope( |
| 198 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 208 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 199 std::string(), std::move(verdict_dictionary)); | 209 std::string(), std::move(verdict_dictionary)); |
| 200 } | 210 } |
| 201 | 211 |
| 202 void PasswordProtectionService::StartRequest( | 212 void PasswordProtectionService::StartRequest( |
| 203 const GURL& main_frame_url, | 213 const GURL& main_frame_url, |
| 204 LoginReputationClientRequest::TriggerType type, | 214 LoginReputationClientRequest::TriggerType type) { |
| 205 bool is_extended_reporting, | |
| 206 bool is_incognito) { | |
| 207 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 215 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 216 if (!IsPingingEnabled()) |
| 217 return; |
| 208 std::unique_ptr<PasswordProtectionRequest> request = | 218 std::unique_ptr<PasswordProtectionRequest> request = |
| 209 base::MakeUnique<PasswordProtectionRequest>( | 219 base::MakeUnique<PasswordProtectionRequest>( |
| 210 main_frame_url, type, is_extended_reporting, is_incognito, | 220 main_frame_url, type, IsExtendedReporting(), IsIncognito(), |
| 211 GetWeakPtr(), GetRequestTimeoutInMS()); | 221 GetWeakPtr(), GetRequestTimeoutInMS()); |
| 212 DCHECK(request); | 222 DCHECK(request); |
| 213 request->Start(); | 223 request->Start(); |
| 214 requests_.insert(std::move(request)); | 224 requests_.insert(std::move(request)); |
| 215 } | 225 } |
| 216 | 226 |
| 217 void PasswordProtectionService::RequestFinished( | 227 void PasswordProtectionService::RequestFinished( |
| 218 PasswordProtectionRequest* request, | 228 PasswordProtectionRequest* request, |
| 219 std::unique_ptr<LoginReputationClientResponse> response) { | 229 std::unique_ptr<LoginReputationClientResponse> response) { |
| 220 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 230 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 221 | 231 |
| 222 DCHECK(request); | 232 DCHECK(request); |
| 223 // TODO(jialiul): We don't cache verdict for incognito mode for now. | 233 // TODO(jialiul): We don't cache verdict for incognito mode for now. |
| 224 // Later we may consider temporarily caching verdict. | 234 // Later we may consider temporarily caching verdict. |
| 225 if (!request->is_incognito() && response) { | 235 if (!request->is_incognito() && response) |
| 226 CacheVerdict(request->main_frame_url(), response.get(), base::Time::Now(), | 236 CacheVerdict(request->main_frame_url(), response.get(), base::Time::Now()); |
| 227 GetSettingMapForActiveProfile()); | 237 |
| 228 } | |
| 229 // Finished processing this request. Remove it from pending list. | 238 // Finished processing this request. Remove it from pending list. |
| 230 for (auto it = requests_.begin(); it != requests_.end(); it++) { | 239 for (auto it = requests_.begin(); it != requests_.end(); it++) { |
| 231 if (it->get() == request) { | 240 if (it->get() == request) { |
| 232 requests_.erase(it); | 241 requests_.erase(it); |
| 233 break; | 242 break; |
| 234 } | 243 } |
| 235 } | 244 } |
| 236 } | 245 } |
| 237 | 246 |
| 238 void PasswordProtectionService::CancelPendingRequests() { | 247 void PasswordProtectionService::CancelPendingRequests() { |
| 239 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 248 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 240 for (auto it = requests_.begin(); it != requests_.end();) { | 249 for (auto it = requests_.begin(); it != requests_.end();) { |
| 241 // We need to advance the iterator before we cancel because canceling | 250 // We need to advance the iterator before we cancel because canceling |
| 242 // the request will invalidate it when RequestFinished is called. | 251 // the request will invalidate it when RequestFinished is called. |
| 243 PasswordProtectionRequest* request = it->get(); | 252 PasswordProtectionRequest* request = it->get(); |
| 244 it++; | 253 it++; |
| 245 request->Cancel(false); | 254 request->Cancel(false); |
| 246 } | 255 } |
| 247 DCHECK(requests_.empty()); | 256 DCHECK(requests_.empty()); |
| 248 } | 257 } |
| 249 | 258 |
| 250 GURL PasswordProtectionService::GetPasswordProtectionRequestUrl() { | 259 GURL PasswordProtectionService::GetPasswordProtectionRequestUrl() { |
| 251 GURL url(kPasswordProtectionRequestUrl); | 260 GURL url(kPasswordProtectionRequestUrl); |
| 252 std::string api_key = google_apis::GetAPIKey(); | 261 std::string api_key = google_apis::GetAPIKey(); |
| 253 DCHECK(!api_key.empty()); | 262 DCHECK(!api_key.empty()); |
| 254 return url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 263 return url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 255 } | 264 } |
| 256 | 265 |
| 257 size_t PasswordProtectionService::GetStoredVerdictCount() { | 266 int PasswordProtectionService::GetStoredVerdictCount() { |
| 258 HostContentSettingsMap* content_setting_map = GetSettingMapForActiveProfile(); | 267 DCHECK(content_settings_); |
| 259 DCHECK(content_setting_map); | |
| 260 auto it = stored_verdict_counts_.find(content_setting_map); | |
| 261 // If we have already computed this, return its value. | 268 // If we have already computed this, return its value. |
| 262 if (it != stored_verdict_counts_.end()) | 269 if (stored_verdict_count_ >= 0) |
| 263 return it->second; | 270 return stored_verdict_count_; |
| 264 | 271 |
| 265 ContentSettingsForOneType password_protection_settings; | 272 ContentSettingsForOneType password_protection_settings; |
| 266 content_setting_map->GetSettingsForOneType( | 273 content_settings_->GetSettingsForOneType( |
| 267 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, std::string(), | 274 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, std::string(), |
| 268 &password_protection_settings); | 275 &password_protection_settings); |
| 269 stored_verdict_counts_[content_setting_map] = 0U; | 276 stored_verdict_count_ = 0; |
| 270 if (password_protection_settings.empty()) | 277 if (password_protection_settings.empty()) |
| 271 return 0U; | 278 return 0; |
| 272 | 279 |
| 273 for (const ContentSettingPatternSource& source : | 280 for (const ContentSettingPatternSource& source : |
| 274 password_protection_settings) { | 281 password_protection_settings) { |
| 275 std::unique_ptr<base::DictionaryValue> verdict_dictionary = | 282 std::unique_ptr<base::DictionaryValue> verdict_dictionary = |
| 276 base::DictionaryValue::From(content_setting_map->GetWebsiteSetting( | 283 base::DictionaryValue::From(content_settings_->GetWebsiteSetting( |
| 277 GURL(source.primary_pattern.ToString()), GURL(), | 284 GURL(source.primary_pattern.ToString()), GURL(), |
| 278 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, std::string(), nullptr)); | 285 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, std::string(), nullptr)); |
| 279 stored_verdict_counts_[content_setting_map] += verdict_dictionary->size(); | 286 if (verdict_dictionary.get() && !verdict_dictionary->empty()) |
| 287 stored_verdict_count_ += static_cast<int>(verdict_dictionary->size()); |
| 280 } | 288 } |
| 281 return stored_verdict_counts_[content_setting_map]; | 289 return stored_verdict_count_; |
| 282 } | 290 } |
| 283 | 291 |
| 284 int PasswordProtectionService::GetRequestTimeoutInMS() { | 292 int PasswordProtectionService::GetRequestTimeoutInMS() { |
| 285 return kRequestTimeoutMs; | 293 return kRequestTimeoutMs; |
| 286 } | 294 } |
| 287 | 295 |
| 288 void PasswordProtectionService::OnMatchCsdWhiteListResult( | 296 void PasswordProtectionService::OnMatchCsdWhiteListResult( |
| 289 bool match_whitelist) { | 297 bool match_whitelist) { |
| 290 UMA_HISTOGRAM_BOOLEAN( | 298 UMA_HISTOGRAM_BOOLEAN( |
| 291 "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist", | 299 "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist", |
| 292 match_whitelist); | 300 match_whitelist); |
| 293 } | 301 } |
| 294 | 302 |
| 295 HostContentSettingsMap* | |
| 296 PasswordProtectionService::GetSettingMapForActiveProfile() { | |
| 297 // TODO(jialiul): Make this a pure virtual function when we have a derived | |
| 298 // class ready in chrome/browser/safe_browsing directory. | |
| 299 return nullptr; | |
| 300 } | |
| 301 | |
| 302 void PasswordProtectionService::OnURLsDeleted( | 303 void PasswordProtectionService::OnURLsDeleted( |
| 303 history::HistoryService* history_service, | 304 history::HistoryService* history_service, |
| 304 bool all_history, | 305 bool all_history, |
| 305 bool expired, | 306 bool expired, |
| 306 const history::URLRows& deleted_rows, | 307 const history::URLRows& deleted_rows, |
| 307 const std::set<GURL>& favicon_urls) { | 308 const std::set<GURL>& favicon_urls) { |
| 308 HostContentSettingsMap* setting_map = GetSettingMapForActiveProfile(); | |
| 309 if (!setting_map) | |
| 310 return; | |
| 311 | |
| 312 BrowserThread::PostTask( | 309 BrowserThread::PostTask( |
| 313 BrowserThread::UI, FROM_HERE, | 310 BrowserThread::UI, FROM_HERE, |
| 314 base::Bind(&PasswordProtectionService::RemoveContentSettingsOnURLsDeleted, | 311 base::Bind(&PasswordProtectionService::RemoveContentSettingsOnURLsDeleted, |
| 315 GetWeakPtr(), all_history, deleted_rows, setting_map)); | 312 GetWeakPtr(), all_history, deleted_rows)); |
| 313 } |
| 314 |
| 315 void PasswordProtectionService::HistoryServiceBeingDeleted( |
| 316 history::HistoryService* history_service) { |
| 317 history_service_observer_.RemoveAll(); |
| 316 } | 318 } |
| 317 | 319 |
| 318 void PasswordProtectionService::RemoveContentSettingsOnURLsDeleted( | 320 void PasswordProtectionService::RemoveContentSettingsOnURLsDeleted( |
| 319 bool all_history, | 321 bool all_history, |
| 320 const history::URLRows& deleted_rows, | 322 const history::URLRows& deleted_rows) { |
| 321 HostContentSettingsMap* setting_map) { | |
| 322 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 323 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 324 DCHECK(content_settings_); |
| 325 |
| 323 if (all_history) { | 326 if (all_history) { |
| 324 setting_map->ClearSettingsForOneType( | 327 content_settings_->ClearSettingsForOneType( |
| 325 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION); | 328 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION); |
| 326 stored_verdict_counts_[setting_map] = 0U; | 329 stored_verdict_count_ = 0; |
| 327 return; | 330 return; |
| 328 } | 331 } |
| 329 | 332 |
| 330 // For now, if a URL is deleted from history, we simply remove all the | 333 // For now, if a URL is deleted from history, we simply remove all the |
| 331 // cached verdicts of the same origin. This is a pretty aggressive deletion. | 334 // cached verdicts of the same origin. This is a pretty aggressive deletion. |
| 332 // We might revisit this logic later to decide if we want to only delete the | 335 // We might revisit this logic later to decide if we want to only delete the |
| 333 // cached verdict whose cache expression matches this URL. | 336 // cached verdict whose cache expression matches this URL. |
| 334 for (const history::URLRow& row : deleted_rows) { | 337 for (const history::URLRow& row : deleted_rows) { |
| 335 GURL url_key = GetHostNameWithHTTPScheme(row.url()); | 338 GURL url_key = GetHostNameWithHTTPScheme(row.url()); |
| 336 std::unique_ptr<base::DictionaryValue> verdict_dictionary = | 339 std::unique_ptr<base::DictionaryValue> verdict_dictionary = |
| 337 base::DictionaryValue::From(setting_map->GetWebsiteSetting( | 340 base::DictionaryValue::From(content_settings_->GetWebsiteSetting( |
| 338 url_key, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 341 url_key, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 339 std::string(), nullptr)); | 342 std::string(), nullptr)); |
| 340 size_t verdict_count = verdict_dictionary->size(); | 343 |
| 341 stored_verdict_counts_[setting_map] = | 344 // Move on if we have no cached verdict for this deleted history row. |
| 342 GetStoredVerdictCount() - verdict_count; | 345 if (!verdict_dictionary.get() || verdict_dictionary->empty()) |
| 343 setting_map->ClearSettingsForOneTypeWithPredicate( | 346 continue; |
| 347 |
| 348 int verdict_count = static_cast<int>(verdict_dictionary->size()); |
| 349 stored_verdict_count_ = GetStoredVerdictCount() - verdict_count; |
| 350 content_settings_->ClearSettingsForOneTypeWithPredicate( |
| 344 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 351 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 345 base::Bind(&OriginMatchPrimaryPattern, url_key)); | 352 base::Bind(&OriginMatchPrimaryPattern, url_key)); |
| 346 } | 353 } |
| 347 } | 354 } |
| 348 | 355 |
| 349 // static | 356 // static |
| 350 bool PasswordProtectionService::ParseVerdictEntry( | 357 bool PasswordProtectionService::ParseVerdictEntry( |
| 351 base::DictionaryValue* verdict_entry, | 358 base::DictionaryValue* verdict_entry, |
| 352 int* out_verdict_received_time, | 359 int* out_verdict_received_time, |
| 353 LoginReputationClientResponse* out_verdict) { | 360 LoginReputationClientResponse* out_verdict) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 const std::vector<char> verdict_blob(serialized_proto.begin(), | 448 const std::vector<char> verdict_blob(serialized_proto.begin(), |
| 442 serialized_proto.end()); | 449 serialized_proto.end()); |
| 443 std::unique_ptr<base::Value> binary_value = | 450 std::unique_ptr<base::Value> binary_value = |
| 444 base::MakeUnique<base::Value>(verdict_blob); | 451 base::MakeUnique<base::Value>(verdict_blob); |
| 445 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type()); | 452 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type()); |
| 446 result->Set(kVerdictProto, std::move(binary_value)); | 453 result->Set(kVerdictProto, std::move(binary_value)); |
| 447 return result; | 454 return result; |
| 448 } | 455 } |
| 449 | 456 |
| 450 } // namespace safe_browsing | 457 } // namespace safe_browsing |
| OLD | NEW |