OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/wifi_sync/wifi_credential_syncable_service_factory.h" | 5 #include "components/wifi_sync/wifi_credential_syncable_service_factory.h" |
6 | 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" |
7 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 9 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
8 #include "components/wifi_sync/wifi_credential_syncable_service.h" | 10 #include "components/wifi_sync/wifi_credential_syncable_service.h" |
9 | 11 |
| 12 #if defined(OS_CHROMEOS) |
| 13 #include "chromeos/login/login_state.h" |
| 14 #include "chromeos/network/network_handler.h" |
| 15 #include "components/wifi_sync/wifi_config_delegate_chromeos.h" |
| 16 #endif |
| 17 |
10 namespace wifi_sync { | 18 namespace wifi_sync { |
11 | 19 |
| 20 namespace { |
| 21 |
| 22 scoped_ptr<WifiConfigDelegate> BuildConfigDelegate( |
| 23 content::BrowserContext* context) { |
| 24 #if defined(OS_CHROMEOS) |
| 25 const chromeos::LoginState* login_state = chromeos::LoginState::Get(); |
| 26 DCHECK(login_state->IsUserLoggedIn()); |
| 27 DCHECK(!login_state->primary_user_hash().empty()); |
| 28 // TODO(quiche): Verify that |context| is the primary user's context. |
| 29 |
| 30 // Note: NetworkHandler is a singleton that is managed by |
| 31 // ChromeBrowserMainPartsChromeos, and destroyed after all |
| 32 // KeyedService instances are destroyed. |
| 33 chromeos::NetworkHandler* network_handler = chromeos::NetworkHandler::Get(); |
| 34 return make_scoped_ptr(new WifiConfigDelegateChromeOs( |
| 35 login_state->primary_user_hash(), |
| 36 network_handler->managed_network_configuration_handler())); |
| 37 #else |
| 38 NOTREACHED(); |
| 39 return nullptr; |
| 40 #endif |
| 41 } |
| 42 |
| 43 } // namespace |
| 44 |
12 // static | 45 // static |
13 WifiCredentialSyncableService* | 46 WifiCredentialSyncableService* |
14 WifiCredentialSyncableServiceFactory::GetForBrowserContext( | 47 WifiCredentialSyncableServiceFactory::GetForBrowserContext( |
15 content::BrowserContext* browser_context) { | 48 content::BrowserContext* browser_context) { |
16 return static_cast<WifiCredentialSyncableService*>( | 49 return static_cast<WifiCredentialSyncableService*>( |
17 GetInstance()->GetServiceForBrowserContext(browser_context, true)); | 50 GetInstance()->GetServiceForBrowserContext(browser_context, true)); |
18 } | 51 } |
19 | 52 |
20 // static | 53 // static |
21 WifiCredentialSyncableServiceFactory* | 54 WifiCredentialSyncableServiceFactory* |
22 WifiCredentialSyncableServiceFactory::GetInstance() { | 55 WifiCredentialSyncableServiceFactory::GetInstance() { |
23 return Singleton<WifiCredentialSyncableServiceFactory>::get(); | 56 return Singleton<WifiCredentialSyncableServiceFactory>::get(); |
24 } | 57 } |
25 | 58 |
26 // Private methods. | 59 // Private methods. |
27 | 60 |
28 WifiCredentialSyncableServiceFactory::WifiCredentialSyncableServiceFactory() | 61 WifiCredentialSyncableServiceFactory::WifiCredentialSyncableServiceFactory() |
29 : BrowserContextKeyedServiceFactory( | 62 : BrowserContextKeyedServiceFactory( |
30 "WifiCredentialSyncableService", | 63 "WifiCredentialSyncableService", |
31 BrowserContextDependencyManager::GetInstance()) { | 64 BrowserContextDependencyManager::GetInstance()) { |
32 } | 65 } |
33 | 66 |
34 WifiCredentialSyncableServiceFactory::~WifiCredentialSyncableServiceFactory() { | 67 WifiCredentialSyncableServiceFactory::~WifiCredentialSyncableServiceFactory() { |
35 } | 68 } |
36 | 69 |
37 KeyedService* WifiCredentialSyncableServiceFactory::BuildServiceInstanceFor( | 70 KeyedService* WifiCredentialSyncableServiceFactory::BuildServiceInstanceFor( |
38 content::BrowserContext* context) const { | 71 content::BrowserContext* context) const { |
39 // TODO(quiche): Figure out if this behaves properly for multi-profile. | 72 // TODO(quiche): Figure out if this behaves properly for multi-profile. |
40 // crbug.com/430681. | 73 // crbug.com/430681. |
41 return new WifiCredentialSyncableService(); | 74 return new WifiCredentialSyncableService(BuildConfigDelegate(context)); |
42 } | 75 } |
43 | 76 |
44 } // namespace wifi_sync | 77 } // namespace wifi_sync |
OLD | NEW |