forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split token-related methods from WebDataService
These are only used bu Signin/ and will move into the sign-in component once it gets created. TBR=atwilson@chromium.org,ben@chromium.org BUG=233552 Review URL: https://chromiumcodereview.appspot.com/15734014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202463 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
caitkp@chromium.org
committed
May 27, 2013
1 parent
9993d32
commit b69d631
Showing
19 changed files
with
230 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/webdata/token_web_data.h" | ||
|
||
#include "base/stl_util.h" | ||
#include "chrome/browser/webdata/token_service_table.h" | ||
#include "components/webdata/common/web_database_service.h" | ||
|
||
using base::Bind; | ||
using base::Time; | ||
using content::BrowserThread; | ||
|
||
class TokenWebDataBackend | ||
: public base::RefCountedThreadSafe<TokenWebDataBackend, | ||
BrowserThread::DeleteOnDBThread> { | ||
|
||
public: | ||
TokenWebDataBackend() { | ||
} | ||
|
||
WebDatabase::State RemoveAllTokens(WebDatabase* db) { | ||
if (TokenServiceTable::FromWebDatabase(db)->RemoveAllTokens()) { | ||
return WebDatabase::COMMIT_NEEDED; | ||
} | ||
return WebDatabase::COMMIT_NOT_NEEDED; | ||
} | ||
|
||
WebDatabase::State SetTokenForService( | ||
const std::string& service, const std::string& token, WebDatabase* db) { | ||
if (TokenServiceTable::FromWebDatabase(db)->SetTokenForService(service, | ||
token)) { | ||
return WebDatabase::COMMIT_NEEDED; | ||
} | ||
return WebDatabase::COMMIT_NOT_NEEDED; | ||
} | ||
|
||
scoped_ptr<WDTypedResult> GetAllTokens(WebDatabase* db) { | ||
std::map<std::string, std::string> map; | ||
TokenServiceTable::FromWebDatabase(db)->GetAllTokens(&map); | ||
return scoped_ptr<WDTypedResult>( | ||
new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); | ||
} | ||
|
||
protected: | ||
virtual ~TokenWebDataBackend() { | ||
} | ||
|
||
private: | ||
friend struct BrowserThread::DeleteOnThread<BrowserThread::DB>; | ||
friend class base::DeleteHelper<TokenWebDataBackend>; | ||
// We have to friend RCTS<> so WIN shared-lib build is happy | ||
// (http://crbug/112250). | ||
friend class base::RefCountedThreadSafe<TokenWebDataBackend, | ||
BrowserThread::DeleteOnDBThread>; | ||
|
||
}; | ||
|
||
TokenWebData::TokenWebData(scoped_refptr<WebDatabaseService> wdbs, | ||
const ProfileErrorCallback& callback) | ||
: WebDataServiceBase(wdbs, callback), | ||
token_backend_(new TokenWebDataBackend()) { | ||
} | ||
|
||
void TokenWebData::SetTokenForService(const std::string& service, | ||
const std::string& token) { | ||
wdbs_->ScheduleDBTask(FROM_HERE, | ||
Bind(&TokenWebDataBackend::SetTokenForService, token_backend_, | ||
service, token)); | ||
} | ||
|
||
void TokenWebData::RemoveAllTokens() { | ||
wdbs_->ScheduleDBTask(FROM_HERE, | ||
Bind(&TokenWebDataBackend::RemoveAllTokens, token_backend_)); | ||
} | ||
|
||
// Null on failure. Success is WDResult<std::string> | ||
WebDataServiceBase::Handle TokenWebData::GetAllTokens( | ||
WebDataServiceConsumer* consumer) { | ||
return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | ||
Bind(&TokenWebDataBackend::GetAllTokens, token_backend_), consumer); | ||
} | ||
|
||
TokenWebData::TokenWebData() | ||
: WebDataServiceBase(NULL, ProfileErrorCallback()), | ||
token_backend_(new TokenWebDataBackend()) { | ||
} | ||
|
||
TokenWebData::~TokenWebData() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Chromium settings and storage represent user-selected preferences and | ||
// information and MUST not be extracted, overwritten or modified except | ||
// through Chromium defined APIs. | ||
|
||
#ifndef CHROME_BROWSER_WEBDATA_TOKEN_WEB_DATA_H__ | ||
#define CHROME_BROWSER_WEBDATA_TOKEN_WEB_DATA_H__ | ||
|
||
#include <map> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "base/callback_forward.h" | ||
#include "base/files/file_path.h" | ||
#include "base/location.h" | ||
#include "base/memory/ref_counted.h" | ||
#include "components/webdata/common/web_data_results.h" | ||
#include "components/webdata/common/web_data_service_base.h" | ||
#include "components/webdata/common/web_data_service_consumer.h" | ||
#include "components/webdata/common/web_database.h" | ||
|
||
class TokenWebDataBackend; | ||
class WebDatabaseService; | ||
class WebDataServiceConsumer; | ||
|
||
namespace content { | ||
class BrowserContext; | ||
} | ||
|
||
// TokenWebData is a data repository for storage of authentication tokens. | ||
|
||
class TokenWebData : public WebDataServiceBase { | ||
public: | ||
// Retrieve a WebDataService for the given context. | ||
static scoped_refptr<TokenWebData> FromBrowserContext( | ||
content::BrowserContext* context); | ||
|
||
TokenWebData(scoped_refptr<WebDatabaseService> wdbs, | ||
const ProfileErrorCallback& callback); | ||
|
||
// Set a token to use for a specified service. | ||
void SetTokenForService(const std::string& service, | ||
const std::string& token); | ||
|
||
// Remove all tokens stored in the web database. | ||
void RemoveAllTokens(); | ||
|
||
// Null on failure. Success is WDResult<std::vector<std::string> > | ||
virtual Handle GetAllTokens(WebDataServiceConsumer* consumer); | ||
|
||
protected: | ||
// For unit tests, passes a null callback. | ||
TokenWebData(); | ||
|
||
virtual ~TokenWebData(); | ||
|
||
private: | ||
scoped_refptr<TokenWebDataBackend> token_backend_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(TokenWebData); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_WEBDATA_TOKEN_WEB_DATA_H__ |
Oops, something went wrong.