| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/token_web_data.h" | 5 #include "components/signin/core/webdata/token_web_data.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted_delete_on_message_loop.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" |
| 8 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 9 #include "chrome/browser/webdata/token_service_table.h" | 11 #include "components/signin/core/webdata/token_service_table.h" |
| 10 #include "components/webdata/common/web_database_service.h" | 12 #include "components/webdata/common/web_database_service.h" |
| 11 #include "content/public/browser/browser_thread.h" | |
| 12 | 13 |
| 13 using base::Bind; | 14 using base::Bind; |
| 14 using base::Time; | 15 using base::Time; |
| 15 using content::BrowserThread; | |
| 16 | 16 |
| 17 class TokenWebDataBackend | 17 class TokenWebDataBackend |
| 18 : public base::RefCountedThreadSafe<TokenWebDataBackend, | 18 : public base::RefCountedDeleteOnMessageLoop<TokenWebDataBackend> { |
| 19 BrowserThread::DeleteOnDBThread> { | |
| 20 | 19 |
| 21 public: | 20 public: |
| 22 TokenWebDataBackend() { | 21 TokenWebDataBackend(scoped_refptr<base::MessageLoopProxy> db_thread) |
| 22 : base::RefCountedDeleteOnMessageLoop<TokenWebDataBackend>(db_thread) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 WebDatabase::State RemoveAllTokens(WebDatabase* db) { | 25 WebDatabase::State RemoveAllTokens(WebDatabase* db) { |
| 26 if (TokenServiceTable::FromWebDatabase(db)->RemoveAllTokens()) { | 26 if (TokenServiceTable::FromWebDatabase(db)->RemoveAllTokens()) { |
| 27 return WebDatabase::COMMIT_NEEDED; | 27 return WebDatabase::COMMIT_NEEDED; |
| 28 } | 28 } |
| 29 return WebDatabase::COMMIT_NOT_NEEDED; | 29 return WebDatabase::COMMIT_NOT_NEEDED; |
| 30 } | 30 } |
| 31 | 31 |
| 32 WebDatabase::State RemoveTokenForService( | 32 WebDatabase::State RemoveTokenForService( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 52 TokenServiceTable::FromWebDatabase(db)->GetAllTokens(&map); | 52 TokenServiceTable::FromWebDatabase(db)->GetAllTokens(&map); |
| 53 return scoped_ptr<WDTypedResult>( | 53 return scoped_ptr<WDTypedResult>( |
| 54 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); | 54 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 protected: | 57 protected: |
| 58 virtual ~TokenWebDataBackend() { | 58 virtual ~TokenWebDataBackend() { |
| 59 } | 59 } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 friend struct BrowserThread::DeleteOnThread<BrowserThread::DB>; | 62 friend class base::RefCountedDeleteOnMessageLoop<TokenWebDataBackend>; |
| 63 friend class base::DeleteHelper<TokenWebDataBackend>; | 63 friend class base::DeleteHelper<TokenWebDataBackend>; |
| 64 // We have to friend RCTS<> so WIN shared-lib build is happy | |
| 65 // (http://crbug/112250). | |
| 66 friend class base::RefCountedThreadSafe<TokenWebDataBackend, | |
| 67 BrowserThread::DeleteOnDBThread>; | |
| 68 | |
| 69 }; | 64 }; |
| 70 | 65 |
| 71 TokenWebData::TokenWebData(scoped_refptr<WebDatabaseService> wdbs, | 66 TokenWebData::TokenWebData(scoped_refptr<WebDatabaseService> wdbs, |
| 72 const ProfileErrorCallback& callback) | 67 scoped_refptr<base::MessageLoopProxy> ui_thread, |
| 73 : WebDataServiceBase(wdbs, callback, | 68 scoped_refptr<base::MessageLoopProxy> db_thread, |
| 74 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)), | 69 const ProfileErrorCallback& callback) |
| 75 token_backend_(new TokenWebDataBackend()) { | 70 : WebDataServiceBase(wdbs, callback, ui_thread), |
| 71 token_backend_(new TokenWebDataBackend(db_thread)) { |
| 76 } | 72 } |
| 77 | 73 |
| 78 void TokenWebData::SetTokenForService(const std::string& service, | 74 void TokenWebData::SetTokenForService(const std::string& service, |
| 79 const std::string& token) { | 75 const std::string& token) { |
| 80 wdbs_->ScheduleDBTask(FROM_HERE, | 76 wdbs_->ScheduleDBTask(FROM_HERE, |
| 81 Bind(&TokenWebDataBackend::SetTokenForService, token_backend_, | 77 Bind(&TokenWebDataBackend::SetTokenForService, token_backend_, |
| 82 service, token)); | 78 service, token)); |
| 83 } | 79 } |
| 84 | 80 |
| 85 void TokenWebData::RemoveAllTokens() { | 81 void TokenWebData::RemoveAllTokens() { |
| 86 wdbs_->ScheduleDBTask(FROM_HERE, | 82 wdbs_->ScheduleDBTask(FROM_HERE, |
| 87 Bind(&TokenWebDataBackend::RemoveAllTokens, token_backend_)); | 83 Bind(&TokenWebDataBackend::RemoveAllTokens, token_backend_)); |
| 88 } | 84 } |
| 89 | 85 |
| 90 void TokenWebData::RemoveTokenForService(const std::string& service) { | 86 void TokenWebData::RemoveTokenForService(const std::string& service) { |
| 91 wdbs_->ScheduleDBTask(FROM_HERE, | 87 wdbs_->ScheduleDBTask(FROM_HERE, |
| 92 Bind(&TokenWebDataBackend::RemoveTokenForService, token_backend_, | 88 Bind(&TokenWebDataBackend::RemoveTokenForService, token_backend_, |
| 93 service)); | 89 service)); |
| 94 } | 90 } |
| 95 | 91 |
| 96 // Null on failure. Success is WDResult<std::string> | 92 // Null on failure. Success is WDResult<std::string> |
| 97 WebDataServiceBase::Handle TokenWebData::GetAllTokens( | 93 WebDataServiceBase::Handle TokenWebData::GetAllTokens( |
| 98 WebDataServiceConsumer* consumer) { | 94 WebDataServiceConsumer* consumer) { |
| 99 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | 95 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, |
| 100 Bind(&TokenWebDataBackend::GetAllTokens, token_backend_), consumer); | 96 Bind(&TokenWebDataBackend::GetAllTokens, token_backend_), consumer); |
| 101 } | 97 } |
| 102 | 98 |
| 103 TokenWebData::TokenWebData() | 99 TokenWebData::TokenWebData(scoped_refptr<base::MessageLoopProxy> ui_thread, |
| 104 : WebDataServiceBase(NULL, ProfileErrorCallback(), | 100 scoped_refptr<base::MessageLoopProxy> db_thread) |
| 105 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)), | 101 : WebDataServiceBase(NULL, ProfileErrorCallback(), ui_thread), |
| 106 token_backend_(new TokenWebDataBackend()) { | 102 token_backend_(new TokenWebDataBackend(db_thread)) { |
| 107 } | 103 } |
| 108 | 104 |
| 109 TokenWebData::~TokenWebData() { | 105 TokenWebData::~TokenWebData() { |
| 110 } | 106 } |
| OLD | NEW |