OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/common/chrome_paths.h" | 5 #include "chrome/common/chrome_paths.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/lazy_instance.h" | |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/mac/bundle_locations.h" | 10 #include "base/mac/bundle_locations.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
12 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
13 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
14 #include "base/version.h" | 15 #include "base/version.h" |
15 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
16 #include "chrome/common/chrome_paths_internal.h" | 17 #include "chrome/common/chrome_paths_internal.h" |
17 #include "chrome/common/widevine_cdm_constants.h" | 18 #include "chrome/common/widevine_cdm_constants.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 // The path to the external extension <id>.json files. | 88 // The path to the external extension <id>.json files. |
88 // /usr/share seems like a good choice, see: http://www.pathname.com/fhs/ | 89 // /usr/share seems like a good choice, see: http://www.pathname.com/fhs/ |
89 const base::FilePath::CharType kFilepathSinglePrefExtensions[] = | 90 const base::FilePath::CharType kFilepathSinglePrefExtensions[] = |
90 #if defined(GOOGLE_CHROME_BUILD) | 91 #if defined(GOOGLE_CHROME_BUILD) |
91 FILE_PATH_LITERAL("/usr/share/google-chrome/extensions"); | 92 FILE_PATH_LITERAL("/usr/share/google-chrome/extensions"); |
92 #else | 93 #else |
93 FILE_PATH_LITERAL("/usr/share/chromium/extensions"); | 94 FILE_PATH_LITERAL("/usr/share/chromium/extensions"); |
94 #endif // defined(GOOGLE_CHROME_BUILD) | 95 #endif // defined(GOOGLE_CHROME_BUILD) |
95 #endif // defined(OS_LINUX) | 96 #endif // defined(OS_LINUX) |
96 | 97 |
97 } // namespace | 98 static bool g_user_data_dir_initialized = false; |
98 | 99 |
99 namespace chrome { | 100 static base::LazyInstance<base::FilePath> |
101 g_invalid_specified_user_data_dir = LAZY_INSTANCE_INITIALIZER; | |
100 | 102 |
101 // Gets the path for internal plugins. | 103 // Gets the path for internal plugins. |
102 bool GetInternalPluginsDirectory(base::FilePath* result) { | 104 bool GetInternalPluginsDirectory(base::FilePath* result) { |
103 #if defined(OS_MACOSX) && !defined(OS_IOS) | 105 #if defined(OS_MACOSX) && !defined(OS_IOS) |
104 // If called from Chrome, get internal plugins from a subdirectory of the | 106 // If called from Chrome, get internal plugins from a subdirectory of the |
105 // framework. | 107 // framework. |
106 if (base::mac::AmIBundled()) { | 108 if (base::mac::AmIBundled()) { |
107 *result = chrome::GetFrameworkBundlePath(); | 109 *result = chrome::GetFrameworkBundlePath(); |
108 DCHECK(!result->empty()); | 110 DCHECK(!result->empty()); |
109 *result = result->Append("Internet Plug-Ins"); | 111 *result = result->Append("Internet Plug-Ins"); |
110 return true; | 112 return true; |
111 } | 113 } |
112 // In tests, just look in the module directory (below). | 114 // In tests, just look in the module directory (below). |
113 #endif | 115 #endif |
114 | 116 |
115 // The rest of the world expects plugins in the module directory. | 117 // The rest of the world expects plugins in the module directory. |
116 return PathService::Get(base::DIR_MODULE, result); | 118 return PathService::Get(base::DIR_MODULE, result); |
117 } | 119 } |
118 | 120 |
121 } // namespace | |
122 | |
123 namespace chrome { | |
124 | |
119 bool PathProvider(int key, base::FilePath* result) { | 125 bool PathProvider(int key, base::FilePath* result) { |
120 // Some keys are just aliases... | 126 // Some keys are just aliases... |
121 switch (key) { | 127 switch (key) { |
122 case chrome::DIR_APP: | 128 case chrome::DIR_APP: |
123 return PathService::Get(base::DIR_MODULE, result); | 129 return PathService::Get(base::DIR_MODULE, result); |
124 case chrome::DIR_LOGS: | 130 case chrome::DIR_LOGS: |
125 #ifdef NDEBUG | 131 #ifdef NDEBUG |
126 // Release builds write to the data dir | 132 // Release builds write to the data dir |
127 return PathService::Get(chrome::DIR_USER_DATA, result); | 133 return PathService::Get(chrome::DIR_USER_DATA, result); |
128 #else | 134 #else |
(...skipping 19 matching lines...) Expand all Loading... | |
148 return PathService::Get(base::FILE_MODULE, result); | 154 return PathService::Get(base::FILE_MODULE, result); |
149 } | 155 } |
150 | 156 |
151 // Assume that we will not need to create the directory if it does not exist. | 157 // Assume that we will not need to create the directory if it does not exist. |
152 // This flag can be set to true for the cases where we want to create it. | 158 // This flag can be set to true for the cases where we want to create it. |
153 bool create_dir = false; | 159 bool create_dir = false; |
154 | 160 |
155 base::FilePath cur; | 161 base::FilePath cur; |
156 switch (key) { | 162 switch (key) { |
157 case chrome::DIR_USER_DATA: | 163 case chrome::DIR_USER_DATA: |
164 CHECK(g_user_data_dir_initialized); | |
Vitaly Buka (NO REVIEWS)
2014/02/22 00:27:09
DCHECK is safer here. We need to merge this patch
msw
2014/02/22 00:42:07
Done.
| |
158 if (!GetDefaultUserDataDirectory(&cur)) { | 165 if (!GetDefaultUserDataDirectory(&cur)) { |
159 NOTREACHED(); | 166 NOTREACHED(); |
160 return false; | 167 return false; |
161 } | 168 } |
162 create_dir = true; | 169 create_dir = true; |
163 break; | 170 break; |
164 case chrome::DIR_USER_DOCUMENTS: | 171 case chrome::DIR_USER_DOCUMENTS: |
165 if (!GetUserDocumentsDirectory(&cur)) | 172 if (!GetUserDocumentsDirectory(&cur)) |
166 return false; | 173 return false; |
167 create_dir = true; | 174 create_dir = true; |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 *result = cur; | 551 *result = cur; |
545 return true; | 552 return true; |
546 } | 553 } |
547 | 554 |
548 // This cannot be done as a static initializer sadly since Visual Studio will | 555 // This cannot be done as a static initializer sadly since Visual Studio will |
549 // eliminate this object file if there is no direct entry point into it. | 556 // eliminate this object file if there is no direct entry point into it. |
550 void RegisterPathProvider() { | 557 void RegisterPathProvider() { |
551 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); | 558 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); |
552 } | 559 } |
553 | 560 |
561 void SetUserDataDirInitialized() { | |
562 g_user_data_dir_initialized = true; | |
563 } | |
564 | |
565 void SetInvalidSpecifiedUserDataDir(const base::FilePath& user_data_dir) { | |
566 g_invalid_specified_user_data_dir.Get() = user_data_dir; | |
567 } | |
568 | |
569 const base::FilePath& GetInvalidSpecifiedUserDataDir() { | |
570 return g_invalid_specified_user_data_dir.Get(); | |
571 } | |
572 | |
554 } // namespace chrome | 573 } // namespace chrome |
OLD | NEW |