Chromium Code Reviews| 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..26a4542926b7a64b5f4fc6f9f172354b1dad9cc2 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,75 @@ |
| #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 |
|
pastarmovj
2013/10/23 08:02:17
I think it makes sense to have a bug number refere
satorux1
2013/10/24 01:49:26
good idea. done.
|
| + // DeviceOAuth2TokenService. 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; |
| } |
| } |