File: sync_service_base.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 (109 lines) | stat: -rw-r--r-- 4,262 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2016 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_DRIVER_SYNC_SERVICE_BASE_H_
#define COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_BASE_H_

#include <memory>
#include <string>

#include "base/files/file_path.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
#include "components/sync/base/sync_prefs.h"
#include "components/sync/base/unrecoverable_error_handler.h"
#include "components/sync/base/weak_handle.h"
#include "components/sync/driver/signin_manager_wrapper.h"
#include "components/sync/driver/sync_client.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/engine/sync_engine.h"
#include "components/sync/engine/sync_engine_host.h"
#include "components/sync/engine/sync_manager.h"
#include "components/sync/js/sync_js_controller.h"
#include "components/version_info/version_info.h"

namespace syncer {

// This is a base class for implementations of SyncService that contains some
// common functionality and member variables. Anything that can live inside the
// sync component should eventually live here instead of a concrete
// implementation. This is set up as a base class so things can be transferred
// piece by piece as easily as possible.
class SyncServiceBase : public SyncService, public SyncEngineHost {
 public:
  SyncServiceBase(std::unique_ptr<SyncClient> sync_client,
                  std::unique_ptr<SigninManagerWrapper> signin,
                  const version_info::Channel& channel,
                  const base::FilePath& base_directory,
                  const std::string& debug_identifier);
  ~SyncServiceBase() override;

 protected:
  // Kicks off asynchronous initialization of the SyncEngine.
  void InitializeEngine();

  // Returns SyncCredentials from the OAuth2TokenService.
  virtual SyncCredentials GetCredentials() = 0;

  // Returns a weak handle to the JsEventHandler.
  virtual WeakHandle<JsEventHandler> GetJsEventHandler() = 0;

  // Returns a callback that makes an HttpPostProviderFactory.
  virtual SyncEngine::HttpPostProviderFactoryGetter
  MakeHttpPostProviderFactoryGetter() = 0;

  // Takes the previously saved nigori state; null if there isn't any.
  virtual std::unique_ptr<SyncEncryptionHandler::NigoriState>
  MoveSavedNigoriState() = 0;

  // Returns a weak handle to an UnrecoverableErrorHandler (may be |this|).
  virtual WeakHandle<UnrecoverableErrorHandler>
  GetUnrecoverableErrorHandler() = 0;

  // This profile's SyncClient, which abstracts away non-Sync dependencies and
  // the Sync API component factory.
  const std::unique_ptr<SyncClient> sync_client_;

  // Encapsulates user signin - used to set/get the user's authenticated
  // email address.
  const std::unique_ptr<SigninManagerWrapper> signin_;

  // The product channel of the embedder.
  const version_info::Channel channel_;

  // The path to the base directory under which sync should store its
  // information.
  const base::FilePath base_directory_;

  // The full path to the sync data folder. The folder is not fully deleted when
  // sync is disabled, since it holds both Directory and ModelTypeStore data.
  // Directory files will be selectively targeted instead.
  const base::FilePath sync_data_folder_;

  // An identifier representing this instance for debugging purposes.
  const std::string debug_identifier_;

  // The class that handles getting, setting, and persisting sync
  // preferences.
  SyncPrefs sync_prefs_;

  // The thread where all the sync operations happen. This thread is kept alive
  // until browser shutdown and reused if sync is turned off and on again. It is
  // joined during the shutdown process, but there is an abort mechanism in
  // place to prevent slow HTTP requests from blocking browser shutdown.
  std::unique_ptr<base::Thread> sync_thread_;

  // Our asynchronous engine to communicate with sync components living on
  // other threads.
  std::unique_ptr<SyncEngine> engine_;

 private:
  bool GetLocalSyncConfig(base::FilePath* local_sync_backend_folder) const;

  DISALLOW_COPY_AND_ASSIGN(SyncServiceBase);
};

}  // namespace syncer

#endif  // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_BASE_H_