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/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/webdata/web_database_service.h" | 11 #include "chrome/browser/webdata/web_database_service.h" |
12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
13 #ifdef DEBUG | 13 #ifdef DEBUG |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 #endif | 15 #endif |
16 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
19 | 19 |
20 //////////////////////////////////////////////////////////////////////////////// | 20 //////////////////////////////////////////////////////////////////////////////// |
21 // | 21 // |
22 // WebDataServiceBase implementation. | 22 // WebDataServiceBase implementation. |
23 // | 23 // |
24 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
25 | 25 |
26 using base::Bind; | 26 using base::Bind; |
27 using base::Time; | 27 using base::Time; |
28 using content::BrowserThread; | 28 using content::BrowserThread; |
29 | 29 |
30 WebDataServiceBase::WebDataServiceBase(const base::FilePath& path, | 30 WebDataServiceBase::WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, |
31 const ProfileErrorCallback& callback) | 31 const ProfileErrorCallback& callback) |
32 : db_loaded_(false), | 32 : wdbs_(wdbs), |
33 path_(path), | 33 db_loaded_(false), |
34 profile_error_callback_(callback) { | 34 profile_error_callback_(callback) { |
35 // WebDataService requires DB thread if instantiated. | 35 // WebDataService requires DB thread if instantiated. |
36 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) | 36 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) |
37 // if you do not want to instantiate WebDataService in your test. | 37 // if you do not want to instantiate WebDataService in your test. |
38 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); | 38 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); |
39 } | 39 } |
40 | 40 |
41 void WebDataServiceBase::ShutdownOnUIThread() { | 41 void WebDataServiceBase::ShutdownOnUIThread() { |
42 db_loaded_ = false; | 42 db_loaded_ = false; |
43 BrowserThread::PostTask( | 43 BrowserThread::PostTask( |
44 BrowserThread::DB, FROM_HERE, | 44 BrowserThread::DB, FROM_HERE, |
45 base::Bind(&WebDataServiceBase::ShutdownOnDBThread, this)); | 45 base::Bind(&WebDataServiceBase::ShutdownOnDBThread, this)); |
46 ShutdownDatabase(); | |
47 } | 46 } |
48 | 47 |
49 void WebDataServiceBase::AddTable(scoped_ptr<WebDatabaseTable> table) { | 48 void WebDataServiceBase::AddTable(scoped_ptr<WebDatabaseTable> table) { |
50 if (!wdbs_.get()) | 49 DCHECK(wdbs_.get()); |
51 wdbs_.reset(new WebDatabaseService(path_)); | |
52 wdbs_->AddTable(table.Pass()); | 50 wdbs_->AddTable(table.Pass()); |
53 } | 51 } |
54 | 52 |
55 void WebDataServiceBase::Init() { | 53 void WebDataServiceBase::Init() { |
56 DCHECK(wdbs_.get()); | 54 DCHECK(wdbs_.get()); |
57 wdbs_->LoadDatabase(Bind(&WebDataServiceBase::DatabaseInitOnDB, this)); | 55 wdbs_->LoadDatabase(Bind(&WebDataServiceBase::DatabaseInitOnDB, this)); |
58 } | 56 } |
59 | 57 |
60 void WebDataServiceBase::UnloadDatabase() { | 58 void WebDataServiceBase::UnloadDatabase() { |
61 if (!wdbs_) | 59 if (!wdbs_) |
(...skipping 29 matching lines...) Expand all Loading... |
91 | 89 |
92 base::SupportsUserData* WebDataServiceBase::GetDBUserData() { | 90 base::SupportsUserData* WebDataServiceBase::GetDBUserData() { |
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
94 if (!db_thread_user_data_) | 92 if (!db_thread_user_data_) |
95 db_thread_user_data_.reset(new SupportsUserDataAggregatable()); | 93 db_thread_user_data_.reset(new SupportsUserDataAggregatable()); |
96 return db_thread_user_data_.get(); | 94 return db_thread_user_data_.get(); |
97 } | 95 } |
98 | 96 |
99 WebDataServiceBase::~WebDataServiceBase() { | 97 WebDataServiceBase::~WebDataServiceBase() { |
100 DCHECK(!db_thread_user_data_.get()) << "Forgot to call ShutdownOnUIThread?"; | 98 DCHECK(!db_thread_user_data_.get()) << "Forgot to call ShutdownOnUIThread?"; |
101 wdbs_.reset(); | |
102 } | 99 } |
103 | 100 |
104 void WebDataServiceBase::ShutdownOnDBThread() { | 101 void WebDataServiceBase::ShutdownOnDBThread() { |
105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
106 db_thread_user_data_.reset(); | 103 db_thread_user_data_.reset(); |
107 } | 104 } |
108 | 105 |
109 //////////////////////////////////////////////////////////////////////////////// | 106 //////////////////////////////////////////////////////////////////////////////// |
110 // | 107 // |
111 // The following methods are executed on the DB thread. | 108 // The following methods are executed on the DB thread. |
(...skipping 20 matching lines...) Expand all Loading... |
132 BrowserThread::PostTask( | 129 BrowserThread::PostTask( |
133 BrowserThread::UI, FROM_HERE, | 130 BrowserThread::UI, FROM_HERE, |
134 base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this)); | 131 base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this)); |
135 } else { | 132 } else { |
136 BrowserThread::PostTask( | 133 BrowserThread::PostTask( |
137 BrowserThread::UI, FROM_HERE, | 134 BrowserThread::UI, FROM_HERE, |
138 base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); | 135 base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); |
139 } | 136 } |
140 } | 137 } |
141 | 138 |
OLD | NEW |