| 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_factory.h" | 5 #include "chrome/browser/password_manager/password_store_factory.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/environment.h" | 8 #include "base/environment.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/password_manager/login_database.h" | 10 #include "chrome/browser/password_manager/login_database.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 scoped_refptr<PasswordStore> PasswordStoreFactory::GetForProfile( | 48 scoped_refptr<PasswordStore> PasswordStoreFactory::GetForProfile( |
| 49 Profile* profile, | 49 Profile* profile, |
| 50 Profile::ServiceAccessType sat) { | 50 Profile::ServiceAccessType sat) { |
| 51 if (sat == Profile::IMPLICIT_ACCESS && profile->IsOffTheRecord()) { | 51 if (sat == Profile::IMPLICIT_ACCESS && profile->IsOffTheRecord()) { |
| 52 NOTREACHED() << "This profile is OffTheRecord"; | 52 NOTREACHED() << "This profile is OffTheRecord"; |
| 53 return NULL; | 53 return NULL; |
| 54 } | 54 } |
| 55 | 55 |
| 56 return static_cast<PasswordStore*>( | 56 return static_cast<PasswordStore*>( |
| 57 GetInstance()->GetServiceForProfile(profile, true).get()); | 57 GetInstance()->GetServiceForBrowserContext(profile, true).get()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // static | 60 // static |
| 61 PasswordStoreFactory* PasswordStoreFactory::GetInstance() { | 61 PasswordStoreFactory* PasswordStoreFactory::GetInstance() { |
| 62 return Singleton<PasswordStoreFactory>::get(); | 62 return Singleton<PasswordStoreFactory>::get(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 PasswordStoreFactory::PasswordStoreFactory() | 65 PasswordStoreFactory::PasswordStoreFactory() |
| 66 : RefcountedProfileKeyedServiceFactory( | 66 : RefcountedBrowserContextKeyedServiceFactory( |
| 67 "PasswordStore", | 67 "PasswordStore", |
| 68 ProfileDependencyManager::GetInstance()) { | 68 BrowserContextDependencyManager::GetInstance()) { |
| 69 DependsOn(WebDataServiceFactory::GetInstance()); | 69 DependsOn(WebDataServiceFactory::GetInstance()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 PasswordStoreFactory::~PasswordStoreFactory() {} | 72 PasswordStoreFactory::~PasswordStoreFactory() {} |
| 73 | 73 |
| 74 #if !defined(OS_CHROMEOS) && defined(USE_X11) | 74 #if !defined(OS_CHROMEOS) && defined(USE_X11) |
| 75 LocalProfileId PasswordStoreFactory::GetLocalProfileId( | 75 LocalProfileId PasswordStoreFactory::GetLocalProfileId( |
| 76 PrefService* prefs) const { | 76 PrefService* prefs) const { |
| 77 LocalProfileId id = prefs->GetInteger(prefs::kLocalProfileId); | 77 LocalProfileId id = prefs->GetInteger(prefs::kLocalProfileId); |
| 78 if (id == kInvalidLocalProfileId) { | 78 if (id == kInvalidLocalProfileId) { |
| 79 // Note that there are many more users than this. Thus, by design, this is | 79 // Note that there are many more users than this. Thus, by design, this is |
| 80 // not a unique id. However, it is large enough that it is very unlikely | 80 // not a unique id. However, it is large enough that it is very unlikely |
| 81 // that it would be repeated twice on a single machine. It is still possible | 81 // that it would be repeated twice on a single machine. It is still possible |
| 82 // for that to occur though, so the potential results of it actually | 82 // for that to occur though, so the potential results of it actually |
| 83 // happening should be considered when using this value. | 83 // happening should be considered when using this value. |
| 84 static const LocalProfileId kLocalProfileIdMask = | 84 static const LocalProfileId kLocalProfileIdMask = |
| 85 static_cast<LocalProfileId>((1 << 24) - 1); | 85 static_cast<LocalProfileId>((1 << 24) - 1); |
| 86 do { | 86 do { |
| 87 id = rand() & kLocalProfileIdMask; | 87 id = rand() & kLocalProfileIdMask; |
| 88 // TODO(mdm): scan other profiles to make sure they are not using this id? | 88 // TODO(mdm): scan other profiles to make sure they are not using this id? |
| 89 } while (id == kInvalidLocalProfileId); | 89 } while (id == kInvalidLocalProfileId); |
| 90 prefs->SetInteger(prefs::kLocalProfileId, id); | 90 prefs->SetInteger(prefs::kLocalProfileId, id); |
| 91 } | 91 } |
| 92 return id; | 92 return id; |
| 93 } | 93 } |
| 94 #endif | 94 #endif |
| 95 | 95 |
| 96 scoped_refptr<RefcountedProfileKeyedService> | 96 scoped_refptr<RefcountedBrowserContextKeyedService> |
| 97 PasswordStoreFactory::BuildServiceInstanceFor( | 97 PasswordStoreFactory::BuildServiceInstanceFor( |
| 98 content::BrowserContext* context) const { | 98 content::BrowserContext* context) const { |
| 99 Profile* profile = static_cast<Profile*>(context); | 99 Profile* profile = static_cast<Profile*>(context); |
| 100 | 100 |
| 101 scoped_refptr<PasswordStore> ps; | 101 scoped_refptr<PasswordStore> ps; |
| 102 base::FilePath login_db_file_path = profile->GetPath(); | 102 base::FilePath login_db_file_path = profile->GetPath(); |
| 103 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName); | 103 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName); |
| 104 LoginDatabase* login_db = new LoginDatabase(); | 104 LoginDatabase* login_db = new LoginDatabase(); |
| 105 { | 105 { |
| 106 // TODO(paivanof@gmail.com): execution of login_db->Init() should go | 106 // TODO(paivanof@gmail.com): execution of login_db->Init() should go |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 210 } |
| 211 | 211 |
| 212 content::BrowserContext* PasswordStoreFactory::GetBrowserContextToUse( | 212 content::BrowserContext* PasswordStoreFactory::GetBrowserContextToUse( |
| 213 content::BrowserContext* context) const { | 213 content::BrowserContext* context) const { |
| 214 return chrome::GetBrowserContextRedirectedInIncognito(context); | 214 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 215 } | 215 } |
| 216 | 216 |
| 217 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() const { | 217 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() const { |
| 218 return true; | 218 return true; |
| 219 } | 219 } |
| OLD | NEW |