1 // Copyright (c) 2011 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 #include "chrome/browser/mac/master_prefs.h"
7 #include "base/files/file_util.h"
8 #include "base/mac/foundation_util.h"
9 #include "chrome/common/channel_info.h"
10 #include "chrome/common/chrome_paths_internal.h"
11 #include "components/version_info/version_info.h"
15 #if defined(GOOGLE_CHROME_BUILD)
16 // This should be NSApplicationSupportDirectory, but it has already been
17 // released using NSLibraryDirectory.
18 const NSSearchPathDirectory kSearchPath = NSLibraryDirectory;
19 const char kMasterPreferencesDirectory[] = "Google";
20 const char kMasterPreferencesFileName[] = "Google Chrome Master Preferences";
22 const NSSearchPathDirectory kSearchPath = NSApplicationSupportDirectory;
23 const char kMasterPreferencesDirectory[] = "Chromium";
24 const char kMasterPreferencesFileName[] = "Chromium Master Preferences";
25 #endif // GOOGLE_CHROME_BUILD
30 namespace master_prefs {
32 base::FilePath MasterPrefsPath() {
33 #if defined(GOOGLE_CHROME_BUILD)
34 // Don't load master preferences for the canary.
35 version_info::Channel channel = chrome::GetChannel();
36 if (channel == version_info::Channel::CANARY)
37 return base::FilePath();
38 #endif // GOOGLE_CHROME_BUILD
40 // On official builds, try
41 //~/Library/Application Support/Google/Chrome/Google Chrome Master Preferences
42 // On chromium builds, try
43 //~/Library/Application Support/Chromium/Chromium Master Preferences
44 // This intentionally doesn't use eventual --user-data-dir overrides.
45 base::FilePath user_application_support_path;
46 if (chrome::GetDefaultUserDataDirectory(&user_application_support_path)) {
47 user_application_support_path =
48 user_application_support_path.Append(kMasterPreferencesFileName);
49 if (base::PathExists(user_application_support_path))
50 return user_application_support_path;
53 // On official builds, try /Library/Google/Google Chrome Master Preferences
54 // On chromium builds, try
55 // /Library/Application Support/Chromium/Chromium Master Preferences
56 base::FilePath search_path;
57 if (!base::mac::GetLocalDirectory(kSearchPath, &search_path))
58 return base::FilePath();
60 return search_path.Append(kMasterPreferencesDirectory)
61 .Append(kMasterPreferencesFileName);
64 } // namespace master_prefs