Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/password_manager/password_store_factory.cc

Issue 9703038: Profiles: Really fix refcounted services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Forgot to save a file. >_< Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/password_manager/login_database.h" 9 #include "chrome/browser/password_manager/login_database.h"
10 #include "chrome/browser/password_manager/password_store.h"
10 #include "chrome/browser/password_manager/password_store_default.h" 11 #include "chrome/browser/password_manager/password_store_default.h"
11 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile_dependency_manager.h" 13 #include "chrome/browser/profiles/profile_dependency_manager.h"
13 #include "chrome/common/chrome_constants.h" 14 #include "chrome/common/chrome_constants.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 17
17 #if defined(OS_WIN) 18 #if defined(OS_WIN)
18 #include "chrome/browser/password_manager/password_store_win.h" 19 #include "chrome/browser/password_manager/password_store_win.h"
19 #elif defined(OS_MACOSX) 20 #elif defined(OS_MACOSX)
(...skipping 13 matching lines...) Expand all
33 34
34 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) 35 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
35 namespace { 36 namespace {
36 37
37 const LocalProfileId kInvalidLocalProfileId = 38 const LocalProfileId kInvalidLocalProfileId =
38 static_cast<LocalProfileId>(0); 39 static_cast<LocalProfileId>(0);
39 40
40 } // namespace 41 } // namespace
41 #endif 42 #endif
42 43
43 PasswordStore* PasswordStoreFactory::GetForProfile( 44 scoped_refptr<PasswordStore> PasswordStoreFactory::GetForProfile(
44 Profile* profile, 45 Profile* profile,
45 Profile::ServiceAccessType sat) { 46 Profile::ServiceAccessType sat) {
46 if (sat == Profile::IMPLICIT_ACCESS && profile->IsOffTheRecord()) { 47 if (sat == Profile::IMPLICIT_ACCESS && profile->IsOffTheRecord()) {
47 NOTREACHED() << "This profile is OffTheRecord"; 48 NOTREACHED() << "This profile is OffTheRecord";
48 return NULL; 49 return NULL;
49 } 50 }
50 51
51 return static_cast<PasswordStore*>(GetInstance()->GetBaseForProfile( 52 return static_cast<PasswordStore*>(
52 profile, true)); 53 GetInstance()->GetServiceForProfile(profile, true).get());
53 } 54 }
54 55
55 // static 56 // static
56 PasswordStoreFactory* PasswordStoreFactory::GetInstance() { 57 PasswordStoreFactory* PasswordStoreFactory::GetInstance() {
57 return Singleton<PasswordStoreFactory>::get(); 58 return Singleton<PasswordStoreFactory>::get();
58 } 59 }
59 60
60 PasswordStoreFactory::PasswordStoreFactory() 61 PasswordStoreFactory::PasswordStoreFactory()
61 : RefcountedProfileKeyedServiceFactory( 62 : RefcountedProfileKeyedServiceFactory(
62 "PasswordStore", 63 "PasswordStore",
(...skipping 21 matching lines...) Expand all
84 do { 85 do {
85 id = rand() & kLocalProfileIdMask; 86 id = rand() & kLocalProfileIdMask;
86 // TODO(mdm): scan other profiles to make sure they are not using this id? 87 // TODO(mdm): scan other profiles to make sure they are not using this id?
87 } while (id == kInvalidLocalProfileId); 88 } while (id == kInvalidLocalProfileId);
88 prefs->SetInteger(prefs::kLocalProfileId, id); 89 prefs->SetInteger(prefs::kLocalProfileId, id);
89 } 90 }
90 return id; 91 return id;
91 } 92 }
92 #endif // !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) 93 #endif // !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
93 94
94 RefcountedProfileKeyedService* PasswordStoreFactory::BuildServiceInstanceFor( 95 scoped_refptr<RefcountedProfileKeyedService>
95 Profile* profile) const { 96 PasswordStoreFactory::BuildServiceInstanceFor(Profile* profile) const {
96 scoped_refptr<PasswordStore> ps; 97 scoped_refptr<PasswordStore> ps;
97 FilePath login_db_file_path = profile->GetPath(); 98 FilePath login_db_file_path = profile->GetPath();
98 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName); 99 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
99 LoginDatabase* login_db = new LoginDatabase(); 100 LoginDatabase* login_db = new LoginDatabase();
100 if (!login_db->Init(login_db_file_path)) { 101 if (!login_db->Init(login_db_file_path)) {
101 LOG(ERROR) << "Could not initialize login database."; 102 LOG(ERROR) << "Could not initialize login database.";
102 delete login_db; 103 delete login_db;
103 return NULL; 104 return NULL;
104 } 105 }
105 #if defined(OS_WIN) 106 #if defined(OS_WIN)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 NOTIMPLEMENTED(); 179 NOTIMPLEMENTED();
179 #endif 180 #endif
180 if (!ps) 181 if (!ps)
181 delete login_db; 182 delete login_db;
182 183
183 if (!ps || !ps->Init()) { 184 if (!ps || !ps->Init()) {
184 NOTREACHED() << "Could not initialize password manager."; 185 NOTREACHED() << "Could not initialize password manager.";
185 return NULL; 186 return NULL;
186 } 187 }
187 188
188 return ps.release(); 189 return ps;
189 } 190 }
190 191
191 void PasswordStoreFactory::RegisterUserPrefs(PrefService* prefs) { 192 void PasswordStoreFactory::RegisterUserPrefs(PrefService* prefs) {
192 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) 193 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
193 prefs->RegisterIntegerPref(prefs::kLocalProfileId, 194 prefs->RegisterIntegerPref(prefs::kLocalProfileId,
194 kInvalidLocalProfileId, 195 kInvalidLocalProfileId,
195 PrefService::UNSYNCABLE_PREF); 196 PrefService::UNSYNCABLE_PREF);
196 197
197 // Notice that the preprocessor conditions above are exactly those that will 198 // Notice that the preprocessor conditions above are exactly those that will
198 // result in using PasswordStoreX in CreatePasswordStore() below. 199 // result in using PasswordStoreX in CreatePasswordStore() below.
199 PasswordStoreX::RegisterUserPrefs(prefs); 200 PasswordStoreX::RegisterUserPrefs(prefs);
200 #endif 201 #endif
201 } 202 }
202 203
203 bool PasswordStoreFactory::ServiceRedirectedInIncognito() { 204 bool PasswordStoreFactory::ServiceRedirectedInIncognito() {
204 return true; 205 return true;
205 } 206 }
206 207
207 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() { 208 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() {
208 return true; 209 return true;
209 } 210 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_factory.h ('k') | chrome/browser/password_manager/password_store_x.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698