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 explicit WifiCredentialSyncableService( | |
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 an error to add a network that already exists. It is also an | |
mukesh agrawal
2015/01/22 23:36:03
I meant for this change to be included in PS5. Sor
| |
56 // error to call this method before MergeDataAndStartSyncing(), or | |
57 // after StopSyncing(). | |
58 // | |
59 // TODO(quiche): Allow changing a credential, by addding it again. | |
60 // crbug.com/431436 | |
61 bool AddToSyncedNetworks(const std::string& item_id, | |
62 const WifiCredential& credential); | |
63 | |
40 private: | 64 private: |
41 // The syncer::ModelType that this SyncableService processes and | 65 // The syncer::ModelType that this SyncableService processes and |
42 // generates updates for. | 66 // generates updates for. |
43 static const syncer::ModelType kModelType; | 67 static const syncer::ModelType kModelType; |
44 | 68 |
69 // The object we use to change local network configuration. | |
70 const scoped_ptr<WifiConfigDelegate> network_config_delegate_; | |
71 | |
45 // Our SyncChangeProcessor instance. Used to push changes into | 72 // Our SyncChangeProcessor instance. Used to push changes into |
46 // Chrome Sync. | 73 // Chrome Sync. |
47 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 74 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
48 | 75 |
49 DISALLOW_COPY_AND_ASSIGN(WifiCredentialSyncableService); | 76 DISALLOW_COPY_AND_ASSIGN(WifiCredentialSyncableService); |
50 }; | 77 }; |
51 | 78 |
52 } // namespace wifi_sync | 79 } // namespace wifi_sync |
53 | 80 |
54 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_ | 81 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_ |
OLD | NEW |