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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_actions_model.h

Issue 2613713005: Make ToolbarActionsModel own ComponentToolbarActionsFactory (Closed)
Patch Set: Created 3 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_ 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_ 6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "base/scoped_observer.h" 13 #include "base/scoped_observer.h"
14 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 14 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
15 #include "chrome/browser/extensions/component_migration_helper.h" 15 #include "chrome/browser/extensions/component_migration_helper.h"
msw 2017/01/10 23:23:59 nit: remove this include and use a forward declara
takumif 2017/02/17 03:22:52 Done.
16 #include "chrome/browser/extensions/extension_action.h" 16 #include "chrome/browser/extensions/extension_action.h"
17 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
17 #include "components/keyed_service/core/keyed_service.h" 18 #include "components/keyed_service/core/keyed_service.h"
18 #include "components/prefs/pref_change_registrar.h" 19 #include "components/prefs/pref_change_registrar.h"
19 #include "extensions/browser/extension_prefs.h" 20 #include "extensions/browser/extension_prefs.h"
20 #include "extensions/browser/extension_registry_observer.h" 21 #include "extensions/browser/extension_registry_observer.h"
21 #include "extensions/common/extension.h" 22 #include "extensions/common/extension.h"
22 23
23 class Browser; 24 class Browser;
24 class PrefService; 25 class PrefService;
25 class Profile; 26 class Profile;
26 class ToolbarActionsBar; 27 class ToolbarActionsBar;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 void RemoveObserver(Observer* observer); 127 void RemoveObserver(Observer* observer);
127 128
128 // Moves the given action with |id|'s icon to the given |index|. 129 // Moves the given action with |id|'s icon to the given |index|.
129 void MoveActionIcon(const std::string& id, size_t index); 130 void MoveActionIcon(const std::string& id, size_t index);
130 131
131 // Sets the number of action icons that should be visible. 132 // Sets the number of action icons that should be visible.
132 // If count == size(), this will set the visible icon count to -1, meaning 133 // If count == size(), this will set the visible icon count to -1, meaning
133 // "show all actions". 134 // "show all actions".
134 void SetVisibleIconCount(size_t count); 135 void SetVisibleIconCount(size_t count);
135 136
137 extensions::ComponentMigrationHelper* GetComponentMigrationHelper();
msw 2017/01/10 23:23:59 Is this necessary if the ComponentToolbarActionsFa
takumif 2017/02/17 03:22:52 Removed migration-related code.
138
136 // Note that this (and all_icons_visible()) are the global default, but are 139 // Note that this (and all_icons_visible()) are the global default, but are
137 // inappropriate for determining a specific window's state - for that, use 140 // inappropriate for determining a specific window's state - for that, use
138 // the ToolbarActionsBar. 141 // the ToolbarActionsBar.
139 size_t visible_icon_count() const { 142 size_t visible_icon_count() const {
140 // We have guards around this because |visible_icon_count_| can be set by 143 // We have guards around this because |visible_icon_count_| can be set by
141 // prefs/sync, and we want to ensure that the icon count returned is within 144 // prefs/sync, and we want to ensure that the icon count returned is within
142 // bounds. 145 // bounds.
143 return visible_icon_count_ == -1 146 return visible_icon_count_ == -1
144 ? toolbar_items().size() 147 ? toolbar_items().size()
145 : std::min(static_cast<size_t>(visible_icon_count_), 148 : std::min(static_cast<size_t>(visible_icon_count_),
(...skipping 10 matching lines...) Expand all
156 ToolbarActionsBar* bar); 159 ToolbarActionsBar* bar);
157 std::unique_ptr<ToolbarActionViewController> CreateActionForItem( 160 std::unique_ptr<ToolbarActionViewController> CreateActionForItem(
158 Browser* browser, 161 Browser* browser,
159 ToolbarActionsBar* bar, 162 ToolbarActionsBar* bar,
160 const ToolbarItem& item); 163 const ToolbarItem& item);
161 164
162 const std::vector<ToolbarItem>& toolbar_items() const { 165 const std::vector<ToolbarItem>& toolbar_items() const {
163 return is_highlighting() ? highlighted_items_ : toolbar_items_; 166 return is_highlighting() ? highlighted_items_ : toolbar_items_;
164 } 167 }
165 168
166 extensions::ComponentMigrationHelper* component_migration_helper() {
167 return component_migration_helper_.get();
168 }
169
170 bool is_highlighting() const { return highlight_type_ != HIGHLIGHT_NONE; } 169 bool is_highlighting() const { return highlight_type_ != HIGHLIGHT_NONE; }
171 HighlightType highlight_type() const { return highlight_type_; } 170 HighlightType highlight_type() const { return highlight_type_; }
172 171
173 bool has_active_bubble() const { return has_active_bubble_; } 172 bool has_active_bubble() const { return has_active_bubble_; }
174 void set_has_active_bubble(bool has_active_bubble) { 173 void set_has_active_bubble(bool has_active_bubble) {
175 has_active_bubble_ = has_active_bubble; 174 has_active_bubble_ = has_active_bubble;
176 } 175 }
177 176
177 ComponentToolbarActionsFactory* component_actions_factory() {
178 return component_actions_factory_.get();
179 }
180
178 void SetActionVisibility(const std::string& action_id, bool visible); 181 void SetActionVisibility(const std::string& action_id, bool visible);
179 182
180 // ComponentMigrationHelper::ComponentActionDelegate: 183 // ComponentMigrationHelper::ComponentActionDelegate:
181 // AddComponentAction() is a no-op if |actions_initialized_| is false. 184 // AddComponentAction() is a no-op if |actions_initialized_| is false.
182 void AddComponentAction(const std::string& action_id) override; 185 void AddComponentAction(const std::string& action_id) override;
183 void RemoveComponentAction(const std::string& action_id) override; 186 void RemoveComponentAction(const std::string& action_id) override;
184 bool HasComponentAction(const std::string& action_id) const override; 187 bool HasComponentAction(const std::string& action_id) const override;
185 188
186 void OnActionToolbarPrefChange(); 189 void OnActionToolbarPrefChange();
187 190
188 // Highlights the actions specified by |action_ids|. This will cause 191 // Highlights the actions specified by |action_ids|. This will cause
189 // the ToolbarModel to only display those actions. 192 // the ToolbarModel to only display those actions.
190 // Highlighting mode is only entered if there is at least one action to be 193 // Highlighting mode is only entered if there is at least one action to be
191 // shown. 194 // shown.
192 // Returns true if highlighting mode is entered, false otherwise. 195 // Returns true if highlighting mode is entered, false otherwise.
193 bool HighlightActions(const std::vector<std::string>& action_ids, 196 bool HighlightActions(const std::vector<std::string>& action_ids,
194 HighlightType type); 197 HighlightType type);
195 198
196 // Stop highlighting actions. All actions can be shown again, and the 199 // Stop highlighting actions. All actions can be shown again, and the
197 // number of visible icons will be reset to what it was before highlighting. 200 // number of visible icons will be reset to what it was before highlighting.
198 void StopHighlighting(); 201 void StopHighlighting();
199 202
200 // Gets the ExtensionMessageBubbleController that should be shown for this 203 // Gets the ExtensionMessageBubbleController that should be shown for this
201 // profile, if any. 204 // profile, if any.
202 std::unique_ptr<extensions::ExtensionMessageBubbleController> 205 std::unique_ptr<extensions::ExtensionMessageBubbleController>
203 GetExtensionMessageBubbleController(Browser* browser); 206 GetExtensionMessageBubbleController(Browser* browser);
204 207
208 // Swaps |component_actions_factory_| with |mock_factory|. The ownership of
msw 2017/01/10 23:23:59 nit: s/Swaps/Replaces/ or something like: "Set the
takumif 2017/02/17 03:22:51 Done.
209 // |mock_factory| is transferred to |this|.
Devlin 2017/01/10 23:07:11 if ownership is transferred, use a unique_ptr (and
takumif 2017/02/17 03:22:51 Done.
210 void SetMockActionsFactory(ComponentToolbarActionsFactory* mock_factory);
msw 2017/01/10 23:23:59 nit: append ForTest[ing] to function name (or remo
msw 2017/01/10 23:23:59 Ownership transfers should usually be done with un
takumif 2017/02/17 03:22:52 Done.
takumif 2017/02/17 03:22:52 Done.
211
205 private: 212 private:
206 // Callback when actions are ready. 213 // Callback when actions are ready.
207 void OnReady(); 214 void OnReady();
208 215
209 // ExtensionRegistryObserver: 216 // ExtensionRegistryObserver:
210 void OnExtensionLoaded(content::BrowserContext* browser_context, 217 void OnExtensionLoaded(content::BrowserContext* browser_context,
211 const extensions::Extension* extension) override; 218 const extensions::Extension* extension) override;
212 void OnExtensionUnloaded( 219 void OnExtensionUnloaded(
213 content::BrowserContext* browser_context, 220 content::BrowserContext* browser_context,
214 const extensions::Extension* extension, 221 const extensions::Extension* extension,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 291
285 // The ExtensionActionAPI object, cached for convenience. 292 // The ExtensionActionAPI object, cached for convenience.
286 extensions::ExtensionActionAPI* extension_action_api_; 293 extensions::ExtensionActionAPI* extension_action_api_;
287 294
288 // The ExtensionRegistry object, cached for convenience. 295 // The ExtensionRegistry object, cached for convenience.
289 extensions::ExtensionRegistry* extension_registry_; 296 extensions::ExtensionRegistry* extension_registry_;
290 297
291 // The ExtensionActionManager, cached for convenience. 298 // The ExtensionActionManager, cached for convenience.
292 extensions::ExtensionActionManager* extension_action_manager_; 299 extensions::ExtensionActionManager* extension_action_manager_;
293 300
294 // The ComponentMigrationHelper. 301 std::unique_ptr<ComponentToolbarActionsFactory> component_actions_factory_;
295 std::unique_ptr<extensions::ComponentMigrationHelper>
296 component_migration_helper_;
297 302
298 // True if we've handled the initial EXTENSIONS_READY notification. 303 // True if we've handled the initial EXTENSIONS_READY notification.
299 bool actions_initialized_; 304 bool actions_initialized_;
300 305
301 // If true, we include all actions in the toolbar model. 306 // If true, we include all actions in the toolbar model.
302 bool use_redesign_; 307 bool use_redesign_;
303 308
304 // Ordered list of browser actions. 309 // Ordered list of browser actions.
305 std::vector<ToolbarItem> toolbar_items_; 310 std::vector<ToolbarItem> toolbar_items_;
306 311
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // For observing change of toolbar order preference by external entity (sync). 343 // For observing change of toolbar order preference by external entity (sync).
339 PrefChangeRegistrar pref_change_registrar_; 344 PrefChangeRegistrar pref_change_registrar_;
340 base::Closure pref_change_callback_; 345 base::Closure pref_change_callback_;
341 346
342 base::WeakPtrFactory<ToolbarActionsModel> weak_ptr_factory_; 347 base::WeakPtrFactory<ToolbarActionsModel> weak_ptr_factory_;
343 348
344 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsModel); 349 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsModel);
345 }; 350 };
346 351
347 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_ 352 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698