| 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 SYNC_JS_JS_CONTROLLER_H_ | 5 #ifndef SYNC_JS_JS_CONTROLLER_H_ |
| 6 #define SYNC_JS_JS_CONTROLLER_H_ | 6 #define 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 #include "sync/base/sync_export.h" | 12 #include "sync/base/sync_export.h" |
| 13 | 13 |
| 14 namespace syncer { | 14 namespace syncer { |
| 15 | 15 |
| 16 class JsArgList; | |
| 17 class JsEventHandler; | 16 class JsEventHandler; |
| 18 class JsReplyHandler; | |
| 19 template <typename T> class WeakHandle; | 17 template <typename T> class WeakHandle; |
| 20 | 18 |
| 21 // An interface for objects that JsEventHandlers directly interact | 19 // An interface for objects that JsEventHandlers directly interact |
| 22 // with. JsEventHandlers can add themselves to receive events and | 20 // with. JsEventHandlers can add themselves to receive events and |
| 23 // also send messages which will eventually reach the backend. | 21 // also send messages which will eventually reach the backend. |
| 24 class SYNC_EXPORT JsController { | 22 class SYNC_EXPORT JsController { |
| 25 public: | 23 public: |
| 26 // Adds an event handler which will start receiving JS events (not | 24 // Adds an event handler which will start receiving JS events (not |
| 27 // immediately, so this can be called in the handler's constructor). | 25 // immediately, so this can be called in the handler's constructor). |
| 28 // Multiple event handlers are supported, but each event handler | 26 // Multiple event handlers are supported, but each event handler |
| 29 // must be added at most once. | 27 // must be added at most once. |
| 30 // | 28 // |
| 31 // Ideally, we'd take WeakPtrs, but we need the raw pointer values | 29 // Ideally, we'd take WeakPtrs, but we need the raw pointer values |
| 32 // to be able to look them up for removal. | 30 // to be able to look them up for removal. |
| 33 virtual void AddJsEventHandler(JsEventHandler* event_handler) = 0; | 31 virtual void AddJsEventHandler(JsEventHandler* event_handler) = 0; |
| 34 | 32 |
| 35 // Removes the given event handler if it has been added. It will | 33 // Removes the given event handler if it has been added. It will |
| 36 // immediately stop receiving any JS events. | 34 // immediately stop receiving any JS events. |
| 37 virtual void RemoveJsEventHandler(JsEventHandler* event_handler) = 0; | 35 virtual void RemoveJsEventHandler(JsEventHandler* event_handler) = 0; |
| 38 | 36 |
| 39 // Processes a JS message. The reply (if any) will be sent to | |
| 40 // |reply_handler| if it is initialized. | |
| 41 virtual void ProcessJsMessage( | |
| 42 const std::string& name, const JsArgList& args, | |
| 43 const WeakHandle<JsReplyHandler>& reply_handler) = 0; | |
| 44 | |
| 45 protected: | 37 protected: |
| 46 virtual ~JsController() {} | 38 virtual ~JsController() {} |
| 47 }; | 39 }; |
| 48 | 40 |
| 49 } // namespace syncer | 41 } // namespace syncer |
| 50 | 42 |
| 51 #endif // SYNC_JS_JS_CONTROLLER_H_ | 43 #endif // SYNC_JS_JS_CONTROLLER_H_ |
| OLD | NEW |