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

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: address comments Created 7 years, 1 month 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
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.
41 // DeviceOAuth2TokenService. Here's how that should work:
42 //
43 // if token_service is ready:
44 // run callback asynchronously via MessageLoop
45 // return
46 //
47 // add callback to the pending callback list
48 //
49 // if there is only one pending callback:
50 // start getting the system salt asynchronously...
51 //
52 // upon receiving the system salt:
53 // create CryptohomeTokenEncryptor with that key
54 // create DeviceOAuth2TokenService
55 // run all the pending callbacks
56 base::MessageLoop::current()->PostTask(
57 FROM_HERE,
58 base::Bind(callback, token_service));
23 } 59 }
24 60
25 // static 61 // static
26 void DeviceOAuth2TokenServiceFactory::Initialize() { 62 void DeviceOAuth2TokenServiceFactory::Initialize() {
27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 63 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
28 DCHECK(!g_device_oauth2_token_service_); 64
29 g_device_oauth2_token_service_ = new DeviceOAuth2TokenService( 65 DCHECK(!g_factory);
30 g_browser_process->system_request_context(), 66 g_factory = new DeviceOAuth2TokenServiceFactory;
31 g_browser_process->local_state(),
32 new CryptohomeTokenEncryptor);
33 } 67 }
34 68
35 // static 69 // static
36 void DeviceOAuth2TokenServiceFactory::Shutdown() { 70 void DeviceOAuth2TokenServiceFactory::Shutdown() {
37 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 71 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
38 if (g_device_oauth2_token_service_) { 72
39 delete g_device_oauth2_token_service_; 73 if (g_factory) {
40 g_device_oauth2_token_service_ = NULL; 74 delete g_factory;
75 g_factory = NULL;
41 } 76 }
42 } 77 }
43 78
44 } // namespace chromeos 79 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698