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

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

Issue 2613713005: Make ToolbarActionsModel own ComponentToolbarActionsFactory (Closed)
Patch Set: Fix buildbot failure Created 3 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_COMPONENT_TOOLBAR_ACTIONS_FACTORY_H_ 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_COMPONENT_TOOLBAR_ACTIONS_FACTORY_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_COMPONENT_TOOLBAR_ACTIONS_FACTORY_H_ 6 #define CHROME_BROWSER_UI_TOOLBAR_COMPONENT_TOOLBAR_ACTIONS_FACTORY_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
14 13
15 class Browser; 14 class Browser;
16 class ExtensionService; 15 class ExtensionService;
17 class Profile; 16 class Profile;
17 class ToolbarActionsBar;
18 class ToolbarActionViewController; 18 class ToolbarActionViewController;
19 19
20 namespace extensions { 20 namespace extensions {
21 class ExtensionRegistry; 21 class ExtensionRegistry;
22 } 22 }
23 23
24 // The registry for all component toolbar actions. Component toolbar actions 24 // The registry for all component toolbar actions. Component toolbar actions
25 // are actions that live in the toolbar (like extension actions), but are 25 // are actions that live in the toolbar (like extension actions), but are for
26 // components of chrome, such as ChromeCast. 26 // components of Chrome, such as Media Router.
27 class ComponentToolbarActionsFactory { 27 class ComponentToolbarActionsFactory {
28 public: 28 public:
29 // Extension and component action IDs. 29 // Extension and component action IDs.
30 static const char kCastBetaExtensionId[]; 30 static const char kCastBetaExtensionId[];
31 static const char kCastExtensionId[]; 31 static const char kCastExtensionId[];
32 static const char kMediaRouterActionId[]; 32 static const char kMediaRouterActionId[];
33 33
34 ComponentToolbarActionsFactory(); 34 explicit ComponentToolbarActionsFactory(Profile* profile);
35 virtual ~ComponentToolbarActionsFactory(); 35 virtual ~ComponentToolbarActionsFactory();
36 36
37 static ComponentToolbarActionsFactory* GetInstance(); 37 // Returns a set of IDs of the component actions that should be present when
38 // the toolbar model is initialized.
39 virtual std::set<std::string> GetInitialComponentIds();
38 40
39 // Returns a vector of IDs of the component actions. 41 // Called when component actions are added or removed before the toolbar model
40 virtual std::set<std::string> GetInitialComponentIds(Profile* profile); 42 // is initialized. Adds or removes |action_id| to/from |initial_ids_| as
43 // necessary.
44 void OnAddComponentActionBeforeInit(const std::string& action_id);
45 void OnRemoveComponentActionBeforeInit(const std::string& action_id);
41 46
42 // Returns a collection of controllers for component actions. Declared 47 // Returns the controller responsible for the component action associated with
43 // virtual for testing. 48 // |action_id| in |bar|. Declared virtual for testing.
44 virtual std::unique_ptr<ToolbarActionViewController> 49 virtual std::unique_ptr<ToolbarActionViewController>
45 GetComponentToolbarActionForId(const std::string& id, 50 GetComponentToolbarActionForId(const std::string& action_id,
46 Browser* browser, 51 Browser* browser,
47 ToolbarActionsBar* bar); 52 ToolbarActionsBar* bar);
48 53
49 // Unloads extensions that were migrated to component actions and therefore 54 // Unloads extensions that were migrated to component actions and therefore
50 // are no longer needed. 55 // are no longer needed.
51 void UnloadMigratedExtensions(ExtensionService* service, 56 void UnloadMigratedExtensions(ExtensionService* service,
52 extensions::ExtensionRegistry* registry); 57 extensions::ExtensionRegistry* registry);
53 58
54 // Sets the factory to use for testing purposes.
55 // Ownership remains with the caller.
56 static void SetTestingFactory(ComponentToolbarActionsFactory* factory);
57
58 private: 59 private:
59 // Unloads an extension if it is active. 60 // Unloads an extension if it is active.
60 void UnloadExtension(ExtensionService* service, 61 void UnloadExtension(ExtensionService* service,
61 extensions::ExtensionRegistry* registry, 62 extensions::ExtensionRegistry* registry,
62 const std::string& extension_id); 63 const std::string& extension_id);
63 64
65 Profile* profile_;
66
67 // IDs of component actions that should be added to the toolbar model when it
68 // gets initialized.
69 std::set<std::string> initial_ids_;
70
64 DISALLOW_COPY_AND_ASSIGN(ComponentToolbarActionsFactory); 71 DISALLOW_COPY_AND_ASSIGN(ComponentToolbarActionsFactory);
65 }; 72 };
66 73
67 #endif // CHROME_BROWSER_UI_TOOLBAR_COMPONENT_TOOLBAR_ACTIONS_FACTORY_H_ 74 #endif // CHROME_BROWSER_UI_TOOLBAR_COMPONENT_TOOLBAR_ACTIONS_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698