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

Side by Side Diff: components/webui_generator/web_ui_view.h

Issue 1038003002: Use variadic template for screen handler's AddCallback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « components/login/base_screen_handler_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 CHROME_BROWSER_UI_WEBUI_WUG_WEB_UI_VIEW_H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_WUG_WEB_UI_VIEW_H_
6 #define CHROME_BROWSER_UI_WEBUI_WUG_WEB_UI_VIEW_H_ 6 #define CHROME_BROWSER_UI_WEBUI_WUG_WEB_UI_VIEW_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // Overridden from View: 52 // Overridden from View:
53 void Init() override; 53 void Init() override;
54 54
55 protected: 55 protected:
56 using ResourcesMap = 56 using ResourcesMap =
57 base::hash_map<std::string, scoped_refptr<base::RefCountedMemory>>; 57 base::hash_map<std::string, scoped_refptr<base::RefCountedMemory>>;
58 58
59 content::WebUI* web_ui() { return web_ui_; } 59 content::WebUI* web_ui() { return web_ui_; }
60 60
61 template <typename T> 61 template <typename T, typename... Args>
62 void AddCallback(const std::string& name, void (T::*method)()) { 62 void AddCallback(const std::string& name, void (T::*method)(Args...)) {
63 base::Callback<void()> callback = 63 base::Callback<void(Args...)> callback =
64 base::Bind(method, base::Unretained(static_cast<T*>(this))); 64 base::Bind(method, base::Unretained(static_cast<T*>(this)));
65 web_ui_->RegisterMessageCallback( 65 web_ui_->RegisterMessageCallback(
66 name, base::Bind(&::login::CallbackWrapper0, callback)); 66 name, base::Bind(&::login::CallbackWrapper<Args...>, callback));
67 }
68
69 template <typename T, typename A1>
70 void AddCallback(const std::string& name, void (T::*method)(A1 arg1)) {
71 base::Callback<void(A1)> callback =
72 base::Bind(method, base::Unretained(static_cast<T*>(this)));
73 web_ui_->RegisterMessageCallback(
74 name, base::Bind(&::login::CallbackWrapper1<A1>, callback));
75 } 67 }
76 68
77 // Overridden from View: 69 // Overridden from View:
78 void OnReady() override; 70 void OnReady() override;
79 void OnContextChanged(const base::DictionaryValue& diff) override; 71 void OnContextChanged(const base::DictionaryValue& diff) override;
80 72
81 virtual void AddLocalizedValues(::login::LocalizedValuesBuilder* builder) = 0; 73 virtual void AddLocalizedValues(::login::LocalizedValuesBuilder* builder) = 0;
82 virtual void AddResources(ResourcesMap* resources_map) = 0; 74 virtual void AddResources(ResourcesMap* resources_map) = 0;
83 75
84 private: 76 private:
(...skipping 22 matching lines...) Expand all
107 bool html_ready_; 99 bool html_ready_;
108 bool view_bound_; 100 bool view_bound_;
109 scoped_ptr<Context> pending_context_changes_; 101 scoped_ptr<Context> pending_context_changes_;
110 102
111 DISALLOW_COPY_AND_ASSIGN(WebUIView); 103 DISALLOW_COPY_AND_ASSIGN(WebUIView);
112 }; 104 };
113 105
114 } // namespace webui_generator 106 } // namespace webui_generator
115 107
116 #endif // CHROME_BROWSER_UI_WEBUI_WUG_WEB_UI_VIEW_H_ 108 #endif // CHROME_BROWSER_UI_WEBUI_WUG_WEB_UI_VIEW_H_
OLDNEW
« no previous file with comments | « components/login/base_screen_handler_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698