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

Side by Side Diff: chrome/browser/command_updater.cc

Issue 10677009: Move command handling and updating off Browser and onto a helper object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 | « chrome/browser/command_updater.h ('k') | chrome/browser/command_updater_unittest.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 (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 #include "chrome/browser/command_updater.h" 5 #include "chrome/browser/command_updater.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "chrome/browser/command_observer.h"
12 13
13 CommandUpdater::CommandUpdaterDelegate::~CommandUpdaterDelegate() { 14 CommandUpdater::CommandUpdaterDelegate::~CommandUpdaterDelegate() {
14 } 15 }
15 16
16 class CommandUpdater::Command { 17 class CommandUpdater::Command {
17 public: 18 public:
18 bool enabled; 19 bool enabled;
19 ObserverList<CommandObserver> observers; 20 ObserverList<CommandObserver> observers;
20 21
21 Command() : enabled(true) {} 22 Command() : enabled(true) {}
(...skipping 11 matching lines...) Expand all
33 const CommandMap::const_iterator command(commands_.find(id)); 34 const CommandMap::const_iterator command(commands_.find(id));
34 if (command == commands_.end()) 35 if (command == commands_.end())
35 return false; 36 return false;
36 return command->second->enabled; 37 return command->second->enabled;
37 } 38 }
38 39
39 bool CommandUpdater::SupportsCommand(int id) const { 40 bool CommandUpdater::SupportsCommand(int id) const {
40 return commands_.find(id) != commands_.end(); 41 return commands_.find(id) != commands_.end();
41 } 42 }
42 43
43 void CommandUpdater::ExecuteCommand(int id) { 44 bool CommandUpdater::ExecuteCommand(int id) {
44 ExecuteCommandWithDisposition(id, CURRENT_TAB); 45 return ExecuteCommandWithDisposition(id, CURRENT_TAB);
45 } 46 }
46 47
47 void CommandUpdater::ExecuteCommandWithDisposition( 48 bool CommandUpdater::ExecuteCommandWithDisposition(
48 int id, 49 int id,
49 WindowOpenDisposition disposition) { 50 WindowOpenDisposition disposition) {
50 if (IsCommandEnabled(id)) 51 if (SupportsCommand(id) && IsCommandEnabled(id)) {
51 delegate_->ExecuteCommandWithDisposition(id, disposition); 52 delegate_->ExecuteCommandWithDisposition(id, disposition);
53 return true;
54 }
55 return false;
52 } 56 }
53 57
54 CommandUpdater::CommandObserver::~CommandObserver() { 58 CommandObserver::~CommandObserver() {
55 } 59 }
56 60
57 void CommandUpdater::UpdateCommandEnabled(int id, bool enabled) { 61 void CommandUpdater::UpdateCommandEnabled(int id, bool enabled) {
58 Command* command = GetCommand(id, true); 62 Command* command = GetCommand(id, true);
59 if (command->enabled == enabled) 63 if (command->enabled == enabled)
60 return; // Nothing to do. 64 return; // Nothing to do.
61 command->enabled = enabled; 65 command->enabled = enabled;
62 FOR_EACH_OBSERVER(CommandObserver, command->observers, 66 FOR_EACH_OBSERVER(CommandObserver, command->observers,
63 EnabledStateChangedForCommand(id, enabled)); 67 EnabledStateChangedForCommand(id, enabled));
64 } 68 }
(...skipping 18 matching lines...) Expand all
83 87
84 void CommandUpdater::RemoveCommandObserver(CommandObserver* observer) { 88 void CommandUpdater::RemoveCommandObserver(CommandObserver* observer) {
85 for (CommandMap::const_iterator it = commands_.begin(); 89 for (CommandMap::const_iterator it = commands_.begin();
86 it != commands_.end(); 90 it != commands_.end();
87 ++it) { 91 ++it) {
88 Command* command = it->second; 92 Command* command = it->second;
89 if (command) 93 if (command)
90 command->observers.RemoveObserver(observer); 94 command->observers.RemoveObserver(observer);
91 } 95 }
92 } 96 }
OLDNEW
« no previous file with comments | « chrome/browser/command_updater.h ('k') | chrome/browser/command_updater_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698