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