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

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

Issue 6286038: Add initial code to do filename munging in the FileSystem.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 /* static */ 61 /* static */
62 ClientSideDetectionService* ClientSideDetectionService::Create( 62 ClientSideDetectionService* ClientSideDetectionService::Create(
63 const FilePath& model_path, 63 const FilePath& model_path,
64 URLRequestContextGetter* request_context_getter) { 64 URLRequestContextGetter* request_context_getter) {
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
66 scoped_ptr<ClientSideDetectionService> service( 66 scoped_ptr<ClientSideDetectionService> service(
67 new ClientSideDetectionService(model_path, request_context_getter)); 67 new ClientSideDetectionService(model_path, request_context_getter));
68 // We try to open the model file right away and start fetching it if 68 // We try to open the model file right away and start fetching it if
69 // it does not already exist on disk. 69 // it does not already exist on disk.
70 base::FileUtilProxy::CreateOrOpenCallback* cb = 70 base::FileUtilProxyBase::CreateOrOpenCallback* cb =
71 service.get()->callback_factory_.NewCallback( 71 service.get()->callback_factory_.NewCallback(
72 &ClientSideDetectionService::OpenModelFileDone); 72 &ClientSideDetectionService::OpenModelFileDone);
73 if (!base::FileUtilProxy::CreateOrOpen( 73 if (!base::FileUtilProxy::GetInstance()->CreateOrOpen(
74 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 74 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
75 model_path, 75 model_path,
76 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, 76 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
77 cb)) { 77 cb)) {
78 delete cb; 78 delete cb;
79 return NULL; 79 return NULL;
80 } 80 }
81 return service.release(); 81 return service.release();
82 } 82 }
83 83
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // restart. 154 // restart.
155 SetModelStatus(ERROR_STATUS); 155 SetModelStatus(ERROR_STATUS);
156 } 156 }
157 } 157 }
158 158
159 void ClientSideDetectionService::CreateModelFileDone( 159 void ClientSideDetectionService::CreateModelFileDone(
160 base::PlatformFileError error_code, 160 base::PlatformFileError error_code,
161 base::PassPlatformFile file, 161 base::PassPlatformFile file,
162 bool created) { 162 bool created) {
163 model_file_ = file.ReleaseValue(); 163 model_file_ = file.ReleaseValue();
164 base::FileUtilProxy::ReadWriteCallback* cb = callback_factory_.NewCallback( 164 base::FileUtilProxyBase::ReadWriteCallback* cb =
165 &ClientSideDetectionService::WriteModelFileDone); 165 callback_factory_.NewCallback(
166 &ClientSideDetectionService::WriteModelFileDone);
166 if (!created || 167 if (!created ||
167 base::PLATFORM_FILE_OK != error_code || 168 base::PLATFORM_FILE_OK != error_code ||
168 !base::FileUtilProxy::Write( 169 !base::FileUtilProxy::GetInstance()->Write(
169 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 170 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
170 model_file_, 171 model_file_,
171 0 /* offset */, tmp_model_string_->data(), tmp_model_string_->size(), 172 0 /* offset */, tmp_model_string_->data(), tmp_model_string_->size(),
172 cb)) { 173 cb)) {
173 delete cb; 174 delete cb;
174 // An error occurred somewhere. We close the model file if necessary and 175 // An error occurred somewhere. We close the model file if necessary and
175 // then run all the pending callbacks giving them an invalid model file. 176 // then run all the pending callbacks giving them an invalid model file.
176 CloseModelFile(); 177 CloseModelFile();
177 SetModelStatus(ERROR_STATUS); 178 SetModelStatus(ERROR_STATUS);
178 } 179 }
(...skipping 10 matching lines...) Expand all
189 CloseModelFile(); 190 CloseModelFile();
190 SetModelStatus(ERROR_STATUS); 191 SetModelStatus(ERROR_STATUS);
191 } 192 }
192 // Delete the model string that we kept around while we were writing the 193 // Delete the model string that we kept around while we were writing the
193 // string to disk - we don't need it anymore. 194 // string to disk - we don't need it anymore.
194 tmp_model_string_.reset(); 195 tmp_model_string_.reset();
195 } 196 }
196 197
197 void ClientSideDetectionService::CloseModelFile() { 198 void ClientSideDetectionService::CloseModelFile() {
198 if (model_file_ != base::kInvalidPlatformFileValue) { 199 if (model_file_ != base::kInvalidPlatformFileValue) {
199 base::FileUtilProxy::Close( 200 base::FileUtilProxy::GetInstance()->Close(
200 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 201 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
201 model_file_, 202 model_file_,
202 NULL); 203 NULL);
203 } 204 }
204 model_file_ = base::kInvalidPlatformFileValue; 205 model_file_ = base::kInvalidPlatformFileValue;
205 } 206 }
206 207
207 void ClientSideDetectionService::StartGetModelFile( 208 void ClientSideDetectionService::StartGetModelFile(
208 OpenModelDoneCallback* callback) { 209 OpenModelDoneCallback* callback) {
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 const net::URLRequestStatus& status, 273 const net::URLRequestStatus& status,
273 int response_code, 274 int response_code,
274 const ResponseCookies& cookies, 275 const ResponseCookies& cookies,
275 const std::string& data) { 276 const std::string& data) {
276 if (status.is_success() && RC_REQUEST_OK == response_code) { 277 if (status.is_success() && RC_REQUEST_OK == response_code) {
277 // Copy the model because it has to be accessible after this function 278 // Copy the model because it has to be accessible after this function
278 // returns. Once we have written the model to a file we will delete the 279 // returns. Once we have written the model to a file we will delete the
279 // temporary model string. TODO(noelutz): don't store the model to disk if 280 // temporary model string. TODO(noelutz): don't store the model to disk if
280 // it's invalid. 281 // it's invalid.
281 tmp_model_string_.reset(new std::string(data)); 282 tmp_model_string_.reset(new std::string(data));
282 base::FileUtilProxy::CreateOrOpenCallback* cb = 283 base::FileUtilProxyBase::CreateOrOpenCallback* cb =
283 callback_factory_.NewCallback( 284 callback_factory_.NewCallback(
284 &ClientSideDetectionService::CreateModelFileDone); 285 &ClientSideDetectionService::CreateModelFileDone);
285 if (!base::FileUtilProxy::CreateOrOpen( 286 if (!base::FileUtilProxy::GetInstance()->CreateOrOpen(
286 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 287 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
287 model_path_, 288 model_path_,
288 base::PLATFORM_FILE_CREATE_ALWAYS | 289 base::PLATFORM_FILE_CREATE_ALWAYS |
289 base::PLATFORM_FILE_WRITE | 290 base::PLATFORM_FILE_WRITE |
290 base::PLATFORM_FILE_READ, 291 base::PLATFORM_FILE_READ,
291 cb)) { 292 cb)) {
292 delete cb; 293 delete cb;
293 SetModelStatus(ERROR_STATUS); 294 SetModelStatus(ERROR_STATUS);
294 } 295 }
295 } else { 296 } else {
(...skipping 30 matching lines...) Expand all
326 while (!phishing_report_times_.empty() && 327 while (!phishing_report_times_.empty() &&
327 phishing_report_times_.front() < cutoff) { 328 phishing_report_times_.front() < cutoff) {
328 phishing_report_times_.pop(); 329 phishing_report_times_.pop();
329 } 330 }
330 331
331 // Return the number of elements that are above the cutoff. 332 // Return the number of elements that are above the cutoff.
332 return phishing_report_times_.size(); 333 return phishing_report_times_.size();
333 } 334 }
334 335
335 } // namespace safe_browsing 336 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698