Chromium Code Reviews| 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 <string> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 9 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 11 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 12 #include "components/wifi_sync/wifi_config_delegate.h" | |
| 10 #include "components/wifi_sync/wifi_credential_syncable_service.h" | 13 #include "components/wifi_sync/wifi_credential_syncable_service.h" |
| 14 #include "content/public/browser/browser_context.h" | |
| 11 | 15 |
| 12 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
| 17 #include "base/files/file_path.h" | |
| 13 #include "chromeos/login/login_state.h" | 18 #include "chromeos/login/login_state.h" |
| 14 #include "chromeos/network/network_handler.h" | 19 #include "chromeos/network/network_handler.h" |
| 15 #include "components/wifi_sync/wifi_config_delegate_chromeos.h" | 20 #include "components/wifi_sync/wifi_config_delegate_chromeos.h" |
| 16 #endif | 21 #endif |
| 17 | 22 |
| 18 namespace wifi_sync { | 23 namespace wifi_sync { |
| 19 | 24 |
| 20 namespace { | 25 namespace { |
| 21 | 26 |
| 22 scoped_ptr<WifiConfigDelegate> BuildConfigDelegate( | |
| 23 content::BrowserContext* context) { | |
| 24 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
| 25 const chromeos::LoginState* login_state = chromeos::LoginState::Get(); | 28 // Returns a string identifying a ChromeOS network settings profile, |
| 26 DCHECK(login_state->IsUserLoggedIn()); | 29 // by that profile's UserHash property. This value may be communicated |
| 27 DCHECK(!login_state->primary_user_hash().empty()); | 30 // to the ChromeOS connection manager ("Shill"), but must not be |
| 28 // TODO(quiche): Verify that |context| is the primary user's context. | 31 // exposed to any untrusted code (e.g., via web APIs). |
|
mukesh agrawal
2015/02/06 02:40:55
I believe this (newly added) comment captures how
| |
| 29 | 32 std::string GetUserHash(content::BrowserContext* context, |
| 30 // Note: NetworkHandler is a singleton that is managed by | 33 bool use_login_state) { |
| 31 // ChromeBrowserMainPartsChromeos, and destroyed after all | 34 if (use_login_state) { |
| 32 // KeyedService instances are destroyed. | 35 const chromeos::LoginState* login_state = chromeos::LoginState::Get(); |
| 33 chromeos::NetworkHandler* network_handler = chromeos::NetworkHandler::Get(); | 36 DCHECK(login_state->IsUserLoggedIn()); |
| 34 return make_scoped_ptr(new WifiConfigDelegateChromeOs( | 37 DCHECK(!login_state->primary_user_hash().empty()); |
| 35 login_state->primary_user_hash(), | 38 // TODO(quiche): Verify that |context| is the primary user's context. |
| 36 network_handler->managed_network_configuration_handler())); | 39 return login_state->primary_user_hash(); |
| 37 #else | 40 } else { |
| 38 NOTREACHED(); | 41 // In WiFi credential sync tests, LoginState is not |
| 39 return nullptr; | 42 // available. Instead, those tests set their Shill profiles' |
| 43 // UserHashes based on the corresponding BrowserContexts' storage | |
| 44 // paths. | |
|
mukesh agrawal
2015/02/06 02:40:55
This (newly added) comment should explain why this
| |
| 45 return context->GetPath().BaseName().value(); | |
| 46 } | |
| 47 } | |
| 40 #endif | 48 #endif |
| 41 } | |
| 42 | 49 |
| 43 } // namespace | 50 } // namespace |
| 44 | 51 |
| 45 // static | 52 // static |
| 46 WifiCredentialSyncableService* | 53 WifiCredentialSyncableService* |
| 47 WifiCredentialSyncableServiceFactory::GetForBrowserContext( | 54 WifiCredentialSyncableServiceFactory::GetForBrowserContext( |
| 48 content::BrowserContext* browser_context) { | 55 content::BrowserContext* browser_context) { |
| 49 return static_cast<WifiCredentialSyncableService*>( | 56 return static_cast<WifiCredentialSyncableService*>( |
| 50 GetInstance()->GetServiceForBrowserContext(browser_context, true)); | 57 GetInstance()->GetServiceForBrowserContext(browser_context, true)); |
| 51 } | 58 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 64 BrowserContextDependencyManager::GetInstance()) { | 71 BrowserContextDependencyManager::GetInstance()) { |
| 65 } | 72 } |
| 66 | 73 |
| 67 WifiCredentialSyncableServiceFactory::~WifiCredentialSyncableServiceFactory() { | 74 WifiCredentialSyncableServiceFactory::~WifiCredentialSyncableServiceFactory() { |
| 68 } | 75 } |
| 69 | 76 |
| 70 KeyedService* WifiCredentialSyncableServiceFactory::BuildServiceInstanceFor( | 77 KeyedService* WifiCredentialSyncableServiceFactory::BuildServiceInstanceFor( |
| 71 content::BrowserContext* context) const { | 78 content::BrowserContext* context) const { |
| 72 // TODO(quiche): Figure out if this behaves properly for multi-profile. | 79 // TODO(quiche): Figure out if this behaves properly for multi-profile. |
| 73 // crbug.com/430681. | 80 // crbug.com/430681. |
| 74 return new WifiCredentialSyncableService(BuildConfigDelegate(context)); | 81 #if defined(OS_CHROMEOS) |
| 82 return new WifiCredentialSyncableService( | |
| 83 BuildWifiConfigDelegateChromeOs(context)); | |
| 84 #else | |
| 85 NOTREACHED(); | |
| 86 return nullptr; | |
| 87 #endif | |
| 75 } | 88 } |
| 76 | 89 |
| 90 #if defined(OS_CHROMEOS) | |
| 91 scoped_ptr<WifiConfigDelegate> | |
| 92 WifiCredentialSyncableServiceFactory::BuildWifiConfigDelegateChromeOs( | |
| 93 content::BrowserContext* context) const { | |
| 94 // Note: NetworkHandler is a singleton that is managed by | |
| 95 // ChromeBrowserMainPartsChromeos, and destroyed after all | |
| 96 // KeyedService instances are destroyed. | |
| 97 chromeos::NetworkHandler* network_handler = chromeos::NetworkHandler::Get(); | |
| 98 return make_scoped_ptr(new WifiConfigDelegateChromeOs( | |
| 99 GetUserHash(context, !ignore_login_state_for_test_), | |
| 100 network_handler->managed_network_configuration_handler())); | |
| 101 } | |
| 102 #endif | |
| 103 | |
| 77 } // namespace wifi_sync | 104 } // namespace wifi_sync |
| OLD | NEW |