| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_SYNCABLE_SERVICE_IMPL_H_ | 5 #ifndef COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_IMPL_H_ |
| 6 #define COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_IMPL_H_ | 6 #define COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_IMPL_H_ |
| 7 | 7 |
| 8 #include "components/wifi_sync/wifi_credential_syncable_service.h" | 8 #include "components/wifi_sync/wifi_credential_syncable_service.h" |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "components/wifi_sync/wifi_config_delegate.h" | 15 #include "components/wifi_sync/wifi_config_delegate.h" |
| 16 #include "components/wifi_sync/wifi_config_observer.h" |
| 16 #include "components/wifi_sync/wifi_credential.h" | 17 #include "components/wifi_sync/wifi_credential.h" |
| 17 #include "components/wifi_sync/wifi_security_class.h" | 18 #include "components/wifi_sync/wifi_security_class.h" |
| 18 #include "sync/api/sync_change_processor.h" | 19 #include "sync/api/sync_change_processor.h" |
| 19 | 20 |
| 20 namespace wifi_sync { | 21 namespace wifi_sync { |
| 21 | 22 |
| 22 // This service does not necessarily own the storage for WiFi | 23 // This service does not necessarily own the storage for WiFi |
| 23 // credentials. In particular, on ChromeOS, WiFi credential storage is | 24 // credentials. In particular, on ChromeOS, WiFi credential storage is |
| 24 // managed by the ChromeOS connection manager ("Shill"). | 25 // managed by the ChromeOS connection manager ("Shill"). |
| 25 // | 26 // |
| 26 // On ChromeOS, this class should only be instantiated | 27 // On ChromeOS, this class should only be instantiated |
| 27 // for the primary user profile, as that is the only profile for | 28 // for the primary user profile, as that is the only profile for |
| 28 // which a Shill profile is loaded. | 29 // which a Shill profile is loaded. |
| 29 class WifiCredentialSyncableServiceImpl | 30 class WifiCredentialSyncableServiceImpl |
| 30 : public WifiCredentialSyncableService { | 31 : public WifiCredentialSyncableService { |
| 31 public: | 32 public: |
| 32 // Constructs a syncable service. Changes from Chrome Sync will be | 33 // Constructs a syncable service. Changes from Chrome Sync will be |
| 33 // applied locally by |network_config_delegate|. Local changes will | 34 // applied locally by |network_config_delegate|. Local changes will |
| 34 // be propagated to Chrome Sync using the |sync_processor| provided | 35 // be propagated to Chrome Sync using the |sync_processor| provided |
| 35 // in the call to MergeDataAndStartSyncing. | 36 // in the call to MergeDataAndStartSyncing. |
| 36 explicit WifiCredentialSyncableServiceImpl( | 37 WifiCredentialSyncableServiceImpl( |
| 37 scoped_ptr<WifiConfigDelegate> network_config_delegate); | 38 scoped_ptr<WifiConfigDelegate> network_config_delegate, |
| 39 scoped_ptr<WifiConfigObserver> network_config_observer); |
| 38 ~WifiCredentialSyncableServiceImpl() override; | 40 ~WifiCredentialSyncableServiceImpl() override; |
| 39 | 41 |
| 40 // syncer::SyncableService implementation. | 42 // syncer::SyncableService implementation. |
| 41 syncer::SyncMergeResult MergeDataAndStartSyncing( | 43 syncer::SyncMergeResult MergeDataAndStartSyncing( |
| 42 syncer::ModelType type, | 44 syncer::ModelType type, |
| 43 const syncer::SyncDataList& initial_sync_data, | 45 const syncer::SyncDataList& initial_sync_data, |
| 44 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 46 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 45 scoped_ptr<syncer::SyncErrorFactory> error_handler) override; | 47 scoped_ptr<syncer::SyncErrorFactory> error_handler) override; |
| 46 void StopSyncing(syncer::ModelType type) override; | 48 void StopSyncing(syncer::ModelType type) override; |
| 47 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; | 49 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; |
| 48 syncer::SyncError ProcessSyncChanges( | 50 syncer::SyncError ProcessSyncChanges( |
| 49 const tracked_objects::Location& caller_location, | 51 const tracked_objects::Location& caller_location, |
| 50 const syncer::SyncChangeList& change_list) override; | 52 const syncer::SyncChangeList& change_list) override; |
| 51 | 53 |
| 52 // WifiCredentialSyncableService implementation. | 54 // WifiCredentialSyncableService implementation. |
| 53 bool AddToSyncedNetworks(const std::string& item_id, | 55 bool AddToSyncedNetworks(const WifiCredential& credential) override; |
| 54 const WifiCredential& credential) override; | |
| 55 | 56 |
| 56 private: | 57 private: |
| 57 using SsidAndSecurityClass = | 58 using SsidAndSecurityClass = |
| 58 std::pair<WifiCredential::SsidBytes, WifiSecurityClass>; | 59 std::pair<WifiCredential::SsidBytes, WifiSecurityClass>; |
| 59 using SsidAndSecurityClassToPassphrase = | 60 using SsidAndSecurityClassToPassphrase = |
| 60 std::map<SsidAndSecurityClass, std::string>; | 61 std::map<SsidAndSecurityClass, std::string>; |
| 61 | 62 |
| 62 // The syncer::ModelType that this SyncableService processes and | 63 // The syncer::ModelType that this SyncableService processes and |
| 63 // generates updates for. | 64 // generates updates for. |
| 64 static const syncer::ModelType kModelType; | 65 static const syncer::ModelType kModelType; |
| 65 | 66 |
| 66 // The object we use to change local network configuration. | 67 // The object we use to change local network configuration. |
| 67 const scoped_ptr<WifiConfigDelegate> network_config_delegate_; | 68 const scoped_ptr<WifiConfigDelegate> network_config_delegate_; |
| 68 | 69 |
| 70 // The object that informs us about changes to local network |
| 71 // configuration. |
| 72 const scoped_ptr<WifiConfigObserver> network_config_observer_; |
| 73 |
| 69 // Our SyncChangeProcessor instance. Used to push changes into | 74 // Our SyncChangeProcessor instance. Used to push changes into |
| 70 // Chrome Sync. | 75 // Chrome Sync. |
| 71 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 76 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 72 | 77 |
| 73 // The networks and passphrases that are already known by Chrome | 78 // The networks and passphrases that are already known by Chrome |
| 74 // Sync. All synced networks must be included in this map, even if | 79 // Sync. All synced networks must be included in this map, even if |
| 75 // they do not use passphrases. | 80 // they do not use passphrases. |
| 76 SsidAndSecurityClassToPassphrase synced_networks_and_passphrases_; | 81 SsidAndSecurityClassToPassphrase synced_networks_and_passphrases_; |
| 77 | 82 |
| 78 DISALLOW_COPY_AND_ASSIGN(WifiCredentialSyncableServiceImpl); | 83 DISALLOW_COPY_AND_ASSIGN(WifiCredentialSyncableServiceImpl); |
| 79 }; | 84 }; |
| 80 | 85 |
| 81 } // namespace wifi_sync | 86 } // namespace wifi_sync |
| 82 | 87 |
| 83 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_IMPL_H_ | 88 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_IMPL_H_ |
| OLD | NEW |