Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1033)

Side by Side Diff: components/sync/core_impl/js_sync_manager_observer.cc

Issue 2413313004: [Sync] Move the last things out of core/. (Closed)
Patch Set: Address comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 #include "components/sync/core_impl/js_sync_manager_observer.h"
6
7 #include <cstddef>
8
9 #include "base/location.h"
10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/values.h"
13 #include "components/sync/base/model_type.h"
14 #include "components/sync/engine/cycle/sync_cycle_snapshot.h"
15 #include "components/sync/engine/sync_string_conversions.h"
16 #include "components/sync/js/js_event_details.h"
17 #include "components/sync/js/js_event_handler.h"
18 #include "components/sync/syncable/change_record.h"
19
20 namespace syncer {
21
22 JsSyncManagerObserver::JsSyncManagerObserver() {}
23
24 JsSyncManagerObserver::~JsSyncManagerObserver() {}
25
26 void JsSyncManagerObserver::SetJsEventHandler(
27 const WeakHandle<JsEventHandler>& event_handler) {
28 event_handler_ = event_handler;
29 }
30
31 void JsSyncManagerObserver::OnSyncCycleCompleted(
32 const SyncCycleSnapshot& snapshot) {
33 if (!event_handler_.IsInitialized()) {
34 return;
35 }
36 base::DictionaryValue details;
37 details.Set("snapshot", snapshot.ToValue());
38 HandleJsEvent(FROM_HERE, "onSyncCycleCompleted", JsEventDetails(&details));
39 }
40
41 void JsSyncManagerObserver::OnConnectionStatusChange(ConnectionStatus status) {
42 if (!event_handler_.IsInitialized()) {
43 return;
44 }
45 base::DictionaryValue details;
46 details.SetString("status", ConnectionStatusToString(status));
47 HandleJsEvent(FROM_HERE, "onConnectionStatusChange",
48 JsEventDetails(&details));
49 }
50
51 void JsSyncManagerObserver::OnActionableError(
52 const SyncProtocolError& sync_error) {
53 if (!event_handler_.IsInitialized()) {
54 return;
55 }
56 base::DictionaryValue details;
57 details.Set("syncError", sync_error.ToValue());
58 HandleJsEvent(FROM_HERE, "onActionableError", JsEventDetails(&details));
59 }
60
61 void JsSyncManagerObserver::OnProtocolEvent(const ProtocolEvent& event) {}
62
63 void JsSyncManagerObserver::OnMigrationRequested(ModelTypeSet types) {}
64
65 void JsSyncManagerObserver::OnInitializationComplete(
66 const WeakHandle<JsBackend>& js_backend,
67 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener,
68 bool success,
69 ModelTypeSet restored_types) {
70 if (!event_handler_.IsInitialized()) {
71 return;
72 }
73 // Ignore the |js_backend| argument; it's not really convertible to
74 // JSON anyway.
75
76 base::DictionaryValue details;
77 details.Set("restoredTypes", ModelTypeSetToValue(restored_types));
78
79 HandleJsEvent(FROM_HERE, "onInitializationComplete",
80 JsEventDetails(&details));
81 }
82
83 void JsSyncManagerObserver::HandleJsEvent(
84 const tracked_objects::Location& from_here,
85 const std::string& name,
86 const JsEventDetails& details) {
87 if (!event_handler_.IsInitialized()) {
88 NOTREACHED();
89 return;
90 }
91 event_handler_.Call(from_here, &JsEventHandler::HandleJsEvent, name, details);
92 }
93
94 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/core_impl/js_sync_manager_observer.h ('k') | components/sync/core_impl/js_sync_manager_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698