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 "chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.
h" | 5 #include "chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.
h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "base/bind.h" |
9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/values.h" |
11 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chromeos/dbus/dbus_thread_manager.h" |
| 16 #include "chromeos/dbus/shill_profile_client.h" |
| 17 #include "chromeos/network/managed_network_configuration_handler.h" |
12 #include "chromeos/network/network_handler.h" | 18 #include "chromeos/network/network_handler.h" |
13 #include "chromeos/network/network_state.h" | |
14 #include "chromeos/network/network_state_handler.h" | 19 #include "chromeos/network/network_state_handler.h" |
| 20 #include "components/onc/onc_constants.h" |
15 #include "components/wifi_sync/network_state_helper_chromeos.h" | 21 #include "components/wifi_sync/network_state_helper_chromeos.h" |
16 #include "components/wifi_sync/wifi_security_class.h" | 22 #include "components/wifi_sync/wifi_config_delegate_factory_chromeos.h" |
| 23 |
| 24 using wifi_sync::WifiCredential; |
17 | 25 |
18 using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; | 26 using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; |
19 | 27 |
20 namespace wifi_credentials_helper { | 28 namespace wifi_credentials_helper { |
21 | 29 |
22 namespace { | 30 namespace { |
23 | 31 |
24 const char kProfilePrefix[] = "/profile/"; | 32 const char kProfilePrefix[] = "/profile/"; |
25 | 33 |
| 34 void DoNothingWithString(const std::string&) {} |
| 35 |
| 36 void LogCreateConfigurationFailure( |
| 37 const std::string& debug_hint, |
| 38 const std::string& /* network_config_error_message */, |
| 39 scoped_ptr<base::DictionaryValue> /* network_config_error_data */) { |
| 40 LOG(FATAL) << debug_hint; |
| 41 } |
| 42 |
26 std::string ChromeOsUserHashForBrowserContext( | 43 std::string ChromeOsUserHashForBrowserContext( |
27 const content::BrowserContext& context) { | 44 const content::BrowserContext& context) { |
28 return context.GetPath().BaseName().value(); | 45 return context.GetPath().BaseName().value(); |
29 } | 46 } |
30 | 47 |
31 std::string ShillProfilePathForBrowserContext( | 48 std::string ShillProfilePathForBrowserContext( |
32 const content::BrowserContext& context) { | 49 const content::BrowserContext& context) { |
33 return kProfilePrefix + ChromeOsUserHashForBrowserContext(context); | 50 return kProfilePrefix + ChromeOsUserHashForBrowserContext(context); |
34 } | 51 } |
35 | 52 |
| 53 chromeos::ShillProfileClient::TestInterface* |
| 54 GetShillProfileClientTestInterface() { |
| 55 DCHECK(chromeos::DBusThreadManager::Get()->GetShillProfileClient()); |
| 56 DCHECK(chromeos::DBusThreadManager::Get()->GetShillProfileClient() |
| 57 ->GetTestInterface()); |
| 58 return chromeos::DBusThreadManager::Get()->GetShillProfileClient() |
| 59 ->GetTestInterface(); |
| 60 } |
| 61 |
| 62 chromeos::ManagedNetworkConfigurationHandler* |
| 63 GetManagedNetworkConfigurationHandler() { |
| 64 DCHECK(chromeos::NetworkHandler::Get() |
| 65 ->managed_network_configuration_handler()); |
| 66 return chromeos::NetworkHandler::Get() |
| 67 ->managed_network_configuration_handler(); |
| 68 } |
| 69 |
36 chromeos::NetworkStateHandler* GetNetworkStateHandler() { | 70 chromeos::NetworkStateHandler* GetNetworkStateHandler() { |
37 DCHECK(chromeos::NetworkHandler::Get()->network_state_handler()); | 71 DCHECK(chromeos::NetworkHandler::Get()->network_state_handler()); |
38 return chromeos::NetworkHandler::Get()->network_state_handler(); | 72 return chromeos::NetworkHandler::Get()->network_state_handler(); |
39 } | 73 } |
40 | 74 |
41 } // namespace | 75 } // namespace |
42 | 76 |
| 77 void SetUpChromeOs() { |
| 78 wifi_sync::WifiConfigDelegateFactoryChromeOs::GetInstance() |
| 79 ->SetUseLoginState(false); |
| 80 } |
| 81 |
| 82 bool SetupClientForProfileChromeOs(const Profile* profile) { |
| 83 DCHECK(profile); |
| 84 GetShillProfileClientTestInterface() |
| 85 ->AddProfile(ShillProfilePathForBrowserContext(*profile), |
| 86 ChromeOsUserHashForBrowserContext(*profile)); |
| 87 |
| 88 const base::ListValue policy_network_configs; |
| 89 const base::DictionaryValue policy_global_config; |
| 90 GetManagedNetworkConfigurationHandler() |
| 91 ->SetPolicy(onc::ONC_SOURCE_UNKNOWN, |
| 92 ChromeOsUserHashForBrowserContext(*profile), |
| 93 policy_network_configs, |
| 94 policy_global_config); |
| 95 |
| 96 return true; |
| 97 } |
| 98 |
| 99 void AddWifiCredentialToProfileChromeOs( |
| 100 Profile* profile, const WifiCredential& credential) { |
| 101 DCHECK(profile); |
| 102 wifi_sync::CreateWifiNetworkInShillUserProfile( |
| 103 GetManagedNetworkConfigurationHandler(), |
| 104 ChromeOsUserHashForBrowserContext(*profile), |
| 105 credential, |
| 106 base::Bind(DoNothingWithString), // success_callback |
| 107 base::Bind(LogCreateConfigurationFailure, |
| 108 base::StringPrintf("Failed to add credential %s", |
| 109 credential.ToString().c_str()))); |
| 110 } |
| 111 |
43 WifiCredentialSet GetWifiCredentialsForProfileChromeOs(const Profile* profile) { | 112 WifiCredentialSet GetWifiCredentialsForProfileChromeOs(const Profile* profile) { |
44 DCHECK(profile); | 113 DCHECK(profile); |
45 return wifi_sync::GetWifiCredentialsForShillProfile( | 114 return wifi_sync::GetWifiCredentialsForShillProfile( |
46 GetNetworkStateHandler(), ShillProfilePathForBrowserContext(*profile)); | 115 GetNetworkStateHandler(), ShillProfilePathForBrowserContext(*profile)); |
47 } | 116 } |
48 | 117 |
49 } // namespace wifi_credentials_helper | 118 } // namespace wifi_credentials_helper |
OLD | NEW |