| 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> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "chrome/browser/safe_browsing/protocol_manager.h" | 18 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/safe_browsing/client_model.pb.h" | 20 #include "chrome/common/safe_browsing/client_model.pb.h" |
| 21 #include "chrome/common/safe_browsing/csd.pb.h" | 21 #include "chrome/common/safe_browsing/csd.pb.h" |
| 22 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 22 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
| 23 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 23 #include "components/variations/variations_associated_data.h" | 24 #include "components/variations/variations_associated_data.h" |
| 24 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
| 25 #include "net/http/http_status_code.h" | 26 #include "net/http/http_status_code.h" |
| 26 #include "net/url_request/url_fetcher.h" | 27 #include "net/url_request/url_fetcher.h" |
| 27 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
| 28 #include "net/url_request/url_request_status.h" | 29 #include "net/url_request/url_request_status.h" |
| 29 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 30 | 31 |
| 31 namespace safe_browsing { | 32 namespace safe_browsing { |
| 32 | 33 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 111 |
| 111 void ModelLoader::StartFetch() { | 112 void ModelLoader::StartFetch() { |
| 112 // Start fetching the model either from the cache or possibly from the | 113 // Start fetching the model either from the cache or possibly from the |
| 113 // network if the model isn't in the cache. | 114 // network if the model isn't in the cache. |
| 114 | 115 |
| 115 // TODO(nparker): If no profile needs this model, we shouldn't fetch it. | 116 // TODO(nparker): If no profile needs this model, we shouldn't fetch it. |
| 116 // Then only re-fetch when a profile setting changes to need it. | 117 // Then only re-fetch when a profile setting changes to need it. |
| 117 // This will save on the order of ~50KB/week/client of bandwidth. | 118 // This will save on the order of ~50KB/week/client of bandwidth. |
| 118 fetcher_ = net::URLFetcher::Create(0 /* ID used for testing */, url_, | 119 fetcher_ = net::URLFetcher::Create(0 /* ID used for testing */, url_, |
| 119 net::URLFetcher::GET, this); | 120 net::URLFetcher::GET, this); |
| 121 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 122 fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); |
| 120 fetcher_->SetRequestContext(request_context_getter_); | 123 fetcher_->SetRequestContext(request_context_getter_); |
| 121 fetcher_->Start(); | 124 fetcher_->Start(); |
| 122 } | 125 } |
| 123 | 126 |
| 124 void ModelLoader::OnURLFetchComplete(const net::URLFetcher* source) { | 127 void ModelLoader::OnURLFetchComplete(const net::URLFetcher* source) { |
| 125 DCHECK_EQ(fetcher_.get(), source); | 128 DCHECK_EQ(fetcher_.get(), source); |
| 126 DCHECK_EQ(url_, source->GetURL()); | 129 DCHECK_EQ(url_, source->GetURL()); |
| 127 | 130 |
| 128 std::string data; | 131 std::string data; |
| 129 source->GetResponseAsString(&data); | 132 source->GetResponseAsString(&data); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 204 } |
| 202 | 205 |
| 203 void ModelLoader::CancelFetcher() { | 206 void ModelLoader::CancelFetcher() { |
| 204 // Invalidate any scheduled request. | 207 // Invalidate any scheduled request. |
| 205 weak_factory_.InvalidateWeakPtrs(); | 208 weak_factory_.InvalidateWeakPtrs(); |
| 206 // Cancel any request in progress. | 209 // Cancel any request in progress. |
| 207 fetcher_.reset(); | 210 fetcher_.reset(); |
| 208 } | 211 } |
| 209 | 212 |
| 210 } // namespace safe_browsing | 213 } // namespace safe_browsing |
| OLD | NEW |