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. 4 5 #ifndef COMPONENTS_SYNC_JS_JS_CONTROLLER_H_ 6 #define COMPONENTS_SYNC_JS_JS_CONTROLLER_H_ 7 8 // See README for design comments. 9 10 #include <string> 11 12 namespace syncer { 13 14 class JsEventHandler; 15 16 // An interface for objects that JsEventHandlers directly interact 17 // with. JsEventHandlers can add themselves to receive events and 18 // also send messages which will eventually reach the backend. 19 class JsController { 20 public: 21 // Adds an event handler which will start receiving JS events (not 22 // immediately, so this can be called in the handler's constructor). 23 // Multiple event handlers are supported, but each event handler 24 // must be added at most once. 25 // 26 // Ideally, we'd take WeakPtrs, but we need the raw pointer values 27 // to be able to look them up for removal. 28 virtual void AddJsEventHandler(JsEventHandler* event_handler) = 0; 29 30 // Removes the given event handler if it has been added. It will 31 // immediately stop receiving any JS events. 32 virtual void RemoveJsEventHandler(JsEventHandler* event_handler) = 0; 33 34 protected: ~JsController()35 virtual ~JsController() {} 36 }; 37 38 } // namespace syncer 39 40 #endif // COMPONENTS_SYNC_JS_JS_CONTROLLER_H_ 41