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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cbefb2b849561d2e6f9ded0fa26b7c5b57fdf796 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/settings/device_oauth2_token_service_factory.cc |
| @@ -0,0 +1,61 @@ |
| +// Copyright (c) 2012 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/chromeos/settings/device_oauth2_token_service_factory.h" |
| + |
| +#include "base/lazy_instance.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace chromeos { |
| + |
| +static base::LazyInstance<DeviceOAuth2TokenServiceFactory> |
| + g_device_oauth2_token_service_factory_ = LAZY_INSTANCE_INITIALIZER; |
| + |
| +DeviceOAuth2TokenServiceFactory::DeviceOAuth2TokenServiceFactory() { |
| +} |
| + |
| +DeviceOAuth2TokenServiceFactory::~DeviceOAuth2TokenServiceFactory() { |
| +} |
| + |
| +// static |
| +DeviceOAuth2TokenService* DeviceOAuth2TokenServiceFactory::Get() { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + DeviceOAuth2TokenServiceFactory factory = |
| + g_device_oauth2_token_service_factory_.Get(); |
| + |
| + return factory.GetImpl(); |
|
Mattias Nissler (ping if slow)
2013/04/03 11:33:16
It seems like a simpler implementation could be to
David Roche
2013/04/03 16:34:09
Done.
|
| +} |
| + |
| +DeviceOAuth2TokenService* DeviceOAuth2TokenServiceFactory::GetImpl() { |
| + return device_oauth2_token_service_.get(); |
| +} |
| + |
| +// static |
| +void DeviceOAuth2TokenServiceFactory::Initialize() { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + g_device_oauth2_token_service_factory_.Get().InitializeImpl(); |
| +} |
| + |
| +void DeviceOAuth2TokenServiceFactory::InitializeImpl() { |
| + DCHECK(!device_oauth2_token_service_); |
| + device_oauth2_token_service_.reset( |
| + new DeviceOAuth2TokenService( |
| + g_browser_process->system_request_context(), |
| + g_browser_process->local_state())); |
| +} |
| + |
| +// static |
| +void DeviceOAuth2TokenServiceFactory::Shutdown() { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + g_device_oauth2_token_service_factory_.Get().ShutdownImpl(); |
| +} |
| + |
| +void DeviceOAuth2TokenServiceFactory::ShutdownImpl() { |
| + if (device_oauth2_token_service_.get()) { |
|
Mattias Nissler (ping if slow)
2013/04/03 11:33:16
nit: no need for curlies here.
David Roche
2013/04/03 16:34:09
Done.
|
| + device_oauth2_token_service_->Shutdown(); |
|
Mattias Nissler (ping if slow)
2013/04/03 11:33:16
Shouldn't we just destroy the object here?
David Roche
2013/04/03 16:34:09
Done.
|
| + } |
| +} |
| + |
| +} // namespace chromeos |