1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/safe_browsing/path_sanitizer.h" 6 7 #include "base/logging.h" 8 #include "base/path_service.h" 9 10 namespace safe_browsing { 11 12 PathSanitizer::PathSanitizer() { 13 // Get the home directory path. 14 if (!PathService::Get(base::DIR_HOME, &home_path_)) 15 NOTREACHED(); 16 } 17 18 const base::FilePath& PathSanitizer::GetHomeDirectory() const { 19 return home_path_; 20 } 21 22 void PathSanitizer::StripHomeDirectory(base::FilePath* file_path) const { 23 base::FilePath sanitized_path(FILE_PATH_LITERAL("~")); 24 25 // The |file_path| is overwritten only if a relative path is found. 26 if (home_path_.AppendRelativePath(*file_path, &sanitized_path)) 27 *file_path = sanitized_path; 28 } 29 30 } // namespace safe_browsing 31