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/browser/chromeos/login/startup_utils.h" | 5 #include "chrome/browser/chromeos/login/startup_utils.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 } | 40 } |
41 | 41 |
42 // Saves string "Local State" preference and forces its persistence to disk. | 42 // Saves string "Local State" preference and forces its persistence to disk. |
43 void SaveStringPreferenceForced(const char* pref_name, | 43 void SaveStringPreferenceForced(const char* pref_name, |
44 const std::string& value) { | 44 const std::string& value) { |
45 PrefService* prefs = g_browser_process->local_state(); | 45 PrefService* prefs = g_browser_process->local_state(); |
46 prefs->SetString(pref_name, value); | 46 prefs->SetString(pref_name, value); |
47 prefs->CommitPendingWrite(); | 47 prefs->CommitPendingWrite(); |
48 } | 48 } |
49 | 49 |
| 50 // Returns the path to flag file indicating that both parts of OOBE were |
| 51 // completed. |
| 52 // On chrome device, returns /home/chronos/.oobe_completed. |
| 53 // On Linux desktop, returns {DIR_USER_DATA}/.oobe_completed. |
| 54 base::FilePath GetOobeCompleteFlagPath() { |
| 55 // The constant is defined here so it won't be referenced directly. |
| 56 const char kOobeCompleteFlagFilePath[] = "/home/chronos/.oobe_completed"; |
| 57 |
| 58 if (base::SysInfo::IsRunningOnChromeOS()) { |
| 59 return base::FilePath(kOobeCompleteFlagFilePath); |
| 60 } else { |
| 61 base::FilePath user_data_dir; |
| 62 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 63 return user_data_dir.AppendASCII(".oobe_completed"); |
| 64 } |
| 65 } |
| 66 |
| 67 void CreateOobeCompleteFlagFile() { |
| 68 // Create flag file for boot-time init scripts. |
| 69 const base::FilePath oobe_complete_flag_path = GetOobeCompleteFlagPath(); |
| 70 if (!base::PathExists(oobe_complete_flag_path)) { |
| 71 FILE* oobe_flag_file = base::OpenFile(oobe_complete_flag_path, "w+b"); |
| 72 if (oobe_flag_file == NULL) |
| 73 DLOG(WARNING) << oobe_complete_flag_path.value() << " doesn't exist."; |
| 74 else |
| 75 base::CloseFile(oobe_flag_file); |
| 76 } |
| 77 } |
| 78 |
50 } // namespace | 79 } // namespace |
51 | 80 |
52 namespace chromeos { | 81 namespace chromeos { |
53 | 82 |
54 // static | 83 // static |
55 void StartupUtils::RegisterPrefs(PrefRegistrySimple* registry) { | 84 void StartupUtils::RegisterPrefs(PrefRegistrySimple* registry) { |
56 registry->RegisterBooleanPref(prefs::kOobeComplete, false); | 85 registry->RegisterBooleanPref(prefs::kOobeComplete, false); |
57 registry->RegisterStringPref(prefs::kOobeScreenPending, ""); | 86 registry->RegisterStringPref(prefs::kOobeScreenPending, ""); |
58 registry->RegisterIntegerPref(prefs::kDeviceRegistered, -1); | 87 registry->RegisterIntegerPref(prefs::kDeviceRegistered, -1); |
59 registry->RegisterBooleanPref(prefs::kEnrollmentRecoveryRequired, false); | 88 registry->RegisterBooleanPref(prefs::kEnrollmentRecoveryRequired, false); |
(...skipping 25 matching lines...) Expand all Loading... |
85 | 114 |
86 // Successful enrollment implies that recovery is not required. | 115 // Successful enrollment implies that recovery is not required. |
87 SaveBoolPreferenceForced(prefs::kEnrollmentRecoveryRequired, false); | 116 SaveBoolPreferenceForced(prefs::kEnrollmentRecoveryRequired, false); |
88 } | 117 } |
89 | 118 |
90 // static | 119 // static |
91 void StartupUtils::SaveOobePendingScreen(const std::string& screen) { | 120 void StartupUtils::SaveOobePendingScreen(const std::string& screen) { |
92 SaveStringPreferenceForced(prefs::kOobeScreenPending, screen); | 121 SaveStringPreferenceForced(prefs::kOobeScreenPending, screen); |
93 } | 122 } |
94 | 123 |
95 // Returns the path to flag file indicating that both parts of OOBE were | |
96 // completed. | |
97 // On chrome device, returns /home/chronos/.oobe_completed. | |
98 // On Linux desktop, returns {DIR_USER_DATA}/.oobe_completed. | |
99 static base::FilePath GetOobeCompleteFlagPath() { | |
100 // The constant is defined here so it won't be referenced directly. | |
101 const char kOobeCompleteFlagFilePath[] = "/home/chronos/.oobe_completed"; | |
102 | |
103 if (base::SysInfo::IsRunningOnChromeOS()) { | |
104 return base::FilePath(kOobeCompleteFlagFilePath); | |
105 } else { | |
106 base::FilePath user_data_dir; | |
107 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | |
108 return user_data_dir.AppendASCII(".oobe_completed"); | |
109 } | |
110 } | |
111 | |
112 // static | 124 // static |
113 base::TimeDelta StartupUtils::GetTimeSinceOobeFlagFileCreation() { | 125 base::TimeDelta StartupUtils::GetTimeSinceOobeFlagFileCreation() { |
114 const base::FilePath oobe_complete_flag_path = GetOobeCompleteFlagPath(); | 126 const base::FilePath oobe_complete_flag_path = GetOobeCompleteFlagPath(); |
115 base::File::Info file_info; | 127 base::File::Info file_info; |
116 if (base::GetFileInfo(oobe_complete_flag_path, &file_info)) | 128 if (base::GetFileInfo(oobe_complete_flag_path, &file_info)) |
117 return base::Time::Now() - file_info.creation_time; | 129 return base::Time::Now() - file_info.creation_time; |
118 return base::TimeDelta(); | 130 return base::TimeDelta(); |
119 } | 131 } |
120 | 132 |
121 static void CreateOobeCompleteFlagFile() { | |
122 // Create flag file for boot-time init scripts. | |
123 const base::FilePath oobe_complete_flag_path = GetOobeCompleteFlagPath(); | |
124 if (!base::PathExists(oobe_complete_flag_path)) { | |
125 FILE* oobe_flag_file = base::OpenFile(oobe_complete_flag_path, "w+b"); | |
126 if (oobe_flag_file == NULL) | |
127 DLOG(WARNING) << oobe_complete_flag_path.value() << " doesn't exist."; | |
128 else | |
129 base::CloseFile(oobe_flag_file); | |
130 } | |
131 } | |
132 | |
133 // static | 133 // static |
134 bool StartupUtils::IsDeviceRegistered() { | 134 bool StartupUtils::IsDeviceRegistered() { |
135 int value = | 135 int value = |
136 g_browser_process->local_state()->GetInteger(prefs::kDeviceRegistered); | 136 g_browser_process->local_state()->GetInteger(prefs::kDeviceRegistered); |
137 if (value > 0) { | 137 if (value > 0) { |
138 // Recreate flag file in case it was lost. | 138 // Recreate flag file in case it was lost. |
139 BrowserThread::PostTask( | 139 BrowserThread::PostTask( |
140 BrowserThread::FILE, | 140 BrowserThread::FILE, |
141 FROM_HERE, | 141 FROM_HERE, |
142 base::Bind(&CreateOobeCompleteFlagFile)); | 142 base::Bind(&CreateOobeCompleteFlagFile)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 192 |
193 // static | 193 // static |
194 void StartupUtils::SetInitialLocale(const std::string& locale) { | 194 void StartupUtils::SetInitialLocale(const std::string& locale) { |
195 if (l10n_util::IsValidLocaleSyntax(locale)) | 195 if (l10n_util::IsValidLocaleSyntax(locale)) |
196 SaveStringPreferenceForced(prefs::kInitialLocale, locale); | 196 SaveStringPreferenceForced(prefs::kInitialLocale, locale); |
197 else | 197 else |
198 NOTREACHED(); | 198 NOTREACHED(); |
199 } | 199 } |
200 | 200 |
201 } // namespace chromeos | 201 } // namespace chromeos |
OLD | NEW |