Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: chrome/browser/chromeos/settings/device_oauth2_token_service_factory.cc

Issue 34523003: settings: Make DeviceOAuth2TokenServiceFactory::Get() async (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 5 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
6 6
7 #include "base/message_loop/message_loop.h"
8 #include "base/tracked_objects.h"
7 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 10 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
9 #include "chrome/browser/chromeos/settings/token_encryptor.h" 11 #include "chrome/browser/chromeos/settings/token_encryptor.h"
10 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
11 13
12 namespace chromeos { 14 namespace chromeos {
15 namespace {
13 16
14 static DeviceOAuth2TokenService* g_device_oauth2_token_service_ = NULL; 17 DeviceOAuth2TokenServiceFactory* g_factory = NULL;
15 18
16 DeviceOAuth2TokenServiceFactory::DeviceOAuth2TokenServiceFactory() { 19 } // namespace
20
21 DeviceOAuth2TokenServiceFactory::DeviceOAuth2TokenServiceFactory()
22 : token_service_(new DeviceOAuth2TokenService(
23 g_browser_process->system_request_context(),
24 g_browser_process->local_state(),
25 new CryptohomeTokenEncryptor)) {
26 }
27
28 DeviceOAuth2TokenServiceFactory::~DeviceOAuth2TokenServiceFactory() {
29 delete token_service_;
17 } 30 }
18 31
19 // static 32 // static
20 DeviceOAuth2TokenService* DeviceOAuth2TokenServiceFactory::Get() { 33 void DeviceOAuth2TokenServiceFactory::Get(const GetCallback& callback) {
21 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
22 return g_device_oauth2_token_service_; 35
36 DeviceOAuth2TokenService* token_service = NULL;
37 if (g_factory)
38 token_service = g_factory->token_service_;
39
40 // TODO(satorux): Implement async initialization logic for
41 // DeviceOAuth2TokenService. Here's how that should work:
42 //
43 // if token_service is ready:
44 // run callback asynchronously
pneubeck (no reviews) 2013/10/22 09:05:03 do you mean "immediately" or "synchronously" inste
satorux1 2013/10/22 09:56:43 I meant asynchronously. we could run callback.Run(
45 // return
46 //
47 // if there is no pending callback:
satorux1 2013/10/22 09:56:43 FWIW, I meant "if there is any pending callback"
48 // add callback to the pending callback list
49 // return
50 //
51 // add callback to the pending callback list
52 // start getting the system salt asynchronously...
pneubeck (no reviews) 2013/10/22 09:05:03 Why should we do this lazily triggered by the Get(
satorux1 2013/10/22 09:56:43 Thanks. Will explore the idea, when I implement th
53 //
54 // upon receiving the system salt:
55 // create CryptohomeTokenEncryptor with that key
56 // create DeviceOAuth2TokenService
57 // run all the pending callbacks
58 base::MessageLoop::current()->PostTask(
59 FROM_HERE,
60 base::Bind(callback, token_service));
23 } 61 }
24 62
25 // static 63 // static
26 void DeviceOAuth2TokenServiceFactory::Initialize() { 64 void DeviceOAuth2TokenServiceFactory::Initialize() {
27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 65 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
28 DCHECK(!g_device_oauth2_token_service_); 66
29 g_device_oauth2_token_service_ = new DeviceOAuth2TokenService( 67 DCHECK(!g_factory);
30 g_browser_process->system_request_context(), 68 g_factory = new DeviceOAuth2TokenServiceFactory;
31 g_browser_process->local_state(),
32 new CryptohomeTokenEncryptor);
33 } 69 }
34 70
35 // static 71 // static
36 void DeviceOAuth2TokenServiceFactory::Shutdown() { 72 void DeviceOAuth2TokenServiceFactory::Shutdown() {
37 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 73 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
38 if (g_device_oauth2_token_service_) { 74
39 delete g_device_oauth2_token_service_; 75 if (g_factory) {
40 g_device_oauth2_token_service_ = NULL; 76 delete g_factory;
77 g_factory = NULL;
41 } 78 }
42 } 79 }
43 80
44 } // namespace chromeos 81 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698