Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: sync/js/sync_js_controller.h

Issue 231013003: Remove Sync JS generic request/reply framework (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove js_reply_handler.h from gyp Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/js/js_test_util.cc ('k') | sync/js/sync_js_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_SYNC_JS_CONTROLLER_H_ 5 #ifndef SYNC_JS_SYNC_JS_CONTROLLER_H_
6 #define SYNC_JS_SYNC_JS_CONTROLLER_H_ 6 #define SYNC_JS_SYNC_JS_CONTROLLER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "sync/base/sync_export.h" 15 #include "sync/base/sync_export.h"
16 #include "sync/internal_api/public/util/weak_handle.h" 16 #include "sync/internal_api/public/util/weak_handle.h"
17 #include "sync/js/js_arg_list.h"
18 #include "sync/js/js_controller.h" 17 #include "sync/js/js_controller.h"
19 #include "sync/js/js_event_handler.h" 18 #include "sync/js/js_event_handler.h"
20 19
21 namespace syncer { 20 namespace syncer {
22 21
23 class JsBackend; 22 class JsBackend;
24 23
25 // A class that mediates between the sync JsEventHandlers and the sync 24 // A class that mediates between the sync JsEventHandlers and the sync
26 // JsBackend. 25 // JsBackend.
27 class SYNC_EXPORT SyncJsController 26 class SYNC_EXPORT SyncJsController
28 : public JsController, public JsEventHandler, 27 : public JsController, public JsEventHandler,
29 public base::SupportsWeakPtr<SyncJsController> { 28 public base::SupportsWeakPtr<SyncJsController> {
30 public: 29 public:
31 SyncJsController(); 30 SyncJsController();
32 31
33 virtual ~SyncJsController(); 32 virtual ~SyncJsController();
34 33
35 // Sets the backend to route all messages to (if initialized). 34 // Sets the backend to route all messages to (if initialized).
36 // Sends any queued-up messages if |backend| is initialized. 35 // Sends any queued-up messages if |backend| is initialized.
37 void AttachJsBackend(const WeakHandle<JsBackend>& js_backend); 36 void AttachJsBackend(const WeakHandle<JsBackend>& js_backend);
38 37
39 // JsController implementation. 38 // JsController implementation.
40 virtual void AddJsEventHandler(JsEventHandler* event_handler) OVERRIDE; 39 virtual void AddJsEventHandler(JsEventHandler* event_handler) OVERRIDE;
41 virtual void RemoveJsEventHandler(JsEventHandler* event_handler) OVERRIDE; 40 virtual void RemoveJsEventHandler(JsEventHandler* event_handler) OVERRIDE;
42 // Queues up any messages that are sent when there is no attached
43 // initialized backend.
44 virtual void ProcessJsMessage(
45 const std::string& name, const JsArgList& args,
46 const WeakHandle<JsReplyHandler>& reply_handler) OVERRIDE;
47 41
48 // JsEventHandler implementation. 42 // JsEventHandler implementation.
49 virtual void HandleJsEvent(const std::string& name, 43 virtual void HandleJsEvent(const std::string& name,
50 const JsEventDetails& details) OVERRIDE; 44 const JsEventDetails& details) OVERRIDE;
51 45
52 private: 46 private:
53 // A struct used to hold the arguments to ProcessJsMessage() for
54 // future invocation.
55 struct PendingJsMessage {
56 std::string name;
57 JsArgList args;
58 WeakHandle<JsReplyHandler> reply_handler;
59
60 PendingJsMessage(const std::string& name, const JsArgList& args,
61 const WeakHandle<JsReplyHandler>& reply_handler);
62
63 ~PendingJsMessage();
64 };
65
66 typedef std::vector<PendingJsMessage> PendingJsMessageList;
67
68 // Sets |js_backend_|'s event handler depending on how many 47 // Sets |js_backend_|'s event handler depending on how many
69 // underlying event handlers we have. 48 // underlying event handlers we have.
70 void UpdateBackendEventHandler(); 49 void UpdateBackendEventHandler();
71 50
72 WeakHandle<JsBackend> js_backend_; 51 WeakHandle<JsBackend> js_backend_;
73 ObserverList<JsEventHandler> js_event_handlers_; 52 ObserverList<JsEventHandler> js_event_handlers_;
74 PendingJsMessageList pending_js_messages_;
75 53
76 DISALLOW_COPY_AND_ASSIGN(SyncJsController); 54 DISALLOW_COPY_AND_ASSIGN(SyncJsController);
77 }; 55 };
78 56
79 } // namespace syncer 57 } // namespace syncer
80 58
81 #endif // SYNC_JS_SYNC_JS_CONTROLLER_H_ 59 #endif // SYNC_JS_SYNC_JS_CONTROLLER_H_
OLDNEW
« no previous file with comments | « sync/js/js_test_util.cc ('k') | sync/js/sync_js_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698