Revert of Add Masonry to key_silk_cases. (patchset #3 id:40001 of https://codereview...
[chromium-blink-merge.git] / components / wifi_sync / wifi_credential_syncable_service.h
blob51137044afb2b0a1fa9f307ed87673c0dc003a44
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.
5 #ifndef COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_
6 #define COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_
8 #include <map>
9 #include <string>
10 #include <utility>
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "components/keyed_service/core/keyed_service.h"
15 #include "components/wifi_sync/wifi_config_delegate.h"
16 #include "components/wifi_sync/wifi_credential.h"
17 #include "components/wifi_sync/wifi_security_class.h"
18 #include "sync/api/sync_change_processor.h"
19 #include "sync/api/syncable_service.h"
21 namespace wifi_sync {
23 // KeyedService that synchronizes WiFi credentials between local settings,
24 // and Chrome Sync.
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").
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 scoped_ptr<WifiConfigDelegate> network_config_delegate);
42 ~WifiCredentialSyncableService() override;
44 // syncer::SyncableService implementation.
45 syncer::SyncMergeResult MergeDataAndStartSyncing(
46 syncer::ModelType type,
47 const syncer::SyncDataList& initial_sync_data,
48 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
49 scoped_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;
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().
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);
67 private:
68 using SsidAndSecurityClass =
69 std::pair<WifiCredential::SsidBytes, WifiSecurityClass>;
70 using SsidAndSecurityClassToPassphrase =
71 std::map<SsidAndSecurityClass, std::string>;
73 // The syncer::ModelType that this SyncableService processes and
74 // generates updates for.
75 static const syncer::ModelType kModelType;
77 // The object we use to change local network configuration.
78 const scoped_ptr<WifiConfigDelegate> network_config_delegate_;
80 // Our SyncChangeProcessor instance. Used to push changes into
81 // Chrome Sync.
82 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
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_;
89 DISALLOW_COPY_AND_ASSIGN(WifiCredentialSyncableService);
92 } // namespace wifi_sync
94 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_