Chromium Code Reviews| 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" |
| 11 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
| 14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 15 #include "base/time/time.h" | |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 17 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 19 #include "chromeos/chromeos_switches.h" | 20 #include "chromeos/chromeos_switches.h" |
| 20 #include "components/web_resource/web_resource_pref_names.h" | 21 #include "components/web_resource/web_resource_pref_names.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 23 | 24 |
| 24 using content::BrowserThread; | 25 using content::BrowserThread; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 // Forcing the second pref will force this one as well. Even if this one | 81 // Forcing the second pref will force this one as well. Even if this one |
| 81 // doesn't end up synced it is only going to eat up a couple of bytes with no | 82 // doesn't end up synced it is only going to eat up a couple of bytes with no |
| 82 // side-effects. | 83 // side-effects. |
| 83 g_browser_process->local_state()->ClearPref(prefs::kOobeScreenPending); | 84 g_browser_process->local_state()->ClearPref(prefs::kOobeScreenPending); |
| 84 SaveBoolPreferenceForced(prefs::kOobeComplete, true); | 85 SaveBoolPreferenceForced(prefs::kOobeComplete, true); |
| 85 | 86 |
| 86 // Successful enrollment implies that recovery is not required. | 87 // Successful enrollment implies that recovery is not required. |
| 87 SaveBoolPreferenceForced(prefs::kEnrollmentRecoveryRequired, false); | 88 SaveBoolPreferenceForced(prefs::kEnrollmentRecoveryRequired, false); |
| 88 } | 89 } |
| 89 | 90 |
| 91 // static | |
| 90 void StartupUtils::SaveOobePendingScreen(const std::string& screen) { | 92 void StartupUtils::SaveOobePendingScreen(const std::string& screen) { |
| 91 SaveStringPreferenceForced(prefs::kOobeScreenPending, screen); | 93 SaveStringPreferenceForced(prefs::kOobeScreenPending, screen); |
| 92 } | 94 } |
| 93 | 95 |
| 94 // Returns the path to flag file indicating that both parts of OOBE were | 96 // Returns the path to flag file indicating that both parts of OOBE were |
| 95 // completed. | 97 // completed. |
| 96 // On chrome device, returns /home/chronos/.oobe_completed. | 98 // On chrome device, returns /home/chronos/.oobe_completed. |
| 97 // On Linux desktop, returns {DIR_USER_DATA}/.oobe_completed. | 99 // On Linux desktop, returns {DIR_USER_DATA}/.oobe_completed. |
| 98 static base::FilePath GetOobeCompleteFlagPath() { | 100 // static |
| 101 base::FilePath StartupUtils::GetOobeCompleteFlagPath() { | |
| 99 // The constant is defined here so it won't be referenced directly. | 102 // The constant is defined here so it won't be referenced directly. |
| 100 const char kOobeCompleteFlagFilePath[] = "/home/chronos/.oobe_completed"; | 103 const char kOobeCompleteFlagFilePath[] = "/home/chronos/.oobe_completed"; |
| 101 | 104 |
| 102 if (base::SysInfo::IsRunningOnChromeOS()) { | 105 if (base::SysInfo::IsRunningOnChromeOS()) { |
| 103 return base::FilePath(kOobeCompleteFlagFilePath); | 106 return base::FilePath(kOobeCompleteFlagFilePath); |
| 104 } else { | 107 } else { |
| 105 base::FilePath user_data_dir; | 108 base::FilePath user_data_dir; |
| 106 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 109 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 107 return user_data_dir.AppendASCII(".oobe_completed"); | 110 return user_data_dir.AppendASCII(".oobe_completed"); |
| 108 } | 111 } |
| 109 } | 112 } |
| 110 | 113 |
| 114 base::TimeDelta StartupUtils::GetTimeSinceOobeFileCreation() { | |
| 115 const base::FilePath oobe_timestamp_file = | |
| 116 StartupUtils::GetOobeCompleteFlagPath(); | |
|
achuithb
2015/09/18 16:39:11
Don't think you need StartupUtils::
Greg Levin
2015/09/18 18:49:27
Done.
| |
| 117 base::File::Info fileInfo; | |
| 118 if (base::GetFileInfo(oobe_timestamp_file, &fileInfo)) | |
| 119 return base::Time::Now() - fileInfo.creation_time; | |
| 120 return base::TimeDelta(); | |
| 121 } | |
| 122 | |
| 111 static void CreateOobeCompleteFlagFile() { | 123 static void CreateOobeCompleteFlagFile() { |
| 112 // Create flag file for boot-time init scripts. | 124 // Create flag file for boot-time init scripts. |
| 113 base::FilePath oobe_complete_path = GetOobeCompleteFlagPath(); | 125 const base::FilePath oobe_complete_path = |
| 126 StartupUtils::GetOobeCompleteFlagPath(); | |
| 114 if (!base::PathExists(oobe_complete_path)) { | 127 if (!base::PathExists(oobe_complete_path)) { |
| 115 FILE* oobe_flag_file = base::OpenFile(oobe_complete_path, "w+b"); | 128 FILE* oobe_flag_file = base::OpenFile(oobe_complete_path, "w+b"); |
| 116 if (oobe_flag_file == NULL) | 129 if (oobe_flag_file == NULL) |
| 117 DLOG(WARNING) << oobe_complete_path.value() << " doesn't exist."; | 130 DLOG(WARNING) << oobe_complete_path.value() << " doesn't exist."; |
| 118 else | 131 else |
| 119 base::CloseFile(oobe_flag_file); | 132 base::CloseFile(oobe_flag_file); |
| 120 } | 133 } |
| 121 } | 134 } |
| 122 | 135 |
| 123 // static | 136 // static |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 | 195 |
| 183 // static | 196 // static |
| 184 void StartupUtils::SetInitialLocale(const std::string& locale) { | 197 void StartupUtils::SetInitialLocale(const std::string& locale) { |
| 185 if (l10n_util::IsValidLocaleSyntax(locale)) | 198 if (l10n_util::IsValidLocaleSyntax(locale)) |
| 186 SaveStringPreferenceForced(prefs::kInitialLocale, locale); | 199 SaveStringPreferenceForced(prefs::kInitialLocale, locale); |
| 187 else | 200 else |
| 188 NOTREACHED(); | 201 NOTREACHED(); |
| 189 } | 202 } |
| 190 | 203 |
| 191 } // namespace chromeos | 204 } // namespace chromeos |
| OLD | NEW |