Extract SIGPIPE ignoring code to a common place.
[chromium-blink-merge.git] / chrome / common / extensions / extension_resource.h
blob36d8218c040a0de979ec4d4b4087aa2b69776942
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 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_
8 #include <string>
10 #include "base/file_path.h"
12 // Represents a resource inside an extension. For example, an image, or a
13 // JavaScript file. This is more complicated than just a simple FilePath
14 // because extension resources can come from multiple physical file locations
15 // depending on locale.
16 class ExtensionResource {
17 public:
18 // SymlinkPolicy decides whether we'll allow resources to be a symlink to
19 // anywhere, or whether they must end up within the extension root.
20 enum SymlinkPolicy {
21 SYMLINKS_MUST_RESOLVE_WITHIN_ROOT,
22 FOLLOW_SYMLINKS_ANYWHERE,
25 ExtensionResource();
27 ExtensionResource(const std::string& extension_id,
28 const FilePath& extension_root,
29 const FilePath& relative_path);
31 ~ExtensionResource();
33 // set_follow_symlinks_anywhere allows the resource to be a symlink to
34 // anywhere in the filesystem. By default, resources have to be within
35 // |extension_root| after resolving symlinks.
36 void set_follow_symlinks_anywhere();
38 // Returns actual path to the resource (default or locale specific). In the
39 // browser process, this will DCHECK if not called on the file thread. To
40 // easily load extension images on the UI thread, see ImageLoadingTracker.
41 const FilePath& GetFilePath() const;
43 // Gets the physical file path for the extension resource, taking into account
44 // localization. In the browser process, this will DCHECK if not called on the
45 // file thread. To easily load extension images on the UI thread, see
46 // ImageLoadingTracker.
48 // The relative path must not resolve to a location outside of
49 // |extension_root|. Iff |file_can_symlink_outside_root| is true, then the
50 // file can be a symlink that links outside of |extension_root|.
51 static FilePath GetFilePath(const FilePath& extension_root,
52 const FilePath& relative_path,
53 SymlinkPolicy symlink_policy);
55 // Getters
56 const std::string& extension_id() const { return extension_id_; }
57 const FilePath& extension_root() const { return extension_root_; }
58 const FilePath& relative_path() const { return relative_path_; }
60 bool empty() const { return extension_root().empty(); }
62 // Unit test helpers.
63 FilePath::StringType NormalizeSeperators(
64 const FilePath::StringType& path) const;
65 bool ComparePathWithDefault(const FilePath& path) const;
67 private:
68 // The id of the extension that this resource is associated with.
69 std::string extension_id_;
71 // Extension root.
72 FilePath extension_root_;
74 // Relative path to resource.
75 FilePath relative_path_;
77 // If |follow_symlinks_anywhere_| is true then the resource itself must be
78 // within |extension_root|, but it can be a symlink to a file that is not.
79 bool follow_symlinks_anywhere_;
81 // Full path to extension resource. Starts empty.
82 mutable FilePath full_resource_path_;
85 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_