File: wifi_credential_syncable_service.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (94 lines) | stat: -rw-r--r-- 3,881 bytes parent folder | download
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
82
83
84
85
86
87
88
89
90
91
92
93
94
// 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_SYNC_WIFI_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_
#define COMPONENTS_SYNC_WIFI_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_

#include <map>
#include <memory>
#include <string>
#include <utility>

#include "base/macros.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/sync/model/sync_change_processor.h"
#include "components/sync/model/syncable_service.h"
#include "components/sync_wifi/wifi_config_delegate.h"
#include "components/sync_wifi/wifi_credential.h"
#include "components/sync_wifi/wifi_security_class.h"

namespace sync_wifi {

// 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(
      std::unique_ptr<WifiConfigDelegate> network_config_delegate);
  ~WifiCredentialSyncableService() override;

  // syncer::SyncableService implementation.
  syncer::SyncMergeResult MergeDataAndStartSyncing(
      syncer::ModelType type,
      const syncer::SyncDataList& initial_sync_data,
      std::unique_ptr<syncer::SyncChangeProcessor> sync_processor,
      std::unique_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:
  using SsidAndSecurityClass =
      std::pair<WifiCredential::SsidBytes, WifiSecurityClass>;
  using SsidAndSecurityClassToPassphrase =
      std::map<SsidAndSecurityClass, std::string>;

  // 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 std::unique_ptr<WifiConfigDelegate> network_config_delegate_;

  // Our SyncChangeProcessor instance. Used to push changes into
  // Chrome Sync.
  std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_;

  // The networks and passphrases that are already known by Chrome
  // Sync. All synced networks must be included in this map, even if
  // they do not use passphrases.
  SsidAndSecurityClassToPassphrase synced_networks_and_passphrases_;

  DISALLOW_COPY_AND_ASSIGN(WifiCredentialSyncableService);
};

}  // namespace sync_wifi

#endif  // COMPONENTS_SYNC_WIFI_WIFI_CREDENTIAL_SYNCABLE_SERVICE_H_