Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(869)

Side by Side Diff: components/safe_browsing/password_protection/password_protection_request.cc

Issue 2783773002: Link PasswordProtectionService to Profile and SB Service (Closed)
Patch Set: refine histogram description Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(
104 main_frame_url_, -1 /* tab id not available */, main_frame);
105 // TODO(jialiul): Add sub-frame information and password form information.
106 }
107
95 void PasswordProtectionRequest::SendRequest() { 108 void PasswordProtectionRequest::SendRequest() {
96 DCHECK_CURRENTLY_ON(BrowserThread::UI); 109 DCHECK_CURRENTLY_ON(BrowserThread::UI);
97 110 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 111
104 std::string serialized_request; 112 std::string serialized_request;
105 if (!request.SerializeToString(&serialized_request)) { 113 if (!request_proto_->SerializeToString(&serialized_request)) {
106 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr); 114 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr);
107 return; 115 return;
108 } 116 }
109 117
110 // In case the request take too long, we set a timer to cancel this request. 118 // In case the request take too long, we set a timer to cancel this request.
111 StartTimeout(); 119 StartTimeout();
112 120
113 fetcher_ = net::URLFetcher::Create( 121 fetcher_ = net::URLFetcher::Create(
114 0, PasswordProtectionService::GetPasswordProtectionRequestUrl(), 122 0, PasswordProtectionService::GetPasswordProtectionRequestUrl(),
115 net::URLFetcher::POST, this); 123 net::URLFetcher::POST, this);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 208 }
201 209
202 void PasswordProtectionRequest::Cancel(bool timed_out) { 210 void PasswordProtectionRequest::Cancel(bool timed_out) {
203 DCHECK_CURRENTLY_ON(BrowserThread::UI); 211 DCHECK_CURRENTLY_ON(BrowserThread::UI);
204 fetcher_.reset(); 212 fetcher_.reset();
205 213
206 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr); 214 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr);
207 } 215 }
208 216
209 } // namespace safe_browsing 217 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698