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