OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
Jói
2013/05/23 17:58:08
2013, and no (c)
Cait (Slow)
2013/05/24 16:17:08
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/webdata/token_web_data.h" | |
6 | |
7 #include "base/stl_util.h" | |
8 #include "chrome/browser/webdata/token_service_table.h" | |
9 #include "components/webdata/common/web_database_service.h" | |
10 | |
11 using base::Bind; | |
12 using base::Time; | |
13 using content::BrowserThread; | |
14 | |
15 class TokenWebDataBackend | |
16 : public base::RefCountedThreadSafe<TokenWebDataBackend, | |
17 BrowserThread::DeleteOnDBThread> { | |
18 | |
19 public: | |
20 TokenWebDataBackend() { | |
21 } | |
22 | |
23 WebDatabase::State RemoveAllTokens(WebDatabase* db) { | |
24 if (TokenServiceTable::FromWebDatabase(db)->RemoveAllTokens()) { | |
25 return WebDatabase::COMMIT_NEEDED; | |
26 } | |
27 return WebDatabase::COMMIT_NOT_NEEDED; | |
28 } | |
29 | |
30 WebDatabase::State SetTokenForService( | |
31 const std::string& service, const std::string& token, WebDatabase* db) { | |
32 if (TokenServiceTable::FromWebDatabase(db)->SetTokenForService(service, | |
33 token)) { | |
34 return WebDatabase::COMMIT_NEEDED; | |
35 } | |
36 return WebDatabase::COMMIT_NOT_NEEDED; | |
37 } | |
38 | |
39 scoped_ptr<WDTypedResult> GetAllTokens(WebDatabase* db) { | |
40 std::map<std::string, std::string> map; | |
41 TokenServiceTable::FromWebDatabase(db)->GetAllTokens(&map); | |
42 return scoped_ptr<WDTypedResult>( | |
43 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); | |
44 } | |
45 | |
46 protected: | |
47 virtual ~TokenWebDataBackend() { | |
48 } | |
49 | |
50 private: | |
51 friend struct BrowserThread::DeleteOnThread<BrowserThread::DB>; | |
52 friend class base::DeleteHelper<TokenWebDataBackend>; | |
53 // We have to friend RCTS<> so WIN shared-lib build is happy | |
54 // (http://crbug/112250). | |
55 friend class base::RefCountedThreadSafe<TokenWebDataBackend, | |
56 BrowserThread::DeleteOnDBThread>; | |
57 | |
58 }; | |
59 | |
60 TokenWebData::TokenWebData(scoped_refptr<WebDatabaseService> wdbs, | |
61 const ProfileErrorCallback& callback) | |
62 : WebDataServiceBase(wdbs, callback), | |
63 token_backend_(new TokenWebDataBackend()) { | |
64 } | |
65 | |
66 void TokenWebData::SetTokenForService(const std::string& service, | |
67 const std::string& token) { | |
68 wdbs_->ScheduleDBTask(FROM_HERE, | |
69 Bind(&TokenWebDataBackend::SetTokenForService, token_backend_, | |
70 service, token)); | |
71 } | |
72 | |
73 void TokenWebData::RemoveAllTokens() { | |
74 wdbs_->ScheduleDBTask(FROM_HERE, | |
75 Bind(&TokenWebDataBackend::RemoveAllTokens, token_backend_)); | |
76 } | |
77 | |
78 // Null on failure. Success is WDResult<std::string> | |
79 WebDataServiceBase::Handle TokenWebData::GetAllTokens( | |
80 WebDataServiceConsumer* consumer) { | |
81 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | |
82 Bind(&TokenWebDataBackend::GetAllTokens, token_backend_), consumer); | |
83 } | |
84 | |
85 TokenWebData::TokenWebData() | |
86 : WebDataServiceBase(NULL, ProfileErrorCallback()), | |
87 token_backend_(new TokenWebDataBackend()) { | |
88 } | |
89 | |
90 TokenWebData::~TokenWebData() { | |
91 } | |
OLD | NEW |