Chromium Code Reviews| Index: components/safe_browsing_db/v4_update_protocol_manager.cc |
| diff --git a/components/safe_browsing_db/v4_update_protocol_manager.cc b/components/safe_browsing_db/v4_update_protocol_manager.cc |
| index dca44a7424e1fc0553e13cca7ebda13924c2a132..1219b3636a96d4e35d6162341f5da2f01a2d3201 100644 |
| --- a/components/safe_browsing_db/v4_update_protocol_manager.cc |
| +++ b/components/safe_browsing_db/v4_update_protocol_manager.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/base64.h" |
| #include "base/macros.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/metrics/histogram_macros.h" |
| #include "base/rand_util.h" |
| #include "base/timer/timer.h" |
| @@ -222,7 +223,7 @@ std::string V4UpdateProtocolManager::GetBase64SerializedUpdateRequestProto( |
| bool V4UpdateProtocolManager::ParseUpdateResponse( |
| const std::string& data, |
| - std::vector<ListUpdateResponse>* list_update_responses) { |
| + ParsedServerResponse* parsed_server_response) { |
| FetchThreatListUpdatesResponse response; |
| if (!response.ParseFromString(data)) { |
| @@ -244,8 +245,8 @@ bool V4UpdateProtocolManager::ParseUpdateResponse( |
| } |
| // TODO(vakh): Do something useful with this response. |
| - for (const ListUpdateResponse& list_update_response : |
| - response.list_update_responses()) { |
| + for (ListUpdateResponse list_update_response : |
| + *response.mutable_list_update_responses()) { |
| if (!list_update_response.has_platform_type()) { |
| RecordParseUpdateResult(NO_PLATFORM_TYPE_ERROR); |
| } else if (!list_update_response.has_threat_entry_type()) { |
| @@ -255,7 +256,8 @@ bool V4UpdateProtocolManager::ParseUpdateResponse( |
| } else if (!list_update_response.has_new_client_state()) { |
| RecordParseUpdateResult(NO_STATE_ERROR); |
| } else { |
| - list_update_responses->push_back(list_update_response); |
| + ListUpdateResponse* add = new ListUpdateResponse(list_update_response); |
|
Scott Hess - ex-Googler
2016/06/28 03:58:43
Don't leave a gap where the pointer is raw, unique
vakh (use Gerrit instead)
2016/06/28 21:34:14
Done.
|
| + parsed_server_response->push_back(base::WrapUnique(add)); |
| } |
| } |
| return true; |
| @@ -302,14 +304,15 @@ void V4UpdateProtocolManager::OnURLFetchComplete( |
| last_response_time_ = Time::Now(); |
| - std::vector<ListUpdateResponse> list_update_responses; |
| + std::unique_ptr<ParsedServerResponse> parsed_server_response( |
| + new ParsedServerResponse); |
| if (status.is_success() && response_code == net::HTTP_OK) { |
| RecordUpdateResult(V4OperationResult::STATUS_200); |
| ResetUpdateErrors(); |
| std::string data; |
| source->GetResponseAsString(&data); |
| - if (!ParseUpdateResponse(data, &list_update_responses)) { |
| - list_update_responses.clear(); |
| + if (!ParseUpdateResponse(data, parsed_server_response.get())) { |
| + parsed_server_response->clear(); |
| RecordUpdateResult(V4OperationResult::PARSE_ERROR); |
| } |
| request_.reset(); |
| @@ -317,11 +320,10 @@ void V4UpdateProtocolManager::OnURLFetchComplete( |
| UMA_HISTOGRAM_COUNTS("SafeBrowsing.V4UpdateResponseSizeKB", |
| data.size() / 1024); |
| - // Invoke the callback with list_update_responses. |
| - // The caller should update its state now, based on list_update_responses. |
| + // The caller should update its state now, based on parsed_server_response. |
| // The callback must call ScheduleNextUpdate() at the end to resume |
| // downloading updates. |
| - update_callback_.Run(list_update_responses); |
| + update_callback_.Run(std::move(parsed_server_response)); |
| } else { |
| DVLOG(1) << "SafeBrowsing GetEncodedUpdates request for: " |
| << source->GetURL() << " failed with error: " << status.error() |