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