pastarmovj@chromium.org | 8f45209 | 2012-05-09 19:50:10 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 5 | #include "base/path_service.h" |
avi@google.com | ac68ba2 | 2008-08-07 01:01:25 +0900 | [diff] [blame] | 6 | |
| 7 | #ifdef OS_WIN |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 8 | #include <windows.h> |
| 9 | #include <shellapi.h> |
| 10 | #include <shlobj.h> |
avi@google.com | ac68ba2 | 2008-08-07 01:01:25 +0900 | [diff] [blame] | 11 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 12 | |
evanm@google.com | 874d167 | 2008-10-31 08:54:04 +0900 | [diff] [blame] | 13 | #include "base/file_path.h" |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 14 | #include "base/file_util.h" |
evanm@google.com | 874d167 | 2008-10-31 08:54:04 +0900 | [diff] [blame] | 15 | #include "base/hash_tables.h" |
satish@chromium.org | 2940ad1 | 2010-12-14 16:48:49 +0900 | [diff] [blame] | 16 | #include "base/lazy_instance.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 17 | #include "base/logging.h" |
brettw@chromium.org | abe477a | 2011-01-21 13:55:52 +0900 | [diff] [blame] | 18 | #include "base/synchronization/lock.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 19 | |
| 20 | namespace base { |
evanm@google.com | 3e9d5d7 | 2008-11-20 01:50:03 +0900 | [diff] [blame] | 21 | bool PathProvider(int key, FilePath* result); |
erikkay@google.com | 9fc57d0 | 2008-08-09 05:16:08 +0900 | [diff] [blame] | 22 | #if defined(OS_WIN) |
evanm@google.com | 3e9d5d7 | 2008-11-20 01:50:03 +0900 | [diff] [blame] | 23 | bool PathProviderWin(int key, FilePath* result); |
evanm@google.com | e41d3b3 | 2008-08-15 10:04:11 +0900 | [diff] [blame] | 24 | #elif defined(OS_MACOSX) |
evanm@google.com | 3e9d5d7 | 2008-11-20 01:50:03 +0900 | [diff] [blame] | 25 | bool PathProviderMac(int key, FilePath* result); |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 26 | #elif defined(OS_ANDROID) |
| 27 | bool PathProviderAndroid(int key, FilePath* result); |
evan@chromium.org | c136509 | 2009-11-21 10:29:00 +0900 | [diff] [blame] | 28 | #elif defined(OS_POSIX) |
| 29 | bool PathProviderPosix(int key, FilePath* result); |
erikkay@google.com | c7980ee | 2008-08-06 04:46:31 +0900 | [diff] [blame] | 30 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | namespace { |
| 34 | |
evanm@google.com | 874d167 | 2008-10-31 08:54:04 +0900 | [diff] [blame] | 35 | typedef base::hash_map<int, FilePath> PathMap; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 36 | |
| 37 | // We keep a linked list of providers. In a debug build we ensure that no two |
| 38 | // providers claim overlapping keys. |
| 39 | struct Provider { |
| 40 | PathService::ProviderFunc func; |
| 41 | struct Provider* next; |
| 42 | #ifndef NDEBUG |
| 43 | int key_start; |
| 44 | int key_end; |
| 45 | #endif |
erikkay@google.com | 564ef6d | 2008-08-21 00:47:39 +0900 | [diff] [blame] | 46 | bool is_static; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 47 | }; |
| 48 | |
jhawkins@chromium.org | 88fbaf6 | 2012-01-28 09:34:40 +0900 | [diff] [blame] | 49 | Provider base_provider = { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 50 | base::PathProvider, |
| 51 | NULL, |
| 52 | #ifndef NDEBUG |
| 53 | base::PATH_START, |
erikkay@google.com | 564ef6d | 2008-08-21 00:47:39 +0900 | [diff] [blame] | 54 | base::PATH_END, |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 55 | #endif |
erikkay@google.com | 564ef6d | 2008-08-21 00:47:39 +0900 | [diff] [blame] | 56 | true |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 57 | }; |
| 58 | |
evan@chromium.org | c136509 | 2009-11-21 10:29:00 +0900 | [diff] [blame] | 59 | #if defined(OS_WIN) |
jhawkins@chromium.org | 88fbaf6 | 2012-01-28 09:34:40 +0900 | [diff] [blame] | 60 | Provider base_provider_win = { |
erikkay@google.com | c7980ee | 2008-08-06 04:46:31 +0900 | [diff] [blame] | 61 | base::PathProviderWin, |
| 62 | &base_provider, |
| 63 | #ifndef NDEBUG |
| 64 | base::PATH_WIN_START, |
erikkay@google.com | 564ef6d | 2008-08-21 00:47:39 +0900 | [diff] [blame] | 65 | base::PATH_WIN_END, |
erikkay@google.com | c7980ee | 2008-08-06 04:46:31 +0900 | [diff] [blame] | 66 | #endif |
erikkay@google.com | 564ef6d | 2008-08-21 00:47:39 +0900 | [diff] [blame] | 67 | true |
erikkay@google.com | c7980ee | 2008-08-06 04:46:31 +0900 | [diff] [blame] | 68 | }; |
| 69 | #endif |
| 70 | |
evan@chromium.org | c136509 | 2009-11-21 10:29:00 +0900 | [diff] [blame] | 71 | #if defined(OS_MACOSX) |
jhawkins@chromium.org | 88fbaf6 | 2012-01-28 09:34:40 +0900 | [diff] [blame] | 72 | Provider base_provider_mac = { |
erikkay@google.com | 9fc57d0 | 2008-08-09 05:16:08 +0900 | [diff] [blame] | 73 | base::PathProviderMac, |
| 74 | &base_provider, |
| 75 | #ifndef NDEBUG |
| 76 | base::PATH_MAC_START, |
erikkay@google.com | 564ef6d | 2008-08-21 00:47:39 +0900 | [diff] [blame] | 77 | base::PATH_MAC_END, |
erikkay@google.com | 9fc57d0 | 2008-08-09 05:16:08 +0900 | [diff] [blame] | 78 | #endif |
erikkay@google.com | 564ef6d | 2008-08-21 00:47:39 +0900 | [diff] [blame] | 79 | true |
| 80 | }; |
erikkay@google.com | 9fc57d0 | 2008-08-09 05:16:08 +0900 | [diff] [blame] | 81 | #endif |
evanm@google.com | e41d3b3 | 2008-08-15 10:04:11 +0900 | [diff] [blame] | 82 | |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 83 | #if defined(OS_ANDROID) |
jhawkins@chromium.org | 88fbaf6 | 2012-01-28 09:34:40 +0900 | [diff] [blame] | 84 | Provider base_provider_android = { |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 85 | base::PathProviderAndroid, |
| 86 | &base_provider, |
| 87 | #ifndef NDEBUG |
wjia@chromium.org | 9d594d1 | 2012-09-20 10:59:36 +0900 | [diff] [blame^] | 88 | 0, |
| 89 | 0, |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 90 | #endif |
| 91 | true |
| 92 | }; |
| 93 | #endif |
| 94 | |
| 95 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
jhawkins@chromium.org | 88fbaf6 | 2012-01-28 09:34:40 +0900 | [diff] [blame] | 96 | Provider base_provider_posix = { |
evan@chromium.org | c136509 | 2009-11-21 10:29:00 +0900 | [diff] [blame] | 97 | base::PathProviderPosix, |
evanm@google.com | e41d3b3 | 2008-08-15 10:04:11 +0900 | [diff] [blame] | 98 | &base_provider, |
| 99 | #ifndef NDEBUG |
wjia@chromium.org | 9d594d1 | 2012-09-20 10:59:36 +0900 | [diff] [blame^] | 100 | 0, |
| 101 | 0, |
evanm@google.com | e41d3b3 | 2008-08-15 10:04:11 +0900 | [diff] [blame] | 102 | #endif |
erikkay@google.com | 564ef6d | 2008-08-21 00:47:39 +0900 | [diff] [blame] | 103 | true |
| 104 | }; |
evanm@google.com | e41d3b3 | 2008-08-15 10:04:11 +0900 | [diff] [blame] | 105 | #endif |
| 106 | |
| 107 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 108 | struct PathData { |
brettw@chromium.org | abe477a | 2011-01-21 13:55:52 +0900 | [diff] [blame] | 109 | base::Lock lock; |
| 110 | PathMap cache; // Cache mappings from path key to path value. |
| 111 | PathMap overrides; // Track path overrides. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 112 | Provider* providers; // Linked list of path service providers. |
| 113 | |
erikkay@google.com | c7980ee | 2008-08-06 04:46:31 +0900 | [diff] [blame] | 114 | PathData() { |
| 115 | #if defined(OS_WIN) |
| 116 | providers = &base_provider_win; |
erikkay@google.com | 9fc57d0 | 2008-08-09 05:16:08 +0900 | [diff] [blame] | 117 | #elif defined(OS_MACOSX) |
| 118 | providers = &base_provider_mac; |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 119 | #elif defined(OS_ANDROID) |
| 120 | providers = &base_provider_android; |
evan@chromium.org | c136509 | 2009-11-21 10:29:00 +0900 | [diff] [blame] | 121 | #elif defined(OS_POSIX) |
| 122 | providers = &base_provider_posix; |
erikkay@google.com | c7980ee | 2008-08-06 04:46:31 +0900 | [diff] [blame] | 123 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 124 | } |
erikkay@google.com | 564ef6d | 2008-08-21 00:47:39 +0900 | [diff] [blame] | 125 | |
| 126 | ~PathData() { |
| 127 | Provider* p = providers; |
| 128 | while (p) { |
| 129 | Provider* next = p->next; |
| 130 | if (!p->is_static) |
| 131 | delete p; |
| 132 | p = next; |
| 133 | } |
| 134 | } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 135 | }; |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 136 | |
joth@chromium.org | b24883c | 2011-11-15 22:31:49 +0900 | [diff] [blame] | 137 | static base::LazyInstance<PathData> g_path_data = LAZY_INSTANCE_INITIALIZER; |
satish@chromium.org | 2940ad1 | 2010-12-14 16:48:49 +0900 | [diff] [blame] | 138 | |
erikkay@google.com | a3ff275 | 2008-08-13 02:33:52 +0900 | [diff] [blame] | 139 | static PathData* GetPathData() { |
satish@chromium.org | 2940ad1 | 2010-12-14 16:48:49 +0900 | [diff] [blame] | 140 | return g_path_data.Pointer(); |
erikkay@google.com | a3ff275 | 2008-08-13 02:33:52 +0900 | [diff] [blame] | 141 | } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 142 | |
| 143 | } // namespace |
| 144 | |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 145 | |
erikkay@google.com | a3ff275 | 2008-08-13 02:33:52 +0900 | [diff] [blame] | 146 | // static |
evanm@google.com | 874d167 | 2008-10-31 08:54:04 +0900 | [diff] [blame] | 147 | bool PathService::GetFromCache(int key, FilePath* result) { |
erikkay@google.com | a3ff275 | 2008-08-13 02:33:52 +0900 | [diff] [blame] | 148 | PathData* path_data = GetPathData(); |
brettw@chromium.org | abe477a | 2011-01-21 13:55:52 +0900 | [diff] [blame] | 149 | base::AutoLock scoped_lock(path_data->lock); |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 150 | |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 151 | // check for a cached version |
| 152 | PathMap::const_iterator it = path_data->cache.find(key); |
| 153 | if (it != path_data->cache.end()) { |
| 154 | *result = it->second; |
| 155 | return true; |
| 156 | } |
| 157 | return false; |
| 158 | } |
| 159 | |
erikkay@google.com | a3ff275 | 2008-08-13 02:33:52 +0900 | [diff] [blame] | 160 | // static |
phajdan.jr@chromium.org | 26faa10 | 2010-09-10 08:49:04 +0900 | [diff] [blame] | 161 | bool PathService::GetFromOverrides(int key, FilePath* result) { |
| 162 | PathData* path_data = GetPathData(); |
brettw@chromium.org | abe477a | 2011-01-21 13:55:52 +0900 | [diff] [blame] | 163 | base::AutoLock scoped_lock(path_data->lock); |
phajdan.jr@chromium.org | 26faa10 | 2010-09-10 08:49:04 +0900 | [diff] [blame] | 164 | |
jhawkins@chromium.org | da5f34c | 2011-12-15 03:47:26 +0900 | [diff] [blame] | 165 | // check for an overridden version. |
phajdan.jr@chromium.org | 26faa10 | 2010-09-10 08:49:04 +0900 | [diff] [blame] | 166 | PathMap::const_iterator it = path_data->overrides.find(key); |
| 167 | if (it != path_data->overrides.end()) { |
| 168 | *result = it->second; |
| 169 | return true; |
| 170 | } |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | // static |
evanm@google.com | 874d167 | 2008-10-31 08:54:04 +0900 | [diff] [blame] | 175 | void PathService::AddToCache(int key, const FilePath& path) { |
erikkay@google.com | a3ff275 | 2008-08-13 02:33:52 +0900 | [diff] [blame] | 176 | PathData* path_data = GetPathData(); |
brettw@chromium.org | abe477a | 2011-01-21 13:55:52 +0900 | [diff] [blame] | 177 | base::AutoLock scoped_lock(path_data->lock); |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 178 | // Save the computed path in our cache. |
| 179 | path_data->cache[key] = path; |
| 180 | } |
| 181 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 182 | // TODO(brettw): this function does not handle long paths (filename > MAX_PATH) |
| 183 | // characters). This isn't supported very well by Windows right now, so it is |
| 184 | // moot, but we should keep this in mind for the future. |
| 185 | // static |
evanm@google.com | 874d167 | 2008-10-31 08:54:04 +0900 | [diff] [blame] | 186 | bool PathService::Get(int key, FilePath* result) { |
erikkay@google.com | a3ff275 | 2008-08-13 02:33:52 +0900 | [diff] [blame] | 187 | PathData* path_data = GetPathData(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 188 | DCHECK(path_data); |
| 189 | DCHECK(result); |
pkasting@chromium.org | d23fe1a | 2011-04-01 05:34:25 +0900 | [diff] [blame] | 190 | DCHECK_GE(key, base::DIR_CURRENT); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 191 | |
| 192 | // special case the current directory because it can never be cached |
erikkay@google.com | 9fc57d0 | 2008-08-09 05:16:08 +0900 | [diff] [blame] | 193 | if (key == base::DIR_CURRENT) |
erikkay@google.com | 1d4507f | 2008-08-07 01:29:44 +0900 | [diff] [blame] | 194 | return file_util::GetCurrentDirectory(result); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 195 | |
rvargas@google.com | 2fa9481 | 2010-08-20 08:20:09 +0900 | [diff] [blame] | 196 | if (GetFromCache(key, result)) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 197 | return true; |
estade@chromium.org | 234a632 | 2009-02-28 10:49:55 +0900 | [diff] [blame] | 198 | |
phajdan.jr@chromium.org | 26faa10 | 2010-09-10 08:49:04 +0900 | [diff] [blame] | 199 | if (GetFromOverrides(key, result)) |
| 200 | return true; |
| 201 | |
evanm@google.com | 3e9d5d7 | 2008-11-20 01:50:03 +0900 | [diff] [blame] | 202 | FilePath path; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 203 | |
| 204 | // search providers for the requested path |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 205 | // NOTE: it should be safe to iterate here without the lock |
| 206 | // since RegisterProvider always prepends. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 207 | Provider* provider = path_data->providers; |
| 208 | while (provider) { |
evanm@google.com | 3e9d5d7 | 2008-11-20 01:50:03 +0900 | [diff] [blame] | 209 | if (provider->func(key, &path)) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 210 | break; |
estade@chromium.org | 234a632 | 2009-02-28 10:49:55 +0900 | [diff] [blame] | 211 | DCHECK(path.empty()) << "provider should not have modified path"; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 212 | provider = provider->next; |
| 213 | } |
| 214 | |
estade@chromium.org | 234a632 | 2009-02-28 10:49:55 +0900 | [diff] [blame] | 215 | if (path.empty()) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 216 | return false; |
| 217 | |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 218 | AddToCache(key, path); |
estade@chromium.org | 234a632 | 2009-02-28 10:49:55 +0900 | [diff] [blame] | 219 | |
evanm@google.com | 874d167 | 2008-10-31 08:54:04 +0900 | [diff] [blame] | 220 | *result = path; |
| 221 | return true; |
| 222 | } |
| 223 | |
jcampan@chromium.org | cce10e7 | 2009-06-26 02:29:09 +0900 | [diff] [blame] | 224 | bool PathService::Override(int key, const FilePath& path) { |
pastarmovj@chromium.org | 8f45209 | 2012-05-09 19:50:10 +0900 | [diff] [blame] | 225 | // Just call the full function with true for the value of |create|. |
| 226 | return OverrideAndCreateIfNeeded(key, path, true); |
| 227 | } |
| 228 | |
| 229 | bool PathService::OverrideAndCreateIfNeeded(int key, |
| 230 | const FilePath& path, |
| 231 | bool create) { |
erikkay@google.com | a3ff275 | 2008-08-13 02:33:52 +0900 | [diff] [blame] | 232 | PathData* path_data = GetPathData(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 233 | DCHECK(path_data); |
kushi.p@gmail.com | e18fdd3 | 2011-03-14 07:13:33 +0900 | [diff] [blame] | 234 | DCHECK_GT(key, base::DIR_CURRENT) << "invalid path key"; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 235 | |
jcampan@chromium.org | cce10e7 | 2009-06-26 02:29:09 +0900 | [diff] [blame] | 236 | FilePath file_path = path; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 237 | |
pastarmovj@chromium.org | 8f45209 | 2012-05-09 19:50:10 +0900 | [diff] [blame] | 238 | // For some locations this will fail if called from inside the sandbox there- |
| 239 | // fore we protect this call with a flag. |
| 240 | if (create) { |
| 241 | // Make sure the directory exists. We need to do this before we translate |
| 242 | // this to the absolute path because on POSIX, AbsolutePath fails if called |
| 243 | // on a non-existent path. |
| 244 | if (!file_util::PathExists(file_path) && |
| 245 | !file_util::CreateDirectory(file_path)) |
| 246 | return false; |
| 247 | } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 248 | |
erg@google.com | 08945ec | 2009-10-28 08:31:36 +0900 | [diff] [blame] | 249 | // We need to have an absolute path, as extensions and plugins don't like |
jhawkins@chromium.org | da5f34c | 2011-12-15 03:47:26 +0900 | [diff] [blame] | 250 | // relative paths, and will gladly crash the browser in CHECK()s if they get a |
erg@google.com | 08945ec | 2009-10-28 08:31:36 +0900 | [diff] [blame] | 251 | // relative path. |
| 252 | if (!file_util::AbsolutePath(&file_path)) |
| 253 | return false; |
| 254 | |
brettw@chromium.org | abe477a | 2011-01-21 13:55:52 +0900 | [diff] [blame] | 255 | base::AutoLock scoped_lock(path_data->lock); |
phajdan.jr@chromium.org | 26faa10 | 2010-09-10 08:49:04 +0900 | [diff] [blame] | 256 | |
| 257 | // Clear the cache now. Some of its entries could have depended |
| 258 | // on the value we are overriding, and are now out of sync with reality. |
| 259 | path_data->cache.clear(); |
| 260 | |
jcampan@chromium.org | cce10e7 | 2009-06-26 02:29:09 +0900 | [diff] [blame] | 261 | path_data->cache[key] = file_path; |
phajdan.jr@chromium.org | 26faa10 | 2010-09-10 08:49:04 +0900 | [diff] [blame] | 262 | path_data->overrides[key] = file_path; |
| 263 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 264 | return true; |
| 265 | } |
| 266 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 267 | void PathService::RegisterProvider(ProviderFunc func, int key_start, |
| 268 | int key_end) { |
erikkay@google.com | a3ff275 | 2008-08-13 02:33:52 +0900 | [diff] [blame] | 269 | PathData* path_data = GetPathData(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 270 | DCHECK(path_data); |
kushi.p@gmail.com | e18fdd3 | 2011-03-14 07:13:33 +0900 | [diff] [blame] | 271 | DCHECK_GT(key_end, key_start); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 272 | |
brettw@chromium.org | abe477a | 2011-01-21 13:55:52 +0900 | [diff] [blame] | 273 | base::AutoLock scoped_lock(path_data->lock); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 274 | |
| 275 | Provider* p; |
| 276 | |
| 277 | #ifndef NDEBUG |
| 278 | p = path_data->providers; |
| 279 | while (p) { |
| 280 | DCHECK(key_start >= p->key_end || key_end <= p->key_start) << |
| 281 | "path provider collision"; |
| 282 | p = p->next; |
| 283 | } |
| 284 | #endif |
| 285 | |
| 286 | p = new Provider; |
erikkay@google.com | 564ef6d | 2008-08-21 00:47:39 +0900 | [diff] [blame] | 287 | p->is_static = false; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 288 | p->func = func; |
| 289 | p->next = path_data->providers; |
| 290 | #ifndef NDEBUG |
| 291 | p->key_start = key_start; |
| 292 | p->key_end = key_end; |
| 293 | #endif |
| 294 | path_data->providers = p; |
| 295 | } |