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

Side by Side Diff: content/browser/download/file_metadata_linux.cc

Issue 2123023002: [Downloads] Consolidate MOTW annotation APIs into a single API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-safe-util-to-downloads
Patch Set: [win] Verify that the Zone.Identifier stream has the correct contents. Created 4 years, 3 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
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698