| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/download/file_metadata_linux.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 #include <sys/types.h> | |
| 9 #include <sys/xattr.h> | |
| 10 | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "base/files/file_util.h" | |
| 13 #include "base/logging.h" | |
| 14 #include "url/gurl.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 const char kSourceURLAttrName[] = "user.xdg.origin.url"; | |
| 19 const char kReferrerURLAttrName[] = "user.xdg.referrer.url"; | |
| 20 | |
| 21 static void SetExtendedFileAttribute(const char* path, const char* name, | |
| 22 const char* value, size_t value_size, | |
| 23 int flags) { | |
| 24 int result = setxattr(path, name, value, value_size, flags); | |
| 25 if (result) { | |
| 26 DPLOG(ERROR) | |
| 27 << "Could not set extended attribute " << name << " on file " << path; | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 void AddOriginMetadataToFile(const base::FilePath& file, const GURL& source, | |
| 32 const GURL& referrer) { | |
| 33 DCHECK(base::PathIsWritable(file)); | |
| 34 if (source.is_valid()) { | |
| 35 SetExtendedFileAttribute(file.value().c_str(), kSourceURLAttrName, | |
| 36 source.spec().c_str(), source.spec().length(), 0); | |
| 37 } | |
| 38 if (referrer.is_valid()) { | |
| 39 SetExtendedFileAttribute(file.value().c_str(), kReferrerURLAttrName, | |
| 40 referrer.spec().c_str(), referrer.spec().length(), 0); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 } // namespace content | |
| OLD | NEW |