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

Side by Side Diff: chrome/browser/safe_browsing/client_side_detection_service.cc

Issue 4808003: Fix Valgrind errors that occurred during testing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge. Created 10 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_detection_service.h" 5 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util_proxy.h" 9 #include "base/file_util_proxy.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 20 matching lines...) Expand all
31 "https://sb-ssl.google.com/safebrowsing/clientreport/phishing"; 31 "https://sb-ssl.google.com/safebrowsing/clientreport/phishing";
32 const char ClientSideDetectionService::kClientModelUrl[] = 32 const char ClientSideDetectionService::kClientModelUrl[] =
33 "https://ssl.gstatic.com/safebrowsing/csd/client_model_v0.pb"; 33 "https://ssl.gstatic.com/safebrowsing/csd/client_model_v0.pb";
34 34
35 ClientSideDetectionService::ClientSideDetectionService( 35 ClientSideDetectionService::ClientSideDetectionService(
36 const FilePath& model_path, 36 const FilePath& model_path,
37 URLRequestContextGetter* request_context_getter) 37 URLRequestContextGetter* request_context_getter)
38 : model_path_(model_path), 38 : model_path_(model_path),
39 model_status_(UNKNOWN_STATUS), 39 model_status_(UNKNOWN_STATUS),
40 model_file_(base::kInvalidPlatformFileValue), 40 model_file_(base::kInvalidPlatformFileValue),
41 model_fetcher_(NULL),
41 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 42 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
42 request_context_getter_(request_context_getter) { 43 request_context_getter_(request_context_getter) {
43 } 44 }
44 45
45 ClientSideDetectionService::~ClientSideDetectionService() { 46 ClientSideDetectionService::~ClientSideDetectionService() {
46 method_factory_.RevokeAll(); 47 method_factory_.RevokeAll();
47 STLDeleteContainerPairPointers(client_phishing_reports_.begin(), 48 STLDeleteContainerPairPointers(client_phishing_reports_.begin(),
48 client_phishing_reports_.end()); 49 client_phishing_reports_.end());
49 client_phishing_reports_.clear(); 50 client_phishing_reports_.clear();
50 model_fetcher_.reset();
51 STLDeleteElements(&open_callbacks_); 51 STLDeleteElements(&open_callbacks_);
52 CloseModelFile(); 52 CloseModelFile();
53 } 53 }
54 54
55 /* static */ 55 /* static */
56 ClientSideDetectionService* ClientSideDetectionService::Create( 56 ClientSideDetectionService* ClientSideDetectionService::Create(
57 const FilePath& model_path, 57 const FilePath& model_path,
58 URLRequestContextGetter* request_context_getter) { 58 URLRequestContextGetter* request_context_getter) {
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
60 scoped_ptr<ClientSideDetectionService> service( 60 scoped_ptr<ClientSideDetectionService> service(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 phishing_url, score, thumbnail, callback)); 95 phishing_url, score, thumbnail, callback));
96 } 96 }
97 97
98 void ClientSideDetectionService::OnURLFetchComplete( 98 void ClientSideDetectionService::OnURLFetchComplete(
99 const URLFetcher* source, 99 const URLFetcher* source,
100 const GURL& url, 100 const GURL& url,
101 const URLRequestStatus& status, 101 const URLRequestStatus& status,
102 int response_code, 102 int response_code,
103 const ResponseCookies& cookies, 103 const ResponseCookies& cookies,
104 const std::string& data) { 104 const std::string& data) {
105 if (source == model_fetcher_.get()) { 105 if (source == model_fetcher_) {
106 HandleModelResponse(source, url, status, response_code, cookies, data); 106 HandleModelResponse(source, url, status, response_code, cookies, data);
107 // The fetcher object will be invalid after this method returns.
108 model_fetcher_ = NULL;
107 } else if (client_phishing_reports_.find(source) != 109 } else if (client_phishing_reports_.find(source) !=
108 client_phishing_reports_.end()) { 110 client_phishing_reports_.end()) {
109 HandlePhishingVerdict(source, url, status, response_code, cookies, data); 111 HandlePhishingVerdict(source, url, status, response_code, cookies, data);
110 } else { 112 } else {
111 NOTREACHED(); 113 NOTREACHED();
112 } 114 }
115 delete source;
113 } 116 }
114 117
115 void ClientSideDetectionService::SetModelStatus(ModelStatus status) { 118 void ClientSideDetectionService::SetModelStatus(ModelStatus status) {
116 DCHECK_NE(READY_STATUS, model_status_); 119 DCHECK_NE(READY_STATUS, model_status_);
117 model_status_ = status; 120 model_status_ = status;
118 if (READY_STATUS == status || ERROR_STATUS == status) { 121 if (READY_STATUS == status || ERROR_STATUS == status) {
119 for (size_t i = 0; i < open_callbacks_.size(); ++i) { 122 for (size_t i = 0; i < open_callbacks_.size(); ++i) {
120 open_callbacks_[i]->Run(model_file_); 123 open_callbacks_[i]->Run(model_file_);
121 } 124 }
122 STLDeleteElements(&open_callbacks_); 125 STLDeleteElements(&open_callbacks_);
123 } else { 126 } else {
124 NOTREACHED(); 127 NOTREACHED();
125 } 128 }
126 } 129 }
127 130
128 void ClientSideDetectionService::OpenModelFileDone( 131 void ClientSideDetectionService::OpenModelFileDone(
129 base::PlatformFileError error_code, 132 base::PlatformFileError error_code,
130 base::PassPlatformFile file, 133 base::PassPlatformFile file,
131 bool created) { 134 bool created) {
132 DCHECK(!created); 135 DCHECK(!created);
133 if (base::PLATFORM_FILE_OK == error_code) { 136 if (base::PLATFORM_FILE_OK == error_code) {
134 // The model file already exists. There is no need to fetch the model. 137 // The model file already exists. There is no need to fetch the model.
135 model_file_ = file.ReleaseValue(); 138 model_file_ = file.ReleaseValue();
136 SetModelStatus(READY_STATUS); 139 SetModelStatus(READY_STATUS);
137 } else if (base::PLATFORM_FILE_ERROR_NOT_FOUND == error_code) { 140 } else if (base::PLATFORM_FILE_ERROR_NOT_FOUND == error_code) {
138 // We need to fetch the model since it does not exist yet. 141 // We need to fetch the model since it does not exist yet.
139 model_fetcher_.reset(URLFetcher::Create(0 /* ID is not used */, 142 model_fetcher_ = URLFetcher::Create(0 /* ID is not used */,
140 GURL(kClientModelUrl), 143 GURL(kClientModelUrl),
141 URLFetcher::GET, 144 URLFetcher::GET,
142 this)); 145 this);
143 model_fetcher_->set_request_context(request_context_getter_.get()); 146 model_fetcher_->set_request_context(request_context_getter_.get());
144 model_fetcher_->Start(); 147 model_fetcher_->Start();
145 } else { 148 } else {
146 // It is not clear what we should do in this case. For now we simply fail. 149 // It is not clear what we should do in this case. For now we simply fail.
147 // Hopefully, we'll be able to read the model during the next browser 150 // Hopefully, we'll be able to read the model during the next browser
148 // restart. 151 // restart.
149 SetModelStatus(ERROR_STATUS); 152 SetModelStatus(ERROR_STATUS);
150 } 153 }
151 } 154 }
152 155
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 info->callback->Run(info->phishing_url, response.phishy()); 309 info->callback->Run(info->phishing_url, response.phishy());
307 } else { 310 } else {
308 DLOG(ERROR) << "Unable to get the server verdict for URL: " 311 DLOG(ERROR) << "Unable to get the server verdict for URL: "
309 << info->phishing_url; 312 << info->phishing_url;
310 info->callback->Run(info->phishing_url, false); 313 info->callback->Run(info->phishing_url, false);
311 } 314 }
312 client_phishing_reports_.erase(source); 315 client_phishing_reports_.erase(source);
313 } 316 }
314 317
315 } // namespace safe_browsing 318 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698