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

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

Issue 12695015: Split Autofill webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/api/webdata/web_data_service_base.h" 5 #include "chrome/browser/api/webdata/web_data_service_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/profile_error_dialog.h"
13 #include "chrome/browser/webdata/web_database_service.h" 12 #include "chrome/browser/webdata/web_database_service.h"
14 #include "chrome/common/chrome_constants.h" 13 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
16 #ifdef DEBUG 15 #ifdef DEBUG
17 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
18 #endif 17 #endif
19 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
22 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h"
24 21
25 //////////////////////////////////////////////////////////////////////////////// 22 ////////////////////////////////////////////////////////////////////////////////
26 // 23 //
27 // WebDataServiceBase implementation. 24 // WebDataServiceBase implementation.
28 // 25 //
29 //////////////////////////////////////////////////////////////////////////////// 26 ////////////////////////////////////////////////////////////////////////////////
30 27
31 using base::Bind; 28 using base::Bind;
32 using base::Time; 29 using base::Time;
33 using content::BrowserThread; 30 using content::BrowserThread;
34 31
35 WebDataServiceBase::WebDataServiceBase() 32 WebDataServiceBase::WebDataServiceBase(
36 : db_loaded_(false) { 33 scoped_refptr<WebDatabaseService> wdbs,
34 const ProfileErrorCallback& callback)
35 : wdbs_(wdbs),
36 db_loaded_(false),
37 profile_error_callback_(callback) {
37 // WebDataService requires DB thread if instantiated. 38 // WebDataService requires DB thread if instantiated.
38 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) 39 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL)
39 // if you do not want to instantiate WebDataService in your test. 40 // if you do not want to instantiate WebDataService in your test.
40 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); 41 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB));
41 } 42 }
42 43
43 void WebDataServiceBase::ShutdownOnUIThread() { 44 void WebDataServiceBase::ShutdownOnUIThread() {
44 db_loaded_ = false; 45 db_loaded_ = false;
45 ShutdownDatabase(); 46 BrowserThread::PostTask(
47 BrowserThread::DB, FROM_HERE,
48 base::Bind(&WebDataServiceBase::ShutdownOnDBThread, this));
46 } 49 }
47 50
48 void WebDataServiceBase::Init(const base::FilePath& path) { 51 void WebDataServiceBase::Init(const base::FilePath& path) {
49 wdbs_.reset(new WebDatabaseService(path));
50 wdbs_->LoadDatabase(Bind(&WebDataServiceBase::DatabaseInitOnDB, this)); 52 wdbs_->LoadDatabase(Bind(&WebDataServiceBase::DatabaseInitOnDB, this));
51 } 53 }
52 54
53 void WebDataServiceBase::UnloadDatabase() { 55 void WebDataServiceBase::UnloadDatabase() {
54 if (!wdbs_) 56 if (!wdbs_)
55 return; 57 return;
56 wdbs_->UnloadDatabase(); 58 wdbs_->UnloadDatabase();
57 } 59 }
58 60
59 void WebDataServiceBase::ShutdownDatabase() { 61 void WebDataServiceBase::ShutdownDatabase() {
(...skipping 15 matching lines...) Expand all
75 bool WebDataServiceBase::IsDatabaseLoaded() { 77 bool WebDataServiceBase::IsDatabaseLoaded() {
76 return db_loaded_; 78 return db_loaded_;
77 } 79 }
78 80
79 WebDatabase* WebDataServiceBase::GetDatabase() { 81 WebDatabase* WebDataServiceBase::GetDatabase() {
80 if (!wdbs_) 82 if (!wdbs_)
81 return NULL; 83 return NULL;
82 return wdbs_->GetDatabaseOnDB(); 84 return wdbs_->GetDatabaseOnDB();
83 } 85 }
84 86
87 base::SupportsUserData* WebDataServiceBase::GetDBUserData() {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
89 if (!db_thread_user_data_)
90 db_thread_user_data_.reset(new SupportsUserDataAggregatable());
91 return db_thread_user_data_.get();
92 }
93
85 WebDataServiceBase::~WebDataServiceBase() { 94 WebDataServiceBase::~WebDataServiceBase() {
86 wdbs_.reset(); 95 wdbs_ = NULL;
96 }
97
98 void WebDataServiceBase::ShutdownOnDBThread() {
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
100 db_thread_user_data_.reset();
87 } 101 }
88 102
89 //////////////////////////////////////////////////////////////////////////////// 103 ////////////////////////////////////////////////////////////////////////////////
90 // 104 //
91 // The following methods are executed on the DB thread. 105 // The following methods are executed on the DB thread.
92 // 106 //
93 //////////////////////////////////////////////////////////////////////////////// 107 ////////////////////////////////////////////////////////////////////////////////
94 108
95 void WebDataServiceBase::DBInitFailed(sql::InitStatus sql_status) { 109 void WebDataServiceBase::DBInitFailed(sql::InitStatus sql_status) {
96 ShowProfileErrorDialog( 110 if (!profile_error_callback_.is_null())
97 (sql_status == sql::INIT_FAILURE) ? 111 profile_error_callback_.Run(sql_status);
98 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
99 } 112 }
100 113
101 void WebDataServiceBase::NotifyDatabaseLoadedOnUIThread() { 114 void WebDataServiceBase::NotifyDatabaseLoadedOnUIThread() {
102 db_loaded_ = true; 115 db_loaded_ = true;
103 // Notify that the database has been initialized. 116 // Notify that the database has been initialized.
104 content::NotificationService::current()->Notify( 117 content::NotificationService::current()->Notify(
105 chrome::NOTIFICATION_WEB_DATABASE_LOADED, 118 chrome::NOTIFICATION_WEB_DATABASE_LOADED,
106 content::Source<WebDataServiceBase>(this), 119 content::Source<WebDataServiceBase>(this),
107 content::NotificationService::NoDetails()); 120 content::NotificationService::NoDetails());
108 } 121 }
109 122
110 void WebDataServiceBase::DatabaseInitOnDB(sql::InitStatus status) { 123 void WebDataServiceBase::DatabaseInitOnDB(sql::InitStatus status) {
111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
112 if (status == sql::INIT_OK) { 125 if (status == sql::INIT_OK) {
113 BrowserThread::PostTask( 126 BrowserThread::PostTask(
114 BrowserThread::UI, FROM_HERE, 127 BrowserThread::UI, FROM_HERE,
115 base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this)); 128 base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this));
116 } else { 129 } else {
117 BrowserThread::PostTask( 130 BrowserThread::PostTask(
118 BrowserThread::UI, FROM_HERE, 131 BrowserThread::UI, FROM_HERE,
119 base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); 132 base::Bind(&WebDataServiceBase::DBInitFailed, this, status));
120 } 133 }
121 } 134 }
122 135
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698