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/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(const ProfileErrorCallback& callback) |
36 : db_loaded_(false) { | 33 : db_loaded_(false), |
| 34 profile_error_callback_(callback) { |
37 // WebDataService requires DB thread if instantiated. | 35 // WebDataService requires DB thread if instantiated. |
38 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) | 36 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) |
39 // if you do not want to instantiate WebDataService in your test. | 37 // if you do not want to instantiate WebDataService in your test. |
40 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); | 38 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); |
41 } | 39 } |
42 | 40 |
43 void WebDataServiceBase::ShutdownOnUIThread() { | 41 void WebDataServiceBase::ShutdownOnUIThread() { |
44 db_loaded_ = false; | 42 db_loaded_ = false; |
45 ShutdownDatabase(); | 43 ShutdownDatabase(); |
46 } | 44 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 wdbs_.reset(); | 84 wdbs_.reset(); |
87 } | 85 } |
88 | 86 |
89 //////////////////////////////////////////////////////////////////////////////// | 87 //////////////////////////////////////////////////////////////////////////////// |
90 // | 88 // |
91 // The following methods are executed on the DB thread. | 89 // The following methods are executed on the DB thread. |
92 // | 90 // |
93 //////////////////////////////////////////////////////////////////////////////// | 91 //////////////////////////////////////////////////////////////////////////////// |
94 | 92 |
95 void WebDataServiceBase::DBInitFailed(sql::InitStatus sql_status) { | 93 void WebDataServiceBase::DBInitFailed(sql::InitStatus sql_status) { |
96 ShowProfileErrorDialog( | 94 if (!profile_error_callback_.is_null()) |
97 (sql_status == sql::INIT_FAILURE) ? | 95 profile_error_callback_.Run(sql_status); |
98 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); | |
99 } | 96 } |
100 | 97 |
101 void WebDataServiceBase::NotifyDatabaseLoadedOnUIThread() { | 98 void WebDataServiceBase::NotifyDatabaseLoadedOnUIThread() { |
102 db_loaded_ = true; | 99 db_loaded_ = true; |
103 // Notify that the database has been initialized. | 100 // Notify that the database has been initialized. |
104 content::NotificationService::current()->Notify( | 101 content::NotificationService::current()->Notify( |
105 chrome::NOTIFICATION_WEB_DATABASE_LOADED, | 102 chrome::NOTIFICATION_WEB_DATABASE_LOADED, |
106 content::Source<WebDataServiceBase>(this), | 103 content::Source<WebDataServiceBase>(this), |
107 content::NotificationService::NoDetails()); | 104 content::NotificationService::NoDetails()); |
108 } | 105 } |
109 | 106 |
110 void WebDataServiceBase::DatabaseInitOnDB(sql::InitStatus status) { | 107 void WebDataServiceBase::DatabaseInitOnDB(sql::InitStatus status) { |
111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
112 if (status == sql::INIT_OK) { | 109 if (status == sql::INIT_OK) { |
113 BrowserThread::PostTask( | 110 BrowserThread::PostTask( |
114 BrowserThread::UI, FROM_HERE, | 111 BrowserThread::UI, FROM_HERE, |
115 base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this)); | 112 base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this)); |
116 } else { | 113 } else { |
117 BrowserThread::PostTask( | 114 BrowserThread::PostTask( |
118 BrowserThread::UI, FROM_HERE, | 115 BrowserThread::UI, FROM_HERE, |
119 base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); | 116 base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); |
120 } | 117 } |
121 } | 118 } |
122 | 119 |
OLD | NEW |