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

Side by Side Diff: chrome/browser/webdata/web_data_service_factory.cc

Issue 12695015: Split Autofill webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to the end of WDS pipeline Created 7 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/webdata/web_data_service_factory.h" 5 #include "chrome/browser/webdata/web_data_service_factory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "chrome/browser/profiles/profile_dependency_manager.h" 9 #include "chrome/browser/profiles/profile_dependency_manager.h"
10 #include "chrome/browser/ui/profile_error_dialog.h" 10 #include "chrome/browser/ui/profile_error_dialog.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 AutofillProfileSyncableService::CreateForWebDataService(web_data); 42 AutofillProfileSyncableService::CreateForWebDataService(web_data);
43 } 43 }
44 44
45 } // namespace 45 } // namespace
46 46
47 WebDataServiceWrapper::WebDataServiceWrapper() {} 47 WebDataServiceWrapper::WebDataServiceWrapper() {}
48 48
49 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) { 49 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) {
50 base::FilePath path = profile->GetPath(); 50 base::FilePath path = profile->GetPath();
51 path = path.Append(chrome::kWebDataFilename); 51 path = path.Append(chrome::kWebDataFilename);
52 web_data_service_ = new WebDataService(base::Bind(&ProfileErrorCallback)); 52
53 // TODO (caitkp): Rework the callbacks here. They're ugly.
54
55 web_database_ = new WebDatabaseService(path);
53 56
54 // All tables objects that participate in managing the database must 57 // All tables objects that participate in managing the database must
55 // be added here. 58 // be added here.
56 web_data_service_->AddTable( 59 web_database_->AddTable(
57 scoped_ptr<WebDatabaseTable>(new AutofillTable())); 60 scoped_ptr<WebDatabaseTable>(new AutofillTable()));
58 web_data_service_->AddTable( 61 web_database_->AddTable(
59 scoped_ptr<WebDatabaseTable>(new KeywordTable())); 62 scoped_ptr<WebDatabaseTable>(new KeywordTable()));
60 // TODO(mdm): We only really need the LoginsTable on Windows for IE7 password 63 // TODO(mdm): We only really need the LoginsTable on Windows for IE7 password
61 // access, but for now, we still create it on all platforms since it deletes 64 // access, but for now, we still create it on all platforms since it deletes
62 // the old logins table. We can remove this after a while, e.g. in M22 or so. 65 // the old logins table. We can remove this after a while, e.g. in M22 or so.
63 web_data_service_->AddTable( 66 web_database_->AddTable(
64 scoped_ptr<WebDatabaseTable>(new LoginsTable())); 67 scoped_ptr<WebDatabaseTable>(new LoginsTable()));
65 web_data_service_->AddTable( 68 web_database_->AddTable(
66 scoped_ptr<WebDatabaseTable>(new TokenServiceTable())); 69 scoped_ptr<WebDatabaseTable>(new TokenServiceTable()));
67 web_data_service_->AddTable( 70 web_database_->AddTable(
68 scoped_ptr<WebDatabaseTable>(new WebAppsTable())); 71 scoped_ptr<WebDatabaseTable>(new WebAppsTable()));
69 // TODO(thakis): Add a migration to delete the SQL table used by 72 // TODO(thakis): Add a migration to delete the SQL table used by
70 // WebIntentsTable, then remove this. 73 // WebIntentsTable, then remove this.
71 web_data_service_->AddTable( 74 web_database_->AddTable(
72 scoped_ptr<WebDatabaseTable>(new WebIntentsTable())); 75 scoped_ptr<WebDatabaseTable>(new WebIntentsTable()));
73 76
77 web_database_->LoadDatabase(WebDatabaseService::InitCallback());
78
79 web_data_service_ = new WebDataService(
80 web_database_, base::Bind(&ProfileErrorCallback));
74 web_data_service_->Init(path); 81 web_data_service_->Init(path);
75 82
83 autofill_web_data_ = new AutofillWebDataServiceImpl(
84 web_database_, base::Bind(&ProfileErrorCallback));
85 autofill_web_data_->Init(path);
86
76 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 87 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
77 base::Bind(&InitSyncableServicesOnDBThread, 88 base::Bind(&InitSyncableServicesOnDBThread,
78 web_data_service_)); 89 web_data_service_));
79 } 90 }
80 91
81 WebDataServiceWrapper::~WebDataServiceWrapper() { 92 WebDataServiceWrapper::~WebDataServiceWrapper() {
82 } 93 }
83 94
84 void WebDataServiceWrapper::Shutdown() { 95 void WebDataServiceWrapper::Shutdown() {
85 web_data_service_->ShutdownOnUIThread(); 96 web_data_service_->ShutdownOnUIThread();
97 autofill_web_data_->ShutdownOnUIThread();
98 web_database_->ShutdownDatabase();
86 web_data_service_ = NULL; 99 web_data_service_ = NULL;
87 } 100 }
88 101
89 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { 102 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() {
90 return web_data_service_.get(); 103 return web_data_service_.get();
91 } 104 }
92 105
106 scoped_refptr<AutofillWebDataService>
107 WebDataServiceWrapper::GetAutofillWebData() {
108 return autofill_web_data_.get();
109 }
110
93 // static 111 // static
94 scoped_refptr<AutofillWebDataService> 112 scoped_refptr<AutofillWebDataService>
95 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) { 113 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) {
96 // For this service, the implicit/explicit distinction doesn't 114 // For this service, the implicit/explicit distinction doesn't
97 // really matter; it's just used for a DCHECK. So we currently 115 // really matter; it's just used for a DCHECK. So we currently
98 // cheat and always say EXPLICIT_ACCESS. 116 // cheat and always say EXPLICIT_ACCESS.
99 scoped_refptr<WebDataService> service = WebDataServiceFactory::GetForProfile( 117 WebDataServiceWrapper* wrapper =
100 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); 118 WebDataServiceFactory::GetWrapper(
101 119 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS);
102 if (service.get()) { 120 if (wrapper)
103 return scoped_refptr<AutofillWebDataService>( 121 return wrapper->GetAutofillWebData();
104 new AutofillWebDataServiceImpl(service)); 122 // |wrapper| can be NULL in Incognito mode.
105 } else { 123 return scoped_refptr<AutofillWebDataService>(NULL);
106 return scoped_refptr<AutofillWebDataService>(NULL);
107 }
108 } 124 }
109 125
110 // static 126 // static
111 scoped_refptr<WebDataService> WebDataService::FromBrowserContext( 127 scoped_refptr<WebDataService> WebDataService::FromBrowserContext(
112 content::BrowserContext* context) { 128 content::BrowserContext* context) {
113 // For this service, the implicit/explicit distinction doesn't 129 // For this service, the implicit/explicit distinction doesn't
114 // really matter; it's just used for a DCHECK. So we currently 130 // really matter; it's just used for a DCHECK. So we currently
115 // cheat and always say EXPLICIT_ACCESS. 131 // cheat and always say EXPLICIT_ACCESS.
116 return WebDataServiceFactory::GetForProfile( 132 return WebDataServiceFactory::GetForProfile(
117 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); 133 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS);
118 } 134 }
119 135
120 WebDataServiceFactory::WebDataServiceFactory() 136 WebDataServiceFactory::WebDataServiceFactory()
121 : ProfileKeyedServiceFactory( 137 : ProfileKeyedServiceFactory(
122 "WebDataService", 138 "WebDataService",
123 ProfileDependencyManager::GetInstance()) { 139 ProfileDependencyManager::GetInstance()) {
124 // WebDataServiceFactory has no dependecies. 140 // WebDataServiceFactory has no dependecies.
125 } 141 }
126 142
127 WebDataServiceFactory::~WebDataServiceFactory() {} 143 WebDataServiceFactory::~WebDataServiceFactory() {}
128 144
129 // static 145 // static
146 WebDataServiceWrapper* WebDataServiceFactory::GetWrapper(
147 Profile* profile, Profile::ServiceAccessType access_type) {
148 // If |access_type| starts being used for anything other than this
149 // DCHECK, we need to start taking it as a parameter to
150 // AutofillWebDataServiceImpl::FromBrowserContext (see above).
151 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
152 return static_cast<WebDataServiceWrapper*>(
153 GetInstance()->GetServiceForProfile(profile, true));
154 }
155
156 // static
130 scoped_refptr<WebDataService> WebDataServiceFactory::GetForProfile( 157 scoped_refptr<WebDataService> WebDataServiceFactory::GetForProfile(
131 Profile* profile, Profile::ServiceAccessType access_type) { 158 Profile* profile, Profile::ServiceAccessType access_type) {
132 // If |access_type| starts being used for anything other than this 159 // If |access_type| starts being used for anything other than this
133 // DCHECK, we need to start taking it as a parameter to 160 // DCHECK, we need to start taking it as a parameter to
134 // AutofillWebDataServiceImpl::FromBrowserContext (see above). 161 // AutofillWebDataServiceImpl::FromBrowserContext (see above).
135 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); 162 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
136 WebDataServiceWrapper* wrapper = 163 WebDataServiceWrapper* wrapper =
137 static_cast<WebDataServiceWrapper*>( 164 static_cast<WebDataServiceWrapper*>(
138 GetInstance()->GetServiceForProfile(profile, true)); 165 GetInstance()->GetServiceForProfile(profile, true));
139 if (wrapper) 166 if (wrapper)
(...skipping 28 matching lines...) Expand all
168 } 195 }
169 196
170 ProfileKeyedService* 197 ProfileKeyedService*
171 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const { 198 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const {
172 return new WebDataServiceWrapper(profile); 199 return new WebDataServiceWrapper(profile);
173 } 200 }
174 201
175 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { 202 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const {
176 return true; 203 return true;
177 } 204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698