| Index: chrome/browser/chromeos/settings/device_oauth2_token_service_factory.cc
|
| diff --git a/chrome/browser/chromeos/settings/device_oauth2_token_service_factory.cc b/chrome/browser/chromeos/settings/device_oauth2_token_service_factory.cc
|
| index 57b6efb1dae9df33137b45a784612bd260fd7b5c..5f7fb306267a4372e837ea45a33e6e37620349e6 100644
|
| --- a/chrome/browser/chromeos/settings/device_oauth2_token_service_factory.cc
|
| +++ b/chrome/browser/chromeos/settings/device_oauth2_token_service_factory.cc
|
| @@ -4,40 +4,76 @@
|
|
|
| #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h"
|
|
|
| +#include "base/message_loop/message_loop.h"
|
| +#include "base/tracked_objects.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
|
| #include "chrome/browser/chromeos/settings/token_encryptor.h"
|
| #include "content/public/browser/browser_thread.h"
|
|
|
| namespace chromeos {
|
| +namespace {
|
|
|
| -static DeviceOAuth2TokenService* g_device_oauth2_token_service_ = NULL;
|
| +DeviceOAuth2TokenServiceFactory* g_factory = NULL;
|
|
|
| -DeviceOAuth2TokenServiceFactory::DeviceOAuth2TokenServiceFactory() {
|
| +} // namespace
|
| +
|
| +DeviceOAuth2TokenServiceFactory::DeviceOAuth2TokenServiceFactory()
|
| + : token_service_(new DeviceOAuth2TokenService(
|
| + g_browser_process->system_request_context(),
|
| + g_browser_process->local_state(),
|
| + new CryptohomeTokenEncryptor)) {
|
| +}
|
| +
|
| +DeviceOAuth2TokenServiceFactory::~DeviceOAuth2TokenServiceFactory() {
|
| + delete token_service_;
|
| }
|
|
|
| // static
|
| -DeviceOAuth2TokenService* DeviceOAuth2TokenServiceFactory::Get() {
|
| +void DeviceOAuth2TokenServiceFactory::Get(const GetCallback& callback) {
|
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| - return g_device_oauth2_token_service_;
|
| +
|
| + DeviceOAuth2TokenService* token_service = NULL;
|
| + if (g_factory)
|
| + token_service = g_factory->token_service_;
|
| +
|
| + // TODO(satorux): Implement async initialization logic for
|
| + // DeviceOAuth2TokenService. crbug.com/309959.
|
| + // Here's how that should work:
|
| + //
|
| + // if token_service is ready:
|
| + // run callback asynchronously via MessageLoop
|
| + // return
|
| + //
|
| + // add callback to the pending callback list
|
| + //
|
| + // if there is only one pending callback:
|
| + // start getting the system salt asynchronously...
|
| + //
|
| + // upon receiving the system salt:
|
| + // create CryptohomeTokenEncryptor with that key
|
| + // create DeviceOAuth2TokenService
|
| + // run all the pending callbacks
|
| + base::MessageLoop::current()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(callback, token_service));
|
| }
|
|
|
| // static
|
| void DeviceOAuth2TokenServiceFactory::Initialize() {
|
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| - DCHECK(!g_device_oauth2_token_service_);
|
| - g_device_oauth2_token_service_ = new DeviceOAuth2TokenService(
|
| - g_browser_process->system_request_context(),
|
| - g_browser_process->local_state(),
|
| - new CryptohomeTokenEncryptor);
|
| +
|
| + DCHECK(!g_factory);
|
| + g_factory = new DeviceOAuth2TokenServiceFactory;
|
| }
|
|
|
| // static
|
| void DeviceOAuth2TokenServiceFactory::Shutdown() {
|
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| - if (g_device_oauth2_token_service_) {
|
| - delete g_device_oauth2_token_service_;
|
| - g_device_oauth2_token_service_ = NULL;
|
| +
|
| + if (g_factory) {
|
| + delete g_factory;
|
| + g_factory = NULL;
|
| }
|
| }
|
|
|
|
|