| 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/password_manager/password_store_x.h" | 5 #include "chrome/browser/password_manager/password_store_x.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 // it before deleting the file just in case there is some problem deleting | 253 // it before deleting the file just in case there is some problem deleting |
| 254 // the file (e.g. directory is not writable, but file is), which would | 254 // the file (e.g. directory is not writable, but file is), which would |
| 255 // otherwise cause passwords to re-migrate next (or maybe every) time. | 255 // otherwise cause passwords to re-migrate next (or maybe every) time. |
| 256 DeleteAndRecreateDatabaseFile(); | 256 DeleteAndRecreateDatabaseFile(); |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 ssize_t result = ok ? forms.size() : -1; | 259 ssize_t result = ok ? forms.size() : -1; |
| 260 STLDeleteElements(&forms); | 260 STLDeleteElements(&forms); |
| 261 return result; | 261 return result; |
| 262 } | 262 } |
| 263 | |
| 264 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) | |
| 265 // static | |
| 266 void PasswordStoreX::RegisterProfilePrefs( | |
| 267 user_prefs::PrefRegistrySyncable* registry) { | |
| 268 // Normally we should be on the UI thread here, but in tests we might not. | |
| 269 registry->RegisterBooleanPref( | |
| 270 prefs::kPasswordsUseLocalProfileId, | |
| 271 // default: passwords don't use local ids | |
| 272 false, | |
| 273 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 274 } | |
| 275 | |
| 276 // static | |
| 277 bool PasswordStoreX::PasswordsUseLocalProfileId(PrefService* prefs) { | |
| 278 // Normally we should be on the UI thread here, but in tests we might not. | |
| 279 return prefs->GetBoolean(prefs::kPasswordsUseLocalProfileId); | |
| 280 } | |
| 281 | |
| 282 namespace { | |
| 283 // This function is a hack to do something not entirely thread safe: the pref | |
| 284 // service comes from the UI thread, but it's not ref counted. We keep a pointer | |
| 285 // to it on the DB thread, and need to invoke a method on the UI thread. This | |
| 286 // function does that for us without requiring ref counting the pref service. | |
| 287 // TODO(mdm): Fix this if it becomes a problem. Given that this function will | |
| 288 // be called once ever per profile, it probably will not cause a problem... | |
| 289 void UISetPasswordsUseLocalProfileId(PrefService* prefs) { | |
| 290 prefs->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
| 291 } | |
| 292 } // anonymous namespace | |
| 293 | |
| 294 // static | |
| 295 void PasswordStoreX::SetPasswordsUseLocalProfileId(PrefService* prefs) { | |
| 296 // This method should work on any thread, but we expect the DB thread. | |
| 297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
| 298 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 299 base::Bind(&UISetPasswordsUseLocalProfileId, prefs)); | |
| 300 } | |
| 301 #endif // !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) | |
| OLD | NEW |