buffet: Move global instance of CommandManager to buffet::Manager
Removed the global static instance of CommandManager and
transferred ownership of this global instance to buffet::Manager
class.
BUG=None
TEST=USE=buffet P2_TEST_FILTER="buffet::*" FEATURES=test emerge-link platform2
Change-Id: If1b4875d3c26f146bc4f454bb0aaaaf8b17a0c72
Reviewed-on: https://chromium-review.googlesource.com/209563
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/command_manager.cc b/buffet/commands/command_manager.cc
index 26c0b9f..8c54e51 100644
--- a/buffet/commands/command_manager.cc
+++ b/buffet/commands/command_manager.cc
@@ -4,8 +4,6 @@
#include "buffet/commands/command_manager.h"
-#include <base/at_exit.h>
-#include <base/bind.h>
#include <base/file_util.h>
#include <base/files/file_enumerator.h>
#include <base/json/json_reader.h>
@@ -16,8 +14,6 @@
namespace buffet {
-CommandManager* CommandManager::instance_ = nullptr;
-
const CommandDictionary& CommandManager::GetCommandDictionary() const {
return dictionary_;
}
@@ -52,20 +48,12 @@
return LoadCommands(*json, category, error);
}
-CommandManager* CommandManager::GetInstance() {
- CHECK(instance_) << "CommandManager instance not initialized.";
- return instance_;
-}
-
void CommandManager::Startup() {
- CHECK(!instance_) << "CommandManager instance already initialized.";
LOG(INFO) << "Initializing CommandManager.";
- std::unique_ptr<CommandManager> inst(new CommandManager);
-
// Load global standard GCD command dictionary.
base::FilePath base_command_file("/etc/buffet/gcd.json");
LOG(INFO) << "Loading standard commands from " << base_command_file.value();
- CHECK(inst->LoadBaseCommands(base_command_file, nullptr))
+ CHECK(LoadBaseCommands(base_command_file, nullptr))
<< "Failed to load the standard command definitions.";
// Load static device command definitions.
@@ -76,23 +64,10 @@
base::FilePath json_file_path = enumerator.Next();
while (!json_file_path.empty()) {
LOG(INFO) << "Loading command schema from " << json_file_path.value();
- CHECK(inst->LoadCommands(json_file_path, nullptr))
+ CHECK(LoadCommands(json_file_path, nullptr))
<< "Failed to load the command definition file.";
json_file_path = enumerator.Next();
}
-
- // Register a cleanup callback to be executed at shut-down.
- base::AtExitManager::RegisterTask(base::Bind(&CommandManager::Shutdown));
- // Transfer the object instance pointer from the smart pointer to
- // the global pointer.
- instance_ = inst.release();
-}
-
-void CommandManager::Shutdown() {
- CHECK(instance_) << "CommandManager instance not initialized.";
- LOG(INFO) << "Shutting down CommandManager.";
- delete instance_;
- instance_ = nullptr;
}
std::unique_ptr<const base::DictionaryValue> CommandManager::LoadJsonDict(
diff --git a/buffet/commands/command_manager.h b/buffet/commands/command_manager.h
index 02d92fd..1199892 100644
--- a/buffet/commands/command_manager.h
+++ b/buffet/commands/command_manager.h
@@ -52,13 +52,11 @@
bool LoadCommands(const base::FilePath& json_file_path,
ErrorPtr* error);
- // Factory static method to get the global singleton instance of the object.
- static CommandManager* GetInstance();
- // Global startup method to be called by buffet daemon at startup.
- // Initializes the global object singleton and loads the standard GCD command
+ // Startup method to be called by buffet daemon at startup.
+ // Initializes the object and loads the standard GCD command
// dictionary as well as static vendor-provided command definitions for
// the current device.
- static void Startup();
+ void Startup();
private:
// Helper function to load a JSON file that is expected to be
@@ -66,14 +64,10 @@
// in error details in |error|.
std::unique_ptr<const base::DictionaryValue> LoadJsonDict(
const base::FilePath& json_file_path, ErrorPtr* error);
- // Helper method to be called at buffet shutdown to clean up the global
- // singleton instance of this class.
- static void Shutdown();
CommandDictionary base_dictionary_; // Base/std command definitions/schemas.
CommandDictionary dictionary_; // Command definitions/schemas.
- static CommandManager* instance_; // Global singleton instance of the object.
DISALLOW_COPY_AND_ASSIGN(CommandManager);
};