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 #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( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 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() || !content_settings_) { |
|
Nathan Parker
2017/03/30 21:38:12
when would !content_settings be true? Should that
Jialiu Lin
2017/03/30 23:23:07
Yes.... object lifetime scares me... so I tend to
Nathan Parker
2017/03/31 18:41:15
I totally agree! Better safe than sorry... But th
| |
| 109 if (!url.is_valid()) { | |
| 110 return LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED; | 119 return LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED; |
| 111 } | 120 } |
| 112 | 121 |
| 113 GURL hostname = GetHostNameWithHTTPScheme(url); | 122 GURL hostname = GetHostNameWithHTTPScheme(url); |
| 114 std::unique_ptr<base::DictionaryValue> verdict_dictionary = | 123 std::unique_ptr<base::DictionaryValue> verdict_dictionary = |
| 115 base::DictionaryValue::From(settings->GetWebsiteSetting( | 124 base::DictionaryValue::From(content_settings_->GetWebsiteSetting( |
| 116 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 125 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 117 std::string(), nullptr)); | 126 std::string(), nullptr)); |
| 118 // Return early if there is no verdict cached for this origin. | 127 // Return early if there is no verdict cached for this origin. |
| 119 if (!verdict_dictionary.get() || verdict_dictionary->empty()) | 128 if (!verdict_dictionary.get() || verdict_dictionary->empty()) |
| 120 return LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED; | 129 return LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED; |
| 121 | 130 |
| 122 std::vector<std::string> paths; | 131 std::vector<std::string> paths; |
| 123 GeneratePathVariantsWithoutQuery(url, &paths); | 132 GeneratePathVariantsWithoutQuery(url, &paths); |
| 124 size_t max_path_depth = 0U; | 133 size_t max_path_depth = 0U; |
| 125 LoginReputationClientResponse::VerdictType most_matching_verdict = | 134 LoginReputationClientResponse::VerdictType most_matching_verdict = |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 out_response->CopyFrom(verdict); | 172 out_response->CopyFrom(verdict); |
| 164 } | 173 } |
| 165 } | 174 } |
| 166 } | 175 } |
| 167 return most_matching_verdict; | 176 return most_matching_verdict; |
| 168 } | 177 } |
| 169 | 178 |
| 170 void PasswordProtectionService::CacheVerdict( | 179 void PasswordProtectionService::CacheVerdict( |
| 171 const GURL& url, | 180 const GURL& url, |
| 172 LoginReputationClientResponse* verdict, | 181 LoginReputationClientResponse* verdict, |
| 173 const base::Time& receive_time, | 182 const base::Time& receive_time) { |
| 174 HostContentSettingsMap* settings) { | |
| 175 DCHECK(verdict); | 183 DCHECK(verdict); |
| 184 DCHECK(content_settings_); | |
| 176 | 185 |
| 177 GURL hostname = GetHostNameWithHTTPScheme(url); | 186 GURL hostname = GetHostNameWithHTTPScheme(url); |
| 178 std::unique_ptr<base::DictionaryValue> verdict_dictionary = | 187 std::unique_ptr<base::DictionaryValue> verdict_dictionary = |
| 179 base::DictionaryValue::From(settings->GetWebsiteSetting( | 188 base::DictionaryValue::From(content_settings_->GetWebsiteSetting( |
| 180 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 189 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 181 std::string(), nullptr)); | 190 std::string(), nullptr)); |
| 182 | 191 |
| 183 if (!verdict_dictionary.get()) | 192 if (!verdict_dictionary.get()) |
| 184 verdict_dictionary = base::MakeUnique<base::DictionaryValue>(); | 193 verdict_dictionary = base::MakeUnique<base::DictionaryValue>(); |
| 185 | 194 |
| 186 std::unique_ptr<base::DictionaryValue> verdict_entry = | 195 std::unique_ptr<base::DictionaryValue> verdict_entry = |
| 187 CreateDictionaryFromVerdict(verdict, receive_time); | 196 CreateDictionaryFromVerdict(verdict, receive_time); |
| 188 | 197 |
| 189 // Increases stored verdict count if we haven't seen this cache expression | 198 // Increases stored verdict count if we haven't seen this cache expression |
| 190 // before. | 199 // before. |
| 191 if (!verdict_dictionary->HasKey(verdict->cache_expression())) | 200 if (!verdict_dictionary->HasKey(verdict->cache_expression())) |
| 192 stored_verdict_counts_[settings] = GetStoredVerdictCount() + 1U; | 201 stored_verdict_count_ = GetStoredVerdictCount() + 1; |
| 193 // If same cache_expression is already in this verdict_dictionary, we simply | 202 // If same cache_expression is already in this verdict_dictionary, we simply |
| 194 // override it. | 203 // override it. |
| 195 verdict_dictionary->SetWithoutPathExpansion(verdict->cache_expression(), | 204 verdict_dictionary->SetWithoutPathExpansion(verdict->cache_expression(), |
| 196 std::move(verdict_entry)); | 205 std::move(verdict_entry)); |
| 197 settings->SetWebsiteSettingDefaultScope( | 206 content_settings_->SetWebsiteSettingDefaultScope( |
| 198 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 207 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 199 std::string(), std::move(verdict_dictionary)); | 208 std::string(), std::move(verdict_dictionary)); |
| 200 } | 209 } |
| 201 | 210 |
| 202 void PasswordProtectionService::StartRequest( | 211 void PasswordProtectionService::StartRequest( |
| 203 const GURL& main_frame_url, | 212 const GURL& main_frame_url, |
| 204 LoginReputationClientRequest::TriggerType type, | 213 LoginReputationClientRequest::TriggerType type) { |
| 205 bool is_extended_reporting, | |
| 206 bool is_incognito) { | |
| 207 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 214 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 215 if (!IsPingingEnabled()) | |
| 216 return; | |
| 208 std::unique_ptr<PasswordProtectionRequest> request = | 217 std::unique_ptr<PasswordProtectionRequest> request = |
| 209 base::MakeUnique<PasswordProtectionRequest>( | 218 base::MakeUnique<PasswordProtectionRequest>( |
| 210 main_frame_url, type, is_extended_reporting, is_incognito, | 219 main_frame_url, type, IsExtendedReporting(), IsIncognito(), |
| 211 GetWeakPtr(), GetRequestTimeoutInMS()); | 220 GetWeakPtr(), GetRequestTimeoutInMS()); |
| 212 DCHECK(request); | 221 DCHECK(request); |
| 213 request->Start(); | 222 request->Start(); |
| 214 requests_.insert(std::move(request)); | 223 requests_.insert(std::move(request)); |
| 215 } | 224 } |
| 216 | 225 |
| 217 void PasswordProtectionService::RequestFinished( | 226 void PasswordProtectionService::RequestFinished( |
| 218 PasswordProtectionRequest* request, | 227 PasswordProtectionRequest* request, |
| 219 std::unique_ptr<LoginReputationClientResponse> response) { | 228 std::unique_ptr<LoginReputationClientResponse> response) { |
| 220 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 229 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 221 | 230 |
| 222 DCHECK(request); | 231 DCHECK(request); |
| 223 // TODO(jialiul): We don't cache verdict for incognito mode for now. | 232 // TODO(jialiul): We don't cache verdict for incognito mode for now. |
| 224 // Later we may consider temporarily caching verdict. | 233 // Later we may consider temporarily caching verdict. |
| 225 if (!request->is_incognito() && response) { | 234 if (!request->is_incognito() && response) |
| 226 CacheVerdict(request->main_frame_url(), response.get(), base::Time::Now(), | 235 CacheVerdict(request->main_frame_url(), response.get(), base::Time::Now()); |
| 227 GetSettingMapForActiveProfile()); | 236 |
| 228 } | |
| 229 // Finished processing this request. Remove it from pending list. | 237 // Finished processing this request. Remove it from pending list. |
| 230 for (auto it = requests_.begin(); it != requests_.end(); it++) { | 238 for (auto it = requests_.begin(); it != requests_.end(); it++) { |
| 231 if (it->get() == request) { | 239 if (it->get() == request) { |
| 232 requests_.erase(it); | 240 requests_.erase(it); |
| 233 break; | 241 break; |
| 234 } | 242 } |
| 235 } | 243 } |
| 236 } | 244 } |
| 237 | 245 |
| 238 void PasswordProtectionService::CancelPendingRequests() { | 246 void PasswordProtectionService::CancelPendingRequests() { |
| 239 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 247 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 240 for (auto it = requests_.begin(); it != requests_.end();) { | 248 for (auto it = requests_.begin(); it != requests_.end();) { |
| 241 // We need to advance the iterator before we cancel because canceling | 249 // We need to advance the iterator before we cancel because canceling |
| 242 // the request will invalidate it when RequestFinished is called. | 250 // the request will invalidate it when RequestFinished is called. |
| 243 PasswordProtectionRequest* request = it->get(); | 251 PasswordProtectionRequest* request = it->get(); |
| 244 it++; | 252 it++; |
| 245 request->Cancel(false); | 253 request->Cancel(false); |
| 246 } | 254 } |
| 247 DCHECK(requests_.empty()); | 255 DCHECK(requests_.empty()); |
| 248 } | 256 } |
| 249 | 257 |
| 250 GURL PasswordProtectionService::GetPasswordProtectionRequestUrl() { | 258 GURL PasswordProtectionService::GetPasswordProtectionRequestUrl() { |
| 251 GURL url(kPasswordProtectionRequestUrl); | 259 GURL url(kPasswordProtectionRequestUrl); |
| 252 std::string api_key = google_apis::GetAPIKey(); | 260 std::string api_key = google_apis::GetAPIKey(); |
| 253 DCHECK(!api_key.empty()); | 261 DCHECK(!api_key.empty()); |
| 254 return url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 262 return url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 255 } | 263 } |
| 256 | 264 |
| 257 size_t PasswordProtectionService::GetStoredVerdictCount() { | 265 int PasswordProtectionService::GetStoredVerdictCount() { |
| 258 HostContentSettingsMap* content_setting_map = GetSettingMapForActiveProfile(); | 266 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. | 267 // If we have already computed this, return its value. |
| 262 if (it != stored_verdict_counts_.end()) | 268 if (stored_verdict_count_ >= 0) |
| 263 return it->second; | 269 return stored_verdict_count_; |
| 264 | 270 |
| 265 ContentSettingsForOneType password_protection_settings; | 271 ContentSettingsForOneType password_protection_settings; |
| 266 content_setting_map->GetSettingsForOneType( | 272 content_settings_->GetSettingsForOneType( |
| 267 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, std::string(), | 273 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, std::string(), |
| 268 &password_protection_settings); | 274 &password_protection_settings); |
| 269 stored_verdict_counts_[content_setting_map] = 0U; | 275 stored_verdict_count_ = 0; |
| 270 if (password_protection_settings.empty()) | 276 if (password_protection_settings.empty()) |
| 271 return 0U; | 277 return 0; |
| 272 | 278 |
| 273 for (const ContentSettingPatternSource& source : | 279 for (const ContentSettingPatternSource& source : |
| 274 password_protection_settings) { | 280 password_protection_settings) { |
| 275 std::unique_ptr<base::DictionaryValue> verdict_dictionary = | 281 std::unique_ptr<base::DictionaryValue> verdict_dictionary = |
| 276 base::DictionaryValue::From(content_setting_map->GetWebsiteSetting( | 282 base::DictionaryValue::From(content_settings_->GetWebsiteSetting( |
| 277 GURL(source.primary_pattern.ToString()), GURL(), | 283 GURL(source.primary_pattern.ToString()), GURL(), |
| 278 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, std::string(), nullptr)); | 284 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, std::string(), nullptr)); |
| 279 stored_verdict_counts_[content_setting_map] += verdict_dictionary->size(); | 285 if (verdict_dictionary.get() && verdict_dictionary->empty()) |
|
Nathan Parker
2017/03/30 21:38:12
Do you mean !empty()? If it's empty, the ->size()
Jialiu Lin
2017/03/30 23:23:06
Oops. it should be !empty().
| |
| 286 stored_verdict_count_ += static_cast<int>(verdict_dictionary->size()); | |
| 280 } | 287 } |
| 281 return stored_verdict_counts_[content_setting_map]; | 288 return stored_verdict_count_; |
|
Nathan Parker
2017/03/30 21:38:12
It might be interesting to log this value to UMA,
Jialiu Lin
2017/03/30 23:23:08
This number is sent with every ping. I think that'
| |
| 282 } | 289 } |
| 283 | 290 |
| 284 int PasswordProtectionService::GetRequestTimeoutInMS() { | 291 int PasswordProtectionService::GetRequestTimeoutInMS() { |
| 285 return kRequestTimeoutMs; | 292 return kRequestTimeoutMs; |
| 286 } | 293 } |
| 287 | 294 |
| 288 void PasswordProtectionService::OnMatchCsdWhiteListResult( | 295 void PasswordProtectionService::OnMatchCsdWhiteListResult( |
| 289 bool match_whitelist) { | 296 bool match_whitelist) { |
| 290 UMA_HISTOGRAM_BOOLEAN( | 297 UMA_HISTOGRAM_BOOLEAN( |
| 291 "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist", | 298 "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist", |
| 292 match_whitelist); | 299 match_whitelist); |
| 293 } | 300 } |
| 294 | 301 |
| 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( | 302 void PasswordProtectionService::OnURLsDeleted( |
| 303 history::HistoryService* history_service, | 303 history::HistoryService* history_service, |
| 304 bool all_history, | 304 bool all_history, |
| 305 bool expired, | 305 bool expired, |
| 306 const history::URLRows& deleted_rows, | 306 const history::URLRows& deleted_rows, |
| 307 const std::set<GURL>& favicon_urls) { | 307 const std::set<GURL>& favicon_urls) { |
| 308 HostContentSettingsMap* setting_map = GetSettingMapForActiveProfile(); | |
| 309 if (!setting_map) | |
| 310 return; | |
| 311 | |
| 312 BrowserThread::PostTask( | 308 BrowserThread::PostTask( |
| 313 BrowserThread::UI, FROM_HERE, | 309 BrowserThread::UI, FROM_HERE, |
| 314 base::Bind(&PasswordProtectionService::RemoveContentSettingsOnURLsDeleted, | 310 base::Bind(&PasswordProtectionService::RemoveContentSettingsOnURLsDeleted, |
| 315 GetWeakPtr(), all_history, deleted_rows, setting_map)); | 311 GetWeakPtr(), all_history, deleted_rows)); |
| 312 } | |
| 313 | |
| 314 void PasswordProtectionService::HistoryServiceBeingDeleted( | |
| 315 history::HistoryService* history_service) { | |
| 316 history_service_observer_.RemoveAll(); | |
| 316 } | 317 } |
| 317 | 318 |
| 318 void PasswordProtectionService::RemoveContentSettingsOnURLsDeleted( | 319 void PasswordProtectionService::RemoveContentSettingsOnURLsDeleted( |
| 319 bool all_history, | 320 bool all_history, |
| 320 const history::URLRows& deleted_rows, | 321 const history::URLRows& deleted_rows) { |
| 321 HostContentSettingsMap* setting_map) { | |
| 322 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 322 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 323 DCHECK(content_settings_); | |
| 324 | |
| 323 if (all_history) { | 325 if (all_history) { |
| 324 setting_map->ClearSettingsForOneType( | 326 content_settings_->ClearSettingsForOneType( |
| 325 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION); | 327 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION); |
| 326 stored_verdict_counts_[setting_map] = 0U; | 328 stored_verdict_count_ = 0; |
| 327 return; | 329 return; |
| 328 } | 330 } |
| 329 | 331 |
| 330 // For now, if a URL is deleted from history, we simply remove all the | 332 // 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. | 333 // 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 | 334 // We might revisit this logic later to decide if we want to only delete the |
| 333 // cached verdict whose cache expression matches this URL. | 335 // cached verdict whose cache expression matches this URL. |
| 334 for (const history::URLRow& row : deleted_rows) { | 336 for (const history::URLRow& row : deleted_rows) { |
| 335 GURL url_key = GetHostNameWithHTTPScheme(row.url()); | 337 GURL url_key = GetHostNameWithHTTPScheme(row.url()); |
| 336 std::unique_ptr<base::DictionaryValue> verdict_dictionary = | 338 std::unique_ptr<base::DictionaryValue> verdict_dictionary = |
| 337 base::DictionaryValue::From(setting_map->GetWebsiteSetting( | 339 base::DictionaryValue::From(content_settings_->GetWebsiteSetting( |
| 338 url_key, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 340 url_key, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 339 std::string(), nullptr)); | 341 std::string(), nullptr)); |
| 340 size_t verdict_count = verdict_dictionary->size(); | 342 |
| 341 stored_verdict_counts_[setting_map] = | 343 // Move on if we have no cached verdict for this deleted history row. |
| 342 GetStoredVerdictCount() - verdict_count; | 344 if (!verdict_dictionary.get() || verdict_dictionary->empty()) |
| 343 setting_map->ClearSettingsForOneTypeWithPredicate( | 345 continue; |
| 346 | |
| 347 int verdict_count = static_cast<int>(verdict_dictionary->size()); | |
| 348 stored_verdict_count_ = GetStoredVerdictCount() - verdict_count; | |
| 349 content_settings_->ClearSettingsForOneTypeWithPredicate( | |
| 344 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 350 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 345 base::Bind(&OriginMatchPrimaryPattern, url_key)); | 351 base::Bind(&OriginMatchPrimaryPattern, url_key)); |
| 346 } | 352 } |
| 347 } | 353 } |
| 348 | 354 |
| 349 // static | 355 // static |
| 350 bool PasswordProtectionService::ParseVerdictEntry( | 356 bool PasswordProtectionService::ParseVerdictEntry( |
| 351 base::DictionaryValue* verdict_entry, | 357 base::DictionaryValue* verdict_entry, |
| 352 int* out_verdict_received_time, | 358 int* out_verdict_received_time, |
| 353 LoginReputationClientResponse* out_verdict) { | 359 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(), | 447 const std::vector<char> verdict_blob(serialized_proto.begin(), |
| 442 serialized_proto.end()); | 448 serialized_proto.end()); |
| 443 std::unique_ptr<base::Value> binary_value = | 449 std::unique_ptr<base::Value> binary_value = |
| 444 base::MakeUnique<base::Value>(verdict_blob); | 450 base::MakeUnique<base::Value>(verdict_blob); |
| 445 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type()); | 451 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type()); |
| 446 result->Set(kVerdictProto, std::move(binary_value)); | 452 result->Set(kVerdictProto, std::move(binary_value)); |
| 447 return result; | 453 return result; |
| 448 } | 454 } |
| 449 | 455 |
| 450 } // namespace safe_browsing | 456 } // namespace safe_browsing |
| OLD | NEW |