1 // Copyright 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.
5 #ifndef SYNC_JS_SYNC_JS_CONTROLLER_H_
6 #define SYNC_JS_SYNC_JS_CONTROLLER_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h"
15 #include "sync/base/sync_export.h"
16 #include "sync/internal_api/public/util/weak_handle.h"
17 #include "sync/js/js_controller.h"
18 #include "sync/js/js_event_handler.h"
24 // A class that mediates between the sync JsEventHandlers and the sync
26 class SYNC_EXPORT SyncJsController
27 : public JsController
, public JsEventHandler
,
28 public base::SupportsWeakPtr
<SyncJsController
> {
32 ~SyncJsController() override
;
34 // Sets the backend to route all messages to (if initialized).
35 // Sends any queued-up messages if |backend| is initialized.
36 void AttachJsBackend(const WeakHandle
<JsBackend
>& js_backend
);
38 // JsController implementation.
39 void AddJsEventHandler(JsEventHandler
* event_handler
) override
;
40 void RemoveJsEventHandler(JsEventHandler
* event_handler
) override
;
42 // JsEventHandler implementation.
43 void HandleJsEvent(const std::string
& name
,
44 const JsEventDetails
& details
) override
;
47 // Sets |js_backend_|'s event handler depending on how many
48 // underlying event handlers we have.
49 void UpdateBackendEventHandler();
51 WeakHandle
<JsBackend
> js_backend_
;
52 base::ObserverList
<JsEventHandler
> js_event_handlers_
;
54 DISALLOW_COPY_AND_ASSIGN(SyncJsController
);
59 #endif // SYNC_JS_SYNC_JS_CONTROLLER_H_