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.
5 #include "content/browser/download/file_metadata_linux.h"
10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h"
12 #include "base/logging.h"
17 const char kSourceURLAttrName
[] = "user.xdg.origin.url";
18 const char kReferrerURLAttrName
[] = "user.xdg.referrer.url";
20 static void SetExtendedFileAttribute(const char* path
, const char* name
,
21 const char* value
, size_t value_size
,
23 int result
= setxattr(path
, name
, value
, value_size
, flags
);
26 << "Could not set extended attribute " << name
<< " on file " << path
;
30 void AddOriginMetadataToFile(const base::FilePath
& file
, const GURL
& source
,
31 const GURL
& referrer
) {
32 DCHECK(base::PathIsWritable(file
));
33 if (source
.is_valid()) {
34 SetExtendedFileAttribute(file
.value().c_str(), kSourceURLAttrName
,
35 source
.spec().c_str(), source
.spec().length(), 0);
37 if (referrer
.is_valid()) {
38 SetExtendedFileAttribute(file
.value().c_str(), kReferrerURLAttrName
,
39 referrer
.spec().c_str(), referrer
.spec().length(), 0);
43 } // namespace content