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 #include "components/safe_browsing/password_protection/password_protection_reque st.h" | 4 #include "components/safe_browsing/password_protection/password_protection_reque st.h" |
| 5 | 5 |
| 6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
| 7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "components/data_use_measurement/core/data_use_user_data.h" | 9 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 void PasswordProtectionRequest::CheckCachedVerdicts() { | 77 void PasswordProtectionRequest::CheckCachedVerdicts() { |
| 78 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 78 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 79 if (!password_protection_service_) { | 79 if (!password_protection_service_) { |
| 80 Finish(RequestOutcome::SERVICE_DESTROYED, nullptr); | 80 Finish(RequestOutcome::SERVICE_DESTROYED, nullptr); |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 | 83 |
| 84 std::unique_ptr<LoginReputationClientResponse> cached_response = | 84 std::unique_ptr<LoginReputationClientResponse> cached_response = |
| 85 base::MakeUnique<LoginReputationClientResponse>(); | 85 base::MakeUnique<LoginReputationClientResponse>(); |
| 86 auto verdict = password_protection_service_->GetCachedVerdict( | 86 auto verdict = password_protection_service_->GetCachedVerdict( |
| 87 password_protection_service_->GetSettingMapForActiveProfile(), | |
| 88 main_frame_url_, cached_response.get()); | 87 main_frame_url_, cached_response.get()); |
| 89 if (verdict != LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED) | 88 if (verdict != LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED) |
| 90 Finish(RequestOutcome::RESPONSE_ALREADY_CACHED, std::move(cached_response)); | 89 Finish(RequestOutcome::RESPONSE_ALREADY_CACHED, std::move(cached_response)); |
| 91 else | 90 else |
| 92 SendRequest(); | 91 SendRequest(); |
| 93 } | 92 } |
| 94 | 93 |
| 94 void PasswordProtectionRequest::FillRequestProto() { | |
| 95 request_proto_ = base::MakeUnique<LoginReputationClientRequest>(); | |
| 96 request_proto_->set_page_url(main_frame_url_.spec()); | |
| 97 request_proto_->set_trigger_type(request_type_); | |
| 98 request_proto_->set_stored_verdict_cnt( | |
| 99 password_protection_service_->GetStoredVerdictCount()); | |
| 100 LoginReputationClientRequest::Frame* main_frame = | |
| 101 request_proto_->add_frames(); | |
| 102 main_frame->set_url(main_frame_url_.spec()); | |
| 103 password_protection_service_->FillReferrerChain(main_frame_url_, -1, | |
|
Nathan Parker
2017/03/30 21:38:12
Is there a TODO here to add other iframes? Or wou
Jialiu Lin
2017/03/30 23:23:05
Added a TODO
| |
| 104 main_frame); | |
| 105 } | |
| 106 | |
| 95 void PasswordProtectionRequest::SendRequest() { | 107 void PasswordProtectionRequest::SendRequest() { |
| 96 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 108 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 97 | 109 FillRequestProto(); |
| 98 LoginReputationClientRequest request; | |
| 99 request.set_page_url(main_frame_url_.spec()); | |
| 100 request.set_trigger_type(request_type_); | |
| 101 request.set_stored_verdict_cnt( | |
| 102 password_protection_service_->GetStoredVerdictCount()); | |
| 103 | 110 |
| 104 std::string serialized_request; | 111 std::string serialized_request; |
| 105 if (!request.SerializeToString(&serialized_request)) { | 112 if (!request_proto_->SerializeToString(&serialized_request)) { |
| 106 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr); | 113 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr); |
| 107 return; | 114 return; |
| 108 } | 115 } |
| 109 | 116 |
| 110 // In case the request take too long, we set a timer to cancel this request. | 117 // In case the request take too long, we set a timer to cancel this request. |
| 111 StartTimeout(); | 118 StartTimeout(); |
| 112 | 119 |
| 113 fetcher_ = net::URLFetcher::Create( | 120 fetcher_ = net::URLFetcher::Create( |
| 114 0, PasswordProtectionService::GetPasswordProtectionRequestUrl(), | 121 0, PasswordProtectionService::GetPasswordProtectionRequestUrl(), |
| 115 net::URLFetcher::POST, this); | 122 net::URLFetcher::POST, this); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 } | 207 } |
| 201 | 208 |
| 202 void PasswordProtectionRequest::Cancel(bool timed_out) { | 209 void PasswordProtectionRequest::Cancel(bool timed_out) { |
| 203 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 210 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 204 fetcher_.reset(); | 211 fetcher_.reset(); |
| 205 | 212 |
| 206 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr); | 213 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr); |
| 207 } | 214 } |
| 208 | 215 |
| 209 } // namespace safe_browsing | 216 } // namespace safe_browsing |
| OLD | NEW |