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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
// Copyright (c) 2012 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.
#include "sync/internal_api/js_sync_manager_observer.h"
#include <cstddef>
#include "base/location.h"
#include "base/logging.h"
#include "base/string_number_conversions.h"
#include "base/values.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/change_record.h"
#include "sync/internal_api/public/sessions/sync_session_snapshot.h"
#include "sync/internal_api/public/util/sync_string_conversions.h"
#include "sync/js/js_arg_list.h"
#include "sync/js/js_event_details.h"
#include "sync/js/js_event_handler.h"
#include "sync/sessions/session_state.h"
namespace syncer {
JsSyncManagerObserver::JsSyncManagerObserver() {}
JsSyncManagerObserver::~JsSyncManagerObserver() {}
void JsSyncManagerObserver::SetJsEventHandler(
const WeakHandle<JsEventHandler>& event_handler) {
event_handler_ = event_handler;
}
void JsSyncManagerObserver::OnSyncCycleCompleted(
const sessions::SyncSessionSnapshot& snapshot) {
if (!event_handler_.IsInitialized()) {
return;
}
DictionaryValue details;
details.Set("snapshot", snapshot.ToValue());
HandleJsEvent(FROM_HERE, "onSyncCycleCompleted", JsEventDetails(&details));
}
void JsSyncManagerObserver::OnConnectionStatusChange(ConnectionStatus status) {
if (!event_handler_.IsInitialized()) {
return;
}
DictionaryValue details;
details.SetString("status", ConnectionStatusToString(status));
HandleJsEvent(FROM_HERE,
"onConnectionStatusChange", JsEventDetails(&details));
}
void JsSyncManagerObserver::OnUpdatedToken(const std::string& token) {
if (!event_handler_.IsInitialized()) {
return;
}
DictionaryValue details;
details.SetString("token", "<redacted>");
HandleJsEvent(FROM_HERE, "onUpdatedToken", JsEventDetails(&details));
}
void JsSyncManagerObserver::OnPassphraseRequired(
PassphraseRequiredReason reason,
const sync_pb::EncryptedData& pending_keys) {
if (!event_handler_.IsInitialized()) {
return;
}
DictionaryValue details;
details.SetString("reason",
PassphraseRequiredReasonToString(reason));
HandleJsEvent(FROM_HERE, "onPassphraseRequired", JsEventDetails(&details));
}
void JsSyncManagerObserver::OnPassphraseAccepted() {
if (!event_handler_.IsInitialized()) {
return;
}
DictionaryValue details;
HandleJsEvent(FROM_HERE, "onPassphraseAccepted", JsEventDetails(&details));
}
void JsSyncManagerObserver::OnBootstrapTokenUpdated(
const std::string& boostrap_token) {
if (!event_handler_.IsInitialized()) {
return;
}
DictionaryValue details;
details.SetString("bootstrapToken", "<redacted>");
HandleJsEvent(FROM_HERE, "OnBootstrapTokenUpdated", JsEventDetails(&details));
}
void JsSyncManagerObserver::OnEncryptedTypesChanged(
ModelTypeSet encrypted_types,
bool encrypt_everything) {
if (!event_handler_.IsInitialized()) {
return;
}
DictionaryValue details;
details.Set("encryptedTypes",
ModelTypeSetToValue(encrypted_types));
details.SetBoolean("encryptEverything", encrypt_everything);
HandleJsEvent(FROM_HERE,
"onEncryptedTypesChanged", JsEventDetails(&details));
}
void JsSyncManagerObserver::OnEncryptionComplete() {
if (!event_handler_.IsInitialized()) {
return;
}
DictionaryValue details;
HandleJsEvent(FROM_HERE, "onEncryptionComplete", JsEventDetails());
}
void JsSyncManagerObserver::OnActionableError(
const SyncProtocolError& sync_error) {
if (!event_handler_.IsInitialized()) {
return;
}
DictionaryValue details;
details.Set("syncError", sync_error.ToValue());
HandleJsEvent(FROM_HERE, "onActionableError",
JsEventDetails(&details));
}
void JsSyncManagerObserver::OnInitializationComplete(
const WeakHandle<JsBackend>& js_backend,
bool success) {
if (!event_handler_.IsInitialized()) {
return;
}
// Ignore the |js_backend| argument; it's not really convertible to
// JSON anyway.
HandleJsEvent(FROM_HERE, "onInitializationComplete", JsEventDetails());
}
void JsSyncManagerObserver::OnStopSyncingPermanently() {
if (!event_handler_.IsInitialized()) {
return;
}
HandleJsEvent(FROM_HERE, "onStopSyncingPermanently", JsEventDetails());
}
void JsSyncManagerObserver::HandleJsEvent(
const tracked_objects::Location& from_here,
const std::string& name, const JsEventDetails& details) {
if (!event_handler_.IsInitialized()) {
NOTREACHED();
return;
}
event_handler_.Call(from_here,
&JsEventHandler::HandleJsEvent, name, details);
}
} // namespace syncer
|