| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_ |
| 7 | 7 |
| 8 #include <string> |
| 9 |
| 8 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 9 #include "base/platform_thread.h" | 11 #include "base/platform_thread.h" |
| 10 | 12 |
| 11 // Represents a resource inside an extension. For example, an image, or a | 13 // Represents a resource inside an extension. For example, an image, or a |
| 12 // JavaScript file. This is more complicated than just a simple FilePath | 14 // JavaScript file. This is more complicated than just a simple FilePath |
| 13 // because extension resources can come from multiple physical file locations | 15 // because extension resources can come from multiple physical file locations |
| 14 // depending on locale. | 16 // depending on locale. |
| 15 class ExtensionResource { | 17 class ExtensionResource { |
| 16 public: | 18 public: |
| 17 ExtensionResource(); | 19 ExtensionResource(); |
| 18 | 20 |
| 19 ExtensionResource(const FilePath& extension_root, | 21 ExtensionResource(const std::string& extension_id, |
| 22 const FilePath& extension_root, |
| 20 const FilePath& relative_path); | 23 const FilePath& relative_path); |
| 21 | 24 |
| 22 // Returns actual path to the resource (default or locale specific). In the | 25 // Returns actual path to the resource (default or locale specific). In the |
| 23 // browser process, this will DCHECK if not called on the file thread. To | 26 // browser process, this will DCHECK if not called on the file thread. To |
| 24 // easily load extension images on the UI thread, see ImageLoadingTracker. | 27 // easily load extension images on the UI thread, see ImageLoadingTracker. |
| 25 const FilePath& GetFilePath() const; | 28 const FilePath& GetFilePath() const; |
| 26 | 29 |
| 27 // Gets the physical file path for the extension resource, taking into account | 30 // Gets the physical file path for the extension resource, taking into account |
| 28 // localization. In the browser process, this will DCHECK if not called on the | 31 // localization. In the browser process, this will DCHECK if not called on the |
| 29 // file thread. To easily load extension images on the UI thread, see | 32 // file thread. To easily load extension images on the UI thread, see |
| (...skipping 14 matching lines...) Expand all Loading... |
| 44 static void set_file_thread_id(PlatformThreadId thread_id) { | 47 static void set_file_thread_id(PlatformThreadId thread_id) { |
| 45 file_thread_id_ = thread_id; | 48 file_thread_id_ = thread_id; |
| 46 check_for_file_thread_ = true; | 49 check_for_file_thread_ = true; |
| 47 } | 50 } |
| 48 | 51 |
| 49 // Checks whether we are running on the file thread and DCHECKs if not. Relies | 52 // Checks whether we are running on the file thread and DCHECKs if not. Relies |
| 50 // on set_file_thread_id being called first, otherwise, it will not DCHECK. | 53 // on set_file_thread_id being called first, otherwise, it will not DCHECK. |
| 51 static void CheckFileAccessFromFileThread(); | 54 static void CheckFileAccessFromFileThread(); |
| 52 | 55 |
| 53 // Getters | 56 // Getters |
| 57 const std::string& extension_id() const { return extension_id_; } |
| 54 const FilePath& extension_root() const { return extension_root_; } | 58 const FilePath& extension_root() const { return extension_root_; } |
| 55 const FilePath& relative_path() const { return relative_path_; } | 59 const FilePath& relative_path() const { return relative_path_; } |
| 56 | 60 |
| 61 bool empty() { return extension_root().empty(); } |
| 62 |
| 57 // Unit test helpers. | 63 // Unit test helpers. |
| 58 FilePath::StringType NormalizeSeperators(FilePath::StringType path) const; | 64 FilePath::StringType NormalizeSeperators(FilePath::StringType path) const; |
| 59 bool ComparePathWithDefault(const FilePath& path) const; | 65 bool ComparePathWithDefault(const FilePath& path) const; |
| 60 | 66 |
| 61 private: | 67 private: |
| 68 // The id of the extension that this resource is associated with. |
| 69 std::string extension_id_; |
| 70 |
| 62 // Extension root. | 71 // Extension root. |
| 63 FilePath extension_root_; | 72 FilePath extension_root_; |
| 64 | 73 |
| 65 // Relative path to resource. | 74 // Relative path to resource. |
| 66 FilePath relative_path_; | 75 FilePath relative_path_; |
| 67 | 76 |
| 68 // Full path to extension resource. Starts empty. | 77 // Full path to extension resource. Starts empty. |
| 69 mutable FilePath full_resource_path_; | 78 mutable FilePath full_resource_path_; |
| 70 | 79 |
| 71 // The thread id for the file thread. If set, GetFilePath() and related | 80 // The thread id for the file thread. If set, GetFilePath() and related |
| 72 // methods will DCHECK that they are on this thread when called. | 81 // methods will DCHECK that they are on this thread when called. |
| 73 static PlatformThreadId file_thread_id_; | 82 static PlatformThreadId file_thread_id_; |
| 74 | 83 |
| 75 // Whether to check for file thread. See |file_thread_id_|. If set, | 84 // Whether to check for file thread. See |file_thread_id_|. If set, |
| 76 // GetFilePath() and related methods will DCHECK that they are on this thread | 85 // GetFilePath() and related methods will DCHECK that they are on this thread |
| 77 // when called. | 86 // when called. |
| 78 static bool check_for_file_thread_; | 87 static bool check_for_file_thread_; |
| 79 }; | 88 }; |
| 80 | 89 |
| 81 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_ | 90 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_ |
| OLD | NEW |