| 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" |  | 
|   13 #ifdef DEBUG |   12 #ifdef DEBUG | 
|   14 #include "content/public/browser/browser_thread.h" |   13 #include "content/public/browser/browser_thread.h" | 
|   15 #endif |   14 #endif | 
|   16 #include "content/public/browser/notification_details.h" |  | 
|   17 #include "content/public/browser/notification_service.h" |  | 
|   18 #include "content/public/browser/notification_source.h" |  | 
|   19  |   15  | 
|   20 //////////////////////////////////////////////////////////////////////////////// |   16 //////////////////////////////////////////////////////////////////////////////// | 
|   21 // |   17 // | 
|   22 // WebDataServiceBase implementation. |   18 // WebDataServiceBase implementation. | 
|   23 // |   19 // | 
|   24 //////////////////////////////////////////////////////////////////////////////// |   20 //////////////////////////////////////////////////////////////////////////////// | 
|   25  |   21  | 
|   26 using base::Bind; |   22 using base::Bind; | 
|   27 using base::Time; |   23 using base::Time; | 
|   28 using content::BrowserThread; |   24 using content::BrowserThread; | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   91  |   87  | 
|   92 WebDataServiceBase::~WebDataServiceBase() { |   88 WebDataServiceBase::~WebDataServiceBase() { | 
|   93   DCHECK(!db_thread_user_data_.get()) << "Forgot to call ShutdownOnUIThread?"; |   89   DCHECK(!db_thread_user_data_.get()) << "Forgot to call ShutdownOnUIThread?"; | 
|   94 } |   90 } | 
|   95  |   91  | 
|   96 void WebDataServiceBase::ShutdownOnDBThread() { |   92 void WebDataServiceBase::ShutdownOnDBThread() { | 
|   97   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |   93   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 
|   98   db_thread_user_data_.reset(); |   94   db_thread_user_data_.reset(); | 
|   99 } |   95 } | 
|  100  |   96  | 
|  101 //////////////////////////////////////////////////////////////////////////////// |   97 void WebDataServiceBase::NotifyDatabaseLoadedOnUIThread() {} | 
|  102 // |  | 
|  103 // The following methods are executed on the DB thread. |  | 
|  104 // |  | 
|  105 //////////////////////////////////////////////////////////////////////////////// |  | 
|  106  |   98  | 
|  107 void WebDataServiceBase::DBInitFailed(sql::InitStatus sql_status) { |   99 void WebDataServiceBase::DBInitFailed(sql::InitStatus sql_status) { | 
|  108   if (!profile_error_callback_.is_null()) |  100   if (!profile_error_callback_.is_null()) | 
|  109     profile_error_callback_.Run(sql_status); |  101     profile_error_callback_.Run(sql_status); | 
|  110 } |  102 } | 
|  111  |  103  | 
|  112 void WebDataServiceBase::NotifyDatabaseLoadedOnUIThread() { |  104 void WebDataServiceBase::DBInitSucceeded() { | 
|  113   db_loaded_ = true; |  105   db_loaded_ = true; | 
|  114   // Notify that the database has been initialized. |  106   NotifyDatabaseLoadedOnUIThread(); | 
|  115   content::NotificationService::current()->Notify( |  | 
|  116       chrome::NOTIFICATION_WEB_DATABASE_LOADED, |  | 
|  117       content::Source<WebDataServiceBase>(this), |  | 
|  118       content::NotificationService::NoDetails()); |  | 
|  119 } |  107 } | 
|  120  |  108  | 
 |  109 // Executed on DB thread. | 
|  121 void WebDataServiceBase::DatabaseInitOnDB(sql::InitStatus status) { |  110 void WebDataServiceBase::DatabaseInitOnDB(sql::InitStatus status) { | 
|  122   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |  111   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 
|  123   if (status == sql::INIT_OK) { |  112   if (status == sql::INIT_OK) { | 
|  124     BrowserThread::PostTask( |  113     BrowserThread::PostTask( | 
|  125         BrowserThread::UI, FROM_HERE, |  114         BrowserThread::UI, FROM_HERE, | 
|  126         base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this)); |  115         base::Bind(&WebDataServiceBase::DBInitSucceeded, this)); | 
|  127   } else { |  116   } else { | 
|  128     BrowserThread::PostTask( |  117     BrowserThread::PostTask( | 
|  129         BrowserThread::UI, FROM_HERE, |  118         BrowserThread::UI, FROM_HERE, | 
|  130         base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); |  119         base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); | 
|  131   } |  120   } | 
|  132 } |  121 } | 
|  133  |  | 
| OLD | NEW |