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/memory/scoped_ptr.h" | |
13 #include "base/strings/stringprintf.h" | |
14 #include "base/values.h" | |
11 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chromeos/dbus/dbus_thread_manager.h" | |
17 #include "chromeos/dbus/shill_profile_client.h" | |
18 #include "chromeos/network/managed_network_configuration_handler.h" | |
12 #include "chromeos/network/network_handler.h" | 19 #include "chromeos/network/network_handler.h" |
13 #include "chromeos/network/network_state.h" | |
14 #include "chromeos/network/network_state_handler.h" | 20 #include "chromeos/network/network_state_handler.h" |
21 #include "components/onc/onc_constants.h" | |
15 #include "components/wifi_sync/network_state_helper_chromeos.h" | 22 #include "components/wifi_sync/network_state_helper_chromeos.h" |
16 #include "components/wifi_sync/wifi_security_class.h" | 23 #include "components/wifi_sync/wifi_credential_syncable_service_factory.h" |
24 | |
25 using wifi_sync::WifiCredential; | |
17 | 26 |
18 using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; | 27 using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; |
19 | 28 |
20 namespace wifi_credentials_helper { | 29 namespace wifi_credentials_helper { |
21 | 30 |
22 namespace { | 31 namespace { |
23 | 32 |
24 const char kProfilePrefix[] = "/profile/"; | 33 const char kProfilePrefix[] = "/profile/"; |
25 | 34 |
35 void LogCreateConfigurationFailure( | |
36 const std::string& debug_hint, | |
37 const std::string& /* network_config_error_message */, | |
38 scoped_ptr<base::DictionaryValue> /* network_config_error_data */) { | |
39 LOG(FATAL) << debug_hint; | |
40 } | |
41 | |
26 std::string ChromeOsUserHashForBrowserContext( | 42 std::string ChromeOsUserHashForBrowserContext( |
27 const content::BrowserContext& context) { | 43 const content::BrowserContext& context) { |
28 return context.GetPath().BaseName().value(); | 44 return context.GetPath().BaseName().value(); |
29 } | 45 } |
30 | 46 |
31 std::string ShillProfilePathForBrowserContext( | 47 std::string ShillProfilePathForBrowserContext( |
32 const content::BrowserContext& context) { | 48 const content::BrowserContext& context) { |
33 return kProfilePrefix + ChromeOsUserHashForBrowserContext(context); | 49 return kProfilePrefix + ChromeOsUserHashForBrowserContext(context); |
pneubeck (no reviews)
2015/01/30 14:38:45
if this is for testing only, it should be irreleva
mukesh agrawal
2015/01/30 22:28:14
Are you referring to the use of kProfilePrefix (wh
pneubeck (no reviews)
2015/01/31 10:26:40
makes sense.
I'd just add a short comment in front
mukesh agrawal
2015/02/02 20:36:40
Done.
| |
34 } | 50 } |
35 | 51 |
36 chromeos::NetworkStateHandler* GetNetworkStateHandler() { | 52 ::chromeos::ShillProfileClient::TestInterface* |
37 DCHECK(chromeos::NetworkHandler::Get()->network_state_handler()); | 53 GetShillProfileClientTestInterface() { |
38 return chromeos::NetworkHandler::Get()->network_state_handler(); | 54 DCHECK(::chromeos::DBusThreadManager::Get()->GetShillProfileClient()); |
pneubeck (no reviews)
2015/01/30 14:38:45
the DCHECKs (here and in the other Get*()) are not
mukesh agrawal
2015/01/30 22:28:14
Agreed that a nullptr would cause a crash.
The re
pneubeck (no reviews)
2015/01/31 10:26:40
no, keep them if you find them helpful.
just keep
mukesh agrawal
2015/02/02 20:36:40
Acknowledged.
| |
55 DCHECK(::chromeos::DBusThreadManager::Get()->GetShillProfileClient() | |
56 ->GetTestInterface()); | |
57 return ::chromeos::DBusThreadManager::Get()->GetShillProfileClient() | |
58 ->GetTestInterface(); | |
59 } | |
60 | |
61 ::chromeos::ManagedNetworkConfigurationHandler* | |
62 GetManagedNetworkConfigurationHandler() { | |
63 DCHECK(::chromeos::NetworkHandler::Get() | |
64 ->managed_network_configuration_handler()); | |
65 return ::chromeos::NetworkHandler::Get() | |
66 ->managed_network_configuration_handler(); | |
67 } | |
68 | |
69 ::chromeos::NetworkStateHandler* GetNetworkStateHandler() { | |
70 DCHECK(::chromeos::NetworkHandler::Get()->network_state_handler()); | |
71 return ::chromeos::NetworkHandler::Get()->network_state_handler(); | |
39 } | 72 } |
40 | 73 |
41 } // namespace | 74 } // namespace |
42 | 75 |
76 namespace chromeos { | |
77 | |
78 void SetUpChromeOs() { | |
79 wifi_sync::WifiCredentialSyncableServiceFactory::GetInstance() | |
80 ->IgnoreLoginStateForTest(); | |
81 } | |
82 | |
83 bool SetupClientForProfileChromeOs(const Profile* profile) { | |
84 DCHECK(profile); | |
85 GetShillProfileClientTestInterface() | |
86 ->AddProfile(ShillProfilePathForBrowserContext(*profile), | |
87 ChromeOsUserHashForBrowserContext(*profile)); | |
88 | |
89 const base::ListValue policy_network_configs; | |
90 const base::DictionaryValue policy_global_config; | |
91 GetManagedNetworkConfigurationHandler() | |
92 ->SetPolicy(onc::ONC_SOURCE_UNKNOWN, | |
93 ChromeOsUserHashForBrowserContext(*profile), | |
94 policy_network_configs, | |
95 policy_global_config); | |
96 | |
97 return true; | |
pneubeck (no reviews)
2015/01/30 14:38:45
return value not required?
mukesh agrawal
2015/01/30 22:28:14
I think your point is that, since the function alw
pneubeck (no reviews)
2015/01/31 10:26:40
If you want to keep it, I'd suggest to at least do
mukesh agrawal
2015/02/02 20:36:40
Done.
| |
98 } | |
99 | |
100 void AddWifiCredentialToProfileChromeOs( | |
101 Profile* profile, const WifiCredential& credential) { | |
102 DCHECK(profile); | |
103 scoped_ptr<base::DictionaryValue> onc_properties = | |
104 credential.ToOncProperties(); | |
105 if (!onc_properties) { | |
pneubeck (no reviews)
2015/01/30 14:38:45
nit: equivalent to
CHECK(onc_properties) << ...
mukesh agrawal
2015/01/30 22:28:14
Done.
| |
106 LOG(FATAL) << "Failed to generate ONC properties for " | |
107 << credential.ToString(); | |
108 } | |
109 GetManagedNetworkConfigurationHandler() | |
110 ->CreateConfiguration( | |
111 ChromeOsUserHashForBrowserContext(*profile), | |
112 *onc_properties, | |
113 ::chromeos::network_handler::StringResultCallback(), | |
114 base::Bind(LogCreateConfigurationFailure, | |
115 base::StringPrintf("Failed to add credential %s", | |
116 credential.ToString().c_str()))); | |
117 } | |
118 | |
43 WifiCredentialSet GetWifiCredentialsForProfileChromeOs(const Profile* profile) { | 119 WifiCredentialSet GetWifiCredentialsForProfileChromeOs(const Profile* profile) { |
44 DCHECK(profile); | 120 DCHECK(profile); |
45 return wifi_sync::GetWifiCredentialsForShillProfile( | 121 return wifi_sync::GetWifiCredentialsForShillProfile( |
46 GetNetworkStateHandler(), ShillProfilePathForBrowserContext(*profile)); | 122 GetNetworkStateHandler(), ShillProfilePathForBrowserContext(*profile)); |
47 } | 123 } |
48 | 124 |
125 } // namespace chromeos | |
126 | |
49 } // namespace wifi_credentials_helper | 127 } // namespace wifi_credentials_helper |
OLD | NEW |