OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_ | |
6 #define COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 #include <string> | |
11 #include <utility> | |
12 | |
13 #include "base/macros.h" | |
14 #include "components/keyed_service/core/keyed_service.h" | |
15 #include "components/sync/model/sync_change_processor.h" | |
16 #include "components/sync/model/syncable_service.h" | |
17 #include "components/wifi_sync/wifi_config_delegate.h" | |
18 #include "components/wifi_sync/wifi_credential.h" | |
19 #include "components/wifi_sync/wifi_security_class.h" | |
20 | |
21 namespace wifi_sync { | |
22 | |
23 // KeyedService that synchronizes WiFi credentials between local settings, | |
24 // and Chrome Sync. | |
25 // | |
26 // This service does not necessarily own the storage for WiFi | |
27 // credentials. In particular, on ChromeOS, WiFi credential storage is | |
28 // managed by the ChromeOS connection manager ("Shill"). | |
29 // | |
30 // On ChromeOS, this class should only be instantiated | |
31 // for the primary user profile, as that is the only profile for | |
32 // which a Shill profile is loaded. | |
33 class WifiCredentialSyncableService | |
34 : public syncer::SyncableService, public KeyedService { | |
35 public: | |
36 // Constructs a syncable service. Changes from Chrome Sync will be | |
37 // applied locally by |network_config_delegate|. Local changes will | |
38 // be propagated to Chrome Sync using the |sync_processor| provided | |
39 // in the call to MergeDataAndStartSyncing. | |
40 explicit WifiCredentialSyncableService( | |
41 std::unique_ptr<WifiConfigDelegate> network_config_delegate); | |
42 ~WifiCredentialSyncableService() override; | |
43 | |
44 // syncer::SyncableService implementation. | |
45 syncer::SyncMergeResult MergeDataAndStartSyncing( | |
46 syncer::ModelType type, | |
47 const syncer::SyncDataList& initial_sync_data, | |
48 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor, | |
49 std::unique_ptr<syncer::SyncErrorFactory> error_handler) override; | |
50 void StopSyncing(syncer::ModelType type) override; | |
51 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; | |
52 syncer::SyncError ProcessSyncChanges( | |
53 const tracked_objects::Location& caller_location, | |
54 const syncer::SyncChangeList& change_list) override; | |
55 | |
56 // Adds a WiFiCredential to Chrome Sync. |item_id| is a persistent | |
57 // identifier which can be used to later remove the credential. It | |
58 // is an error to add a network that already exists. It is also an | |
59 // error to call this method before MergeDataAndStartSyncing(), or | |
60 // after StopSyncing(). | |
61 // | |
62 // TODO(quiche): Allow changing a credential, by addding it again. | |
63 // crbug.com/431436 | |
64 bool AddToSyncedNetworks(const std::string& item_id, | |
65 const WifiCredential& credential); | |
66 | |
67 private: | |
68 using SsidAndSecurityClass = | |
69 std::pair<WifiCredential::SsidBytes, WifiSecurityClass>; | |
70 using SsidAndSecurityClassToPassphrase = | |
71 std::map<SsidAndSecurityClass, std::string>; | |
72 | |
73 // The syncer::ModelType that this SyncableService processes and | |
74 // generates updates for. | |
75 static const syncer::ModelType kModelType; | |
76 | |
77 // The object we use to change local network configuration. | |
78 const std::unique_ptr<WifiConfigDelegate> network_config_delegate_; | |
79 | |
80 // Our SyncChangeProcessor instance. Used to push changes into | |
81 // Chrome Sync. | |
82 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_; | |
83 | |
84 // The networks and passphrases that are already known by Chrome | |
85 // Sync. All synced networks must be included in this map, even if | |
86 // they do not use passphrases. | |
87 SsidAndSecurityClassToPassphrase synced_networks_and_passphrases_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(WifiCredentialSyncableService); | |
90 }; | |
91 | |
92 } // namespace wifi_sync | |
93 | |
94 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_ | |
OLD | NEW |