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 #ifndef COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_ | 5 #ifndef COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_ |
6 #define COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_ | 6 #define COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_ |
7 | 7 |
8 #include <string> | |
9 | |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
13 #include "components/wifi_sync/wifi_config_delegate.h" | |
11 #include "sync/api/sync_change_processor.h" | 14 #include "sync/api/sync_change_processor.h" |
12 #include "sync/api/syncable_service.h" | 15 #include "sync/api/syncable_service.h" |
13 | 16 |
14 namespace wifi_sync { | 17 namespace wifi_sync { |
18 class WifiCredential; | |
15 | 19 |
16 // KeyedService that synchronizes WiFi credentials between local settings, | 20 // KeyedService that synchronizes WiFi credentials between local settings, |
17 // and Chrome Sync. | 21 // and Chrome Sync. |
18 // | 22 // |
19 // This service does not necessarily own the storage for WiFi | 23 // This service does not necessarily own the storage for WiFi |
20 // credentials. In particular, on ChromeOS, WiFi credential storage is | 24 // credentials. In particular, on ChromeOS, WiFi credential storage is |
21 // managed by the ChromeOS connection manager ("Shill"). | 25 // managed by the ChromeOS connection manager ("Shill"). |
26 // | |
27 // On ChromeOS, this class should only be instantiated | |
28 // for the primary user profile, as that is the only profile for | |
29 // which a Shill profile is loaded. | |
22 class WifiCredentialSyncableService | 30 class WifiCredentialSyncableService |
23 : public syncer::SyncableService, public KeyedService { | 31 : public syncer::SyncableService, public KeyedService { |
24 public: | 32 public: |
25 WifiCredentialSyncableService(); | 33 // Constructs a syncable service. Changes from Chrome Sync will be |
34 // applied locally by |network_config_delegate|. Local changes will | |
35 // be propagated to Chrome Sync using the |sync_processor| provided | |
36 // in the call to MergeDataAndStartSyncing. | |
37 WifiCredentialSyncableService( | |
stevenjb
2015/01/14 00:12:48
explicit
mukesh agrawal
2015/01/20 21:13:15
Done.
| |
38 scoped_ptr<WifiConfigDelegate> network_config_delegate); | |
26 ~WifiCredentialSyncableService() override; | 39 ~WifiCredentialSyncableService() override; |
27 | 40 |
28 // syncer::SyncableService implementation. | 41 // syncer::SyncableService implementation. |
29 syncer::SyncMergeResult MergeDataAndStartSyncing( | 42 syncer::SyncMergeResult MergeDataAndStartSyncing( |
30 syncer::ModelType type, | 43 syncer::ModelType type, |
31 const syncer::SyncDataList& initial_sync_data, | 44 const syncer::SyncDataList& initial_sync_data, |
32 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 45 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
33 scoped_ptr<syncer::SyncErrorFactory> error_handler) override; | 46 scoped_ptr<syncer::SyncErrorFactory> error_handler) override; |
34 void StopSyncing(syncer::ModelType type) override; | 47 void StopSyncing(syncer::ModelType type) override; |
35 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; | 48 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; |
36 syncer::SyncError ProcessSyncChanges( | 49 syncer::SyncError ProcessSyncChanges( |
37 const tracked_objects::Location& caller_location, | 50 const tracked_objects::Location& caller_location, |
38 const syncer::SyncChangeList& change_list) override; | 51 const syncer::SyncChangeList& change_list) override; |
39 | 52 |
53 // Adds a WiFiCredential to Chrome Sync. |item_id| is a persistent | |
54 // identifier which can be used to later remove the credential. It | |
55 // is permitted to change an existing network by adding it again. It | |
56 // is an error to call this method before | |
57 // MergeDataAndStartSyncing(), or after StopSyncing(). | |
58 bool AddToSyncedNetworks( | |
59 const std::string& item_id, const WifiCredential& credential); | |
60 | |
40 private: | 61 private: |
41 // The syncer::ModelType that this SyncableService processes and | 62 // The syncer::ModelType that this SyncableService processes and |
42 // generates updates for. | 63 // generates updates for. |
43 static const syncer::ModelType kModelType; | 64 static const syncer::ModelType kModelType; |
44 | 65 |
66 // The object we use to change local network configuration. | |
67 const scoped_ptr<WifiConfigDelegate> network_config_delegate_; | |
stevenjb
2015/01/14 00:12:48
nit: WS
mukesh agrawal
2015/01/20 21:13:15
Done.
| |
45 // Our SyncChangeProcessor instance. Used to push changes into | 68 // Our SyncChangeProcessor instance. Used to push changes into |
46 // Chrome Sync. | 69 // Chrome Sync. |
47 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 70 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
48 | 71 |
49 DISALLOW_COPY_AND_ASSIGN(WifiCredentialSyncableService); | 72 DISALLOW_COPY_AND_ASSIGN(WifiCredentialSyncableService); |
50 }; | 73 }; |
51 | 74 |
52 } // namespace wifi_sync | 75 } // namespace wifi_sync |
53 | 76 |
54 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_ | 77 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_ |
OLD | NEW |