| 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" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 9 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 10 #include "components/wifi_sync/wifi_config_delegate.h" |
| 10 #include "components/wifi_sync/wifi_credential_syncable_service.h" | 11 #include "components/wifi_sync/wifi_credential_syncable_service.h" |
| 12 #include "content/public/browser/browser_context.h" |
| 11 | 13 |
| 12 #if defined(OS_CHROMEOS) | 14 #if defined(OS_CHROMEOS) |
| 15 #include "base/files/file_path.h" |
| 13 #include "chromeos/login/login_state.h" | 16 #include "chromeos/login/login_state.h" |
| 14 #include "chromeos/network/network_handler.h" | 17 #include "chromeos/network/network_handler.h" |
| 15 #include "components/wifi_sync/wifi_config_delegate_chromeos.h" | 18 #include "components/wifi_sync/wifi_config_delegate_chromeos.h" |
| 16 #endif | 19 #endif |
| 17 | 20 |
| 18 namespace wifi_sync { | 21 namespace wifi_sync { |
| 19 | 22 |
| 20 namespace { | 23 namespace { |
| 21 | 24 |
| 22 scoped_ptr<WifiConfigDelegate> BuildConfigDelegate( | |
| 23 content::BrowserContext* context) { | |
| 24 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
| 25 const chromeos::LoginState* login_state = chromeos::LoginState::Get(); | 26 std::string GetUserHash(content::BrowserContext* context, |
| 26 DCHECK(login_state->IsUserLoggedIn()); | 27 bool use_login_state) { |
| 27 DCHECK(!login_state->primary_user_hash().empty()); | 28 if (use_login_state) { |
| 28 // TODO(quiche): Verify that |context| is the primary user's context. | 29 const chromeos::LoginState* login_state = chromeos::LoginState::Get(); |
| 29 | 30 DCHECK(login_state->IsUserLoggedIn()); |
| 30 // Note: NetworkHandler is a singleton that is managed by | 31 DCHECK(!login_state->primary_user_hash().empty()); |
| 31 // ChromeBrowserMainPartsChromeos, and destroyed after all | 32 // TODO(quiche): Verify that |context| is the primary user's context. |
| 32 // KeyedService instances are destroyed. | 33 return login_state->primary_user_hash(); |
| 33 chromeos::NetworkHandler* network_handler = chromeos::NetworkHandler::Get(); | 34 } else { |
| 34 return make_scoped_ptr(new WifiConfigDelegateChromeOs( | 35 return context->GetPath().BaseName().value(); |
| 35 login_state->primary_user_hash(), | 36 } |
| 36 network_handler->managed_network_configuration_handler())); | 37 } |
| 37 #else | |
| 38 NOTREACHED(); | |
| 39 return nullptr; | |
| 40 #endif | 38 #endif |
| 41 } | |
| 42 | 39 |
| 43 } // namespace | 40 } // namespace |
| 44 | 41 |
| 45 // static | 42 // static |
| 46 WifiCredentialSyncableService* | 43 WifiCredentialSyncableService* |
| 47 WifiCredentialSyncableServiceFactory::GetForBrowserContext( | 44 WifiCredentialSyncableServiceFactory::GetForBrowserContext( |
| 48 content::BrowserContext* browser_context) { | 45 content::BrowserContext* browser_context) { |
| 49 return static_cast<WifiCredentialSyncableService*>( | 46 return static_cast<WifiCredentialSyncableService*>( |
| 50 GetInstance()->GetServiceForBrowserContext(browser_context, true)); | 47 GetInstance()->GetServiceForBrowserContext(browser_context, true)); |
| 51 } | 48 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 64 BrowserContextDependencyManager::GetInstance()) { | 61 BrowserContextDependencyManager::GetInstance()) { |
| 65 } | 62 } |
| 66 | 63 |
| 67 WifiCredentialSyncableServiceFactory::~WifiCredentialSyncableServiceFactory() { | 64 WifiCredentialSyncableServiceFactory::~WifiCredentialSyncableServiceFactory() { |
| 68 } | 65 } |
| 69 | 66 |
| 70 KeyedService* WifiCredentialSyncableServiceFactory::BuildServiceInstanceFor( | 67 KeyedService* WifiCredentialSyncableServiceFactory::BuildServiceInstanceFor( |
| 71 content::BrowserContext* context) const { | 68 content::BrowserContext* context) const { |
| 72 // TODO(quiche): Figure out if this behaves properly for multi-profile. | 69 // TODO(quiche): Figure out if this behaves properly for multi-profile. |
| 73 // crbug.com/430681. | 70 // crbug.com/430681. |
| 74 return new WifiCredentialSyncableService(BuildConfigDelegate(context)); | 71 #if defined(OS_CHROMEOS) |
| 72 return new WifiCredentialSyncableService( |
| 73 BuildWifiConfigDelegateChromeOs(context)); |
| 74 #else |
| 75 NOTREACHED(); |
| 76 return nullptr; |
| 77 #endif |
| 75 } | 78 } |
| 76 | 79 |
| 80 #if defined(OS_CHROMEOS) |
| 81 scoped_ptr<WifiConfigDelegate> |
| 82 WifiCredentialSyncableServiceFactory::BuildWifiConfigDelegateChromeOs( |
| 83 content::BrowserContext* context) const { |
| 84 // Note: NetworkHandler is a singleton that is managed by |
| 85 // ChromeBrowserMainPartsChromeos, and destroyed after all |
| 86 // KeyedService instances are destroyed. |
| 87 chromeos::NetworkHandler* network_handler = chromeos::NetworkHandler::Get(); |
| 88 return make_scoped_ptr(new WifiConfigDelegateChromeOs( |
| 89 GetUserHash(context, !ignore_login_state_for_test_), |
| 90 network_handler->managed_network_configuration_handler())); |
| 91 } |
| 92 #endif |
| 93 |
| 77 } // namespace wifi_sync | 94 } // namespace wifi_sync |
| OLD | NEW |