Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: components/wifi_sync/wifi_credential.h

Issue 809803005: wifi_sync: add ability to convert WifiCredential to onc properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@submit-4.0-wifi-security-class
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ 5 #ifndef COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_
6 #define COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ 6 #define COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "components/wifi_sync/wifi_security_class.h" 14 #include "components/wifi_sync/wifi_security_class.h"
15 15
16 namespace base {
17 class DictionaryValue;
18 }
19
16 namespace wifi_sync { 20 namespace wifi_sync {
17 21
18 // A container to hold the information required to locate and connect 22 // A container to hold the information required to locate and connect
19 // to a WiFi network. 23 // to a WiFi network.
20 class WifiCredential final { // final because the class is copyable 24 class WifiCredential final { // final because the class is copyable
erikwright (departed) 2015/01/08 19:27:08 Is it your intention to permit use of the default
mukesh agrawal 2015/01/09 02:00:18 No, I don't expect there will be a need for defaul
21 public: 25 public:
22 using SsidBytes = std::vector<uint8_t>; 26 using SsidBytes = std::vector<uint8_t>;
23 using CredentialSet = std::set< 27 using CredentialSet = std::set<
24 WifiCredential, 28 WifiCredential,
25 bool(*)(const WifiCredential&a, const WifiCredential& b)>; 29 bool(*)(const WifiCredential&a, const WifiCredential& b)>;
26 30
27 // Constructs a credential with the given |ssid|, |security_class|, 31 // Constructs a credential with the given |ssid|, |security_class|,
28 // and |passphrase|. No assumptions are made about the input 32 // and |passphrase|. No assumptions are made about the input
erikwright (departed) 2015/01/08 19:27:07 You now make an assumption that it is UTF-8.
mukesh agrawal 2015/01/09 02:00:18 See below (comment on ToOncProperties).
29 // encoding of |ssid|. The passphrase must be valid UTF-8. 33 // encoding of |ssid|. The passphrase must be valid UTF-8.
30 WifiCredential(const SsidBytes& ssid, 34 WifiCredential(const SsidBytes& ssid,
31 WifiSecurityClass security_class, 35 WifiSecurityClass security_class,
32 const std::string& passphrase); 36 const std::string& passphrase);
33 ~WifiCredential(); 37 ~WifiCredential();
34 38
35 const SsidBytes& ssid() const { return ssid_; } 39 const SsidBytes& ssid() const { return ssid_; }
36 WifiSecurityClass security_class() const { return security_class_; } 40 WifiSecurityClass security_class() const { return security_class_; }
37 const std::string& passphrase() const { return passphrase_; } 41 const std::string& passphrase() const { return passphrase_; }
38 42
43 // Updates |onc_properties|, adding elements which represent the ONC
44 // properties for this credential. The resulting |onc_properties|
45 // can be used, e.g, to configure a new network. On failure,
46 // returns false, and leaves |onc_properties| unmodified.
47 bool ToOncProperties(base::DictionaryValue* onc_properties) const;
erikwright (departed) 2015/01/08 19:27:08 It seems a bit strange to me that you can instanti
erikwright (departed) 2015/01/08 19:27:08 Does it make sense to add properties to an existin
mukesh agrawal 2015/01/09 02:00:18 It's definitely strange. We have a bug open for th
mukesh agrawal 2015/01/09 02:00:18 Done. Thanks for the idea. I wanted to do somethi
48
39 // Returns a string representation of the credential, for debugging 49 // Returns a string representation of the credential, for debugging
40 // purposes. The string will not include the credential's passphrase. 50 // purposes. The string will not include the credential's passphrase.
41 std::string ToString() const; 51 std::string ToString() const;
42 52
43 // Returns true if credential |a| comes before credential |b|. 53 // Returns true if credential |a| comes before credential |b|.
44 static bool IsLessThan(const WifiCredential& a, const WifiCredential& b); 54 static bool IsLessThan(const WifiCredential& a, const WifiCredential& b);
45 55
46 // Returns an empty set of WifiCredentials, with the IsLessThan 56 // Returns an empty set of WifiCredentials, with the IsLessThan
47 // ordering function plumbed in. 57 // ordering function plumbed in.
48 static CredentialSet MakeSet(); 58 static CredentialSet MakeSet();
49 59
60 // Returns |ssid| as an SsidBytes instance. This convenience
61 // function simplifies some tests, which need to instantiate
62 // SsidBytes from string literals.
63 static SsidBytes MakeSsidBytes(const std::string& ssid);
stevenjb 2015/01/08 17:27:51 If this is only used for tests, append ForTest to
erikwright (departed) 2015/01/08 19:27:07 How will SsidBytes normally be constructed? What i
mukesh agrawal 2015/01/09 02:00:18 Done.
mukesh agrawal 2015/01/09 02:00:18 In the normal case, SsidBytes will be (copy-)const
erikwright (departed) 2015/01/09 14:58:20 Can you, in that case, please add a link or commen
mukesh agrawal 2015/01/09 19:00:02 Done. (Added comment about valid SSIDs.)
64
50 private: 65 private:
51 // The WiFi network's SSID. 66 // The WiFi network's SSID.
52 const SsidBytes ssid_; 67 const SsidBytes ssid_;
53 // The WiFi network's security class (e.g. WEP, PSK). 68 // The WiFi network's security class (e.g. WEP, PSK).
54 const WifiSecurityClass security_class_; 69 const WifiSecurityClass security_class_;
55 // The passphrase for connecting to the network. 70 // The passphrase for connecting to the network.
56 const std::string passphrase_; 71 const std::string passphrase_;
57 }; 72 };
58 73
59 } // namespace wifi_sync 74 } // namespace wifi_sync
60 75
61 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ 76 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698