blob: f0bb423b8c2f85c3e9e9f2092125c1ce58ad8e02 (
plain)
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
|
// Copyright 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.
#ifndef SYNC_JS_SYNC_JS_CONTROLLER_H_
#define SYNC_JS_SYNC_JS_CONTROLLER_H_
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "sync/base/sync_export.h"
#include "sync/internal_api/public/util/weak_handle.h"
#include "sync/js/js_controller.h"
#include "sync/js/js_event_handler.h"
namespace syncer {
class JsBackend;
// A class that mediates between the sync JsEventHandlers and the sync
// JsBackend.
class SYNC_EXPORT SyncJsController
: public JsController, public JsEventHandler,
public base::SupportsWeakPtr<SyncJsController> {
public:
SyncJsController();
virtual ~SyncJsController();
// Sets the backend to route all messages to (if initialized).
// Sends any queued-up messages if |backend| is initialized.
void AttachJsBackend(const WeakHandle<JsBackend>& js_backend);
// JsController implementation.
virtual void AddJsEventHandler(JsEventHandler* event_handler) OVERRIDE;
virtual void RemoveJsEventHandler(JsEventHandler* event_handler) OVERRIDE;
// JsEventHandler implementation.
virtual void HandleJsEvent(const std::string& name,
const JsEventDetails& details) OVERRIDE;
private:
// Sets |js_backend_|'s event handler depending on how many
// underlying event handlers we have.
void UpdateBackendEventHandler();
WeakHandle<JsBackend> js_backend_;
ObserverList<JsEventHandler> js_event_handlers_;
DISALLOW_COPY_AND_ASSIGN(SyncJsController);
};
} // namespace syncer
#endif // SYNC_JS_SYNC_JS_CONTROLLER_H_
|