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 69 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 | 80 // 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 | 81 // doesn't end up synced it is only going to eat up a couple of bytes with no |
82 // side-effects. | 82 // side-effects. |
83 g_browser_process->local_state()->ClearPref(prefs::kOobeScreenPending); | 83 g_browser_process->local_state()->ClearPref(prefs::kOobeScreenPending); |
84 SaveBoolPreferenceForced(prefs::kOobeComplete, true); | 84 SaveBoolPreferenceForced(prefs::kOobeComplete, true); |
85 | 85 |
86 // Successful enrollment implies that recovery is not required. | 86 // Successful enrollment implies that recovery is not required. |
87 SaveBoolPreferenceForced(prefs::kEnrollmentRecoveryRequired, false); | 87 SaveBoolPreferenceForced(prefs::kEnrollmentRecoveryRequired, false); |
88 } | 88 } |
89 | 89 |
90 // static | |
90 void StartupUtils::SaveOobePendingScreen(const std::string& screen) { | 91 void StartupUtils::SaveOobePendingScreen(const std::string& screen) { |
91 SaveStringPreferenceForced(prefs::kOobeScreenPending, screen); | 92 SaveStringPreferenceForced(prefs::kOobeScreenPending, screen); |
92 } | 93 } |
93 | 94 |
94 // Returns the path to flag file indicating that both parts of OOBE were | 95 // Returns the path to flag file indicating that both parts of OOBE were |
95 // completed. | 96 // completed. |
96 // On chrome device, returns /home/chronos/.oobe_completed. | 97 // On chrome device, returns /home/chronos/.oobe_completed. |
97 // On Linux desktop, returns {DIR_USER_DATA}/.oobe_completed. | 98 // On Linux desktop, returns {DIR_USER_DATA}/.oobe_completed. |
98 static base::FilePath GetOobeCompleteFlagPath() { | 99 static base::FilePath GetOobeCompleteFlagPath() { |
99 // The constant is defined here so it won't be referenced directly. | 100 // The constant is defined here so it won't be referenced directly. |
100 const char kOobeCompleteFlagFilePath[] = "/home/chronos/.oobe_completed"; | 101 const char kOobeCompleteFlagFilePath[] = "/home/chronos/.oobe_completed"; |
101 | 102 |
102 if (base::SysInfo::IsRunningOnChromeOS()) { | 103 if (base::SysInfo::IsRunningOnChromeOS()) { |
103 return base::FilePath(kOobeCompleteFlagFilePath); | 104 return base::FilePath(kOobeCompleteFlagFilePath); |
104 } else { | 105 } else { |
105 base::FilePath user_data_dir; | 106 base::FilePath user_data_dir; |
106 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 107 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
107 return user_data_dir.AppendASCII(".oobe_completed"); | 108 return user_data_dir.AppendASCII(".oobe_completed"); |
108 } | 109 } |
109 } | 110 } |
110 | 111 |
112 // static | |
113 base::TimeDelta StartupUtils::GetTimeSinceOobeFlagFileCreation() { | |
114 const base::FilePath oobe_complete_flag_path = GetOobeCompleteFlagPath(); | |
115 base::File::Info file_info; | |
116 if (base::GetFileInfo(oobe_complete_flag_path, &file_info)) | |
117 return base::Time::Now() - file_info.creation_time; | |
118 return base::TimeDelta(); | |
119 } | |
120 | |
111 static void CreateOobeCompleteFlagFile() { | 121 static void CreateOobeCompleteFlagFile() { |
112 // Create flag file for boot-time init scripts. | 122 // Create flag file for boot-time init scripts. |
113 base::FilePath oobe_complete_path = GetOobeCompleteFlagPath(); | 123 const base::FilePath oobe_complete_flag_path = GetOobeCompleteFlagPath(); |
114 if (!base::PathExists(oobe_complete_path)) { | 124 if (!base::PathExists(oobe_complete_flag_path)) { |
115 FILE* oobe_flag_file = base::OpenFile(oobe_complete_path, "w+b"); | 125 FILE* oobe_flag_file = base::OpenFile(oobe_complete_flag_path, "w+b"); |
116 if (oobe_flag_file == NULL) | 126 if (oobe_flag_file == NULL) |
117 DLOG(WARNING) << oobe_complete_path.value() << " doesn't exist."; | 127 DLOG(WARNING) << oobe_complete_flag_path.value() << " doesn't exist."; |
118 else | 128 else |
119 base::CloseFile(oobe_flag_file); | 129 base::CloseFile(oobe_flag_file); |
120 } | 130 } |
121 } | 131 } |
122 | 132 |
123 // static | 133 // static |
124 bool StartupUtils::IsDeviceRegistered() { | 134 bool StartupUtils::IsDeviceRegistered() { |
125 int value = | 135 int value = |
126 g_browser_process->local_state()->GetInteger(prefs::kDeviceRegistered); | 136 g_browser_process->local_state()->GetInteger(prefs::kDeviceRegistered); |
127 if (value > 0) { | 137 if (value > 0) { |
128 // Recreate flag file in case it was lost. | 138 // Recreate flag file in case it was lost. |
129 BrowserThread::PostTask( | 139 BrowserThread::PostTask( |
130 BrowserThread::FILE, | 140 BrowserThread::FILE, |
131 FROM_HERE, | 141 FROM_HERE, |
132 base::Bind(&CreateOobeCompleteFlagFile)); | 142 base::Bind(&CreateOobeCompleteFlagFile)); |
133 return true; | 143 return true; |
134 } else if (value == 0) { | 144 } else if (value == 0) { |
135 return false; | 145 return false; |
136 } else { | 146 } else { |
137 // Pref is not set. For compatibility check flag file. It causes blocking | 147 // Pref is not set. For compatibility check flag file. It causes blocking |
138 // IO on UI thread. But it's required for update from old versions. | 148 // IO on UI thread. But it's required for update from old versions. |
139 base::ThreadRestrictions::ScopedAllowIO allow_io; | 149 base::ThreadRestrictions::ScopedAllowIO allow_io; |
140 base::FilePath oobe_complete_flag_file_path = GetOobeCompleteFlagPath(); | 150 const base::FilePath oobe_complete_flag_path = GetOobeCompleteFlagPath(); |
141 bool file_exists = base::PathExists(oobe_complete_flag_file_path); | 151 bool file_exists = base::PathExists(oobe_complete_flag_path); |
Greg Levin
2015/09/18 18:49:28
Is it generally considered desirable or meddling t
achuithb
2015/09/18 19:05:52
It's fine to clean up as you go along. If you make
| |
142 SaveIntegerPreferenceForced(prefs::kDeviceRegistered, file_exists ? 1 : 0); | 152 SaveIntegerPreferenceForced(prefs::kDeviceRegistered, file_exists ? 1 : 0); |
143 return file_exists; | 153 return file_exists; |
144 } | 154 } |
145 } | 155 } |
146 | 156 |
147 // static | 157 // static |
148 void StartupUtils::MarkDeviceRegistered(const base::Closure& done_callback) { | 158 void StartupUtils::MarkDeviceRegistered(const base::Closure& done_callback) { |
149 SaveIntegerPreferenceForced(prefs::kDeviceRegistered, 1); | 159 SaveIntegerPreferenceForced(prefs::kDeviceRegistered, 1); |
150 if (done_callback.is_null()) { | 160 if (done_callback.is_null()) { |
151 BrowserThread::PostTask( | 161 BrowserThread::PostTask( |
(...skipping 30 matching lines...) Expand all Loading... | |
182 | 192 |
183 // static | 193 // static |
184 void StartupUtils::SetInitialLocale(const std::string& locale) { | 194 void StartupUtils::SetInitialLocale(const std::string& locale) { |
185 if (l10n_util::IsValidLocaleSyntax(locale)) | 195 if (l10n_util::IsValidLocaleSyntax(locale)) |
186 SaveStringPreferenceForced(prefs::kInitialLocale, locale); | 196 SaveStringPreferenceForced(prefs::kInitialLocale, locale); |
187 else | 197 else |
188 NOTREACHED(); | 198 NOTREACHED(); |
189 } | 199 } |
190 | 200 |
191 } // namespace chromeos | 201 } // namespace chromeos |
OLD | NEW |