| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/safe_browsing/client_side_model_loader.h" | 5 #include "chrome/browser/safe_browsing/client_side_model_loader.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "chrome/browser/safe_browsing/protocol_manager.h" | 16 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/safe_browsing/client_model.pb.h" | 18 #include "chrome/common/safe_browsing/client_model.pb.h" |
| 18 #include "chrome/common/safe_browsing/csd.pb.h" | 19 #include "chrome/common/safe_browsing/csd.pb.h" |
| 19 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 20 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 const int response_code = source->GetResponseCode(); | 130 const int response_code = source->GetResponseCode(); |
| 130 SafeBrowsingProtocolManager::RecordHttpResponseOrErrorCode( | 131 SafeBrowsingProtocolManager::RecordHttpResponseOrErrorCode( |
| 131 kUmaModelDownloadResponseMetricName, status, response_code); | 132 kUmaModelDownloadResponseMetricName, status, response_code); |
| 132 | 133 |
| 133 // max_age is valid iff !0. | 134 // max_age is valid iff !0. |
| 134 base::TimeDelta max_age; | 135 base::TimeDelta max_age; |
| 135 if (is_success && net::HTTP_OK == response_code && | 136 if (is_success && net::HTTP_OK == response_code && |
| 136 source->GetResponseHeaders()) { | 137 source->GetResponseHeaders()) { |
| 137 source->GetResponseHeaders()->GetMaxAgeValue(&max_age); | 138 source->GetResponseHeaders()->GetMaxAgeValue(&max_age); |
| 138 } | 139 } |
| 139 scoped_ptr<ClientSideModel> model(new ClientSideModel()); | 140 std::unique_ptr<ClientSideModel> model(new ClientSideModel()); |
| 140 ClientModelStatus model_status; | 141 ClientModelStatus model_status; |
| 141 if (!is_success || net::HTTP_OK != response_code) { | 142 if (!is_success || net::HTTP_OK != response_code) { |
| 142 model_status = MODEL_FETCH_FAILED; | 143 model_status = MODEL_FETCH_FAILED; |
| 143 } else if (data.empty()) { | 144 } else if (data.empty()) { |
| 144 model_status = MODEL_EMPTY; | 145 model_status = MODEL_EMPTY; |
| 145 } else if (data.size() > kMaxModelSizeBytes) { | 146 } else if (data.size() > kMaxModelSizeBytes) { |
| 146 model_status = MODEL_TOO_LARGE; | 147 model_status = MODEL_TOO_LARGE; |
| 147 } else if (!model->ParseFromString(data)) { | 148 } else if (!model->ParseFromString(data)) { |
| 148 model_status = MODEL_PARSE_ERROR; | 149 model_status = MODEL_PARSE_ERROR; |
| 149 } else if (!model->IsInitialized() || !model->has_version()) { | 150 } else if (!model->IsInitialized() || !model->has_version()) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } | 199 } |
| 199 | 200 |
| 200 void ModelLoader::CancelFetcher() { | 201 void ModelLoader::CancelFetcher() { |
| 201 // Invalidate any scheduled request. | 202 // Invalidate any scheduled request. |
| 202 weak_factory_.InvalidateWeakPtrs(); | 203 weak_factory_.InvalidateWeakPtrs(); |
| 203 // Cancel any request in progress. | 204 // Cancel any request in progress. |
| 204 fetcher_.reset(); | 205 fetcher_.reset(); |
| 205 } | 206 } |
| 206 | 207 |
| 207 } // namespace safe_browsing | 208 } // namespace safe_browsing |
| OLD | NEW |