Commit 7317302b authored by thestig@chromium.org's avatar thestig@chromium.org

Cleanup: Simplify system_info_api.cc.

Review URL: https://codereview.chromium.org/140513004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245485 0039d316-1c4b-4281-b951-d872f2087c98
parent b10a7d87
...@@ -37,9 +37,11 @@ namespace system_storage = api::system_storage; ...@@ -37,9 +37,11 @@ namespace system_storage = api::system_storage;
namespace { namespace {
#if defined(USE_ASH)
bool IsDisplayChangedEvent(const std::string& event_name) { bool IsDisplayChangedEvent(const std::string& event_name) {
return event_name == system_display::OnDisplayChanged::kEventName; return event_name == system_display::OnDisplayChanged::kEventName;
} }
#endif
// Event router for systemInfo API. It is a singleton instance shared by // Event router for systemInfo API. It is a singleton instance shared by
// multiple profiles. // multiple profiles.
...@@ -105,11 +107,10 @@ void SystemInfoEventRouter::AddEventListener(const std::string& event_name) { ...@@ -105,11 +107,10 @@ void SystemInfoEventRouter::AddEventListener(const std::string& event_name) {
return; return;
// For systemInfo.display event. // For systemInfo.display event.
if (IsDisplayChangedEvent(event_name)) {
#if defined(USE_ASH) #if defined(USE_ASH)
if (IsDisplayChangedEvent(event_name))
ash::Shell::GetScreen()->AddObserver(this); ash::Shell::GetScreen()->AddObserver(this);
#endif #endif
}
} }
void SystemInfoEventRouter::RemoveEventListener( void SystemInfoEventRouter::RemoveEventListener(
...@@ -118,17 +119,16 @@ void SystemInfoEventRouter::RemoveEventListener( ...@@ -118,17 +119,16 @@ void SystemInfoEventRouter::RemoveEventListener(
std::multiset<std::string>::iterator it = std::multiset<std::string>::iterator it =
watching_event_set_.find(event_name); watching_event_set_.find(event_name);
if (it != watching_event_set_.end()) if (it != watching_event_set_.end()) {
watching_event_set_.erase(it); watching_event_set_.erase(it);
if (watching_event_set_.count(event_name) > 0) if (watching_event_set_.count(event_name) > 0)
return; return;
}
if (IsDisplayChangedEvent(event_name)) {
#if defined(USE_ASH) #if defined(USE_ASH)
if (IsDisplayChangedEvent(event_name))
ash::Shell::GetScreen()->RemoveObserver(this); ash::Shell::GetScreen()->RemoveObserver(this);
#endif #endif
}
} }
void SystemInfoEventRouter::OnRemovableStorageAttached( void SystemInfoEventRouter::OnRemovableStorageAttached(
...@@ -143,8 +143,10 @@ void SystemInfoEventRouter::OnRemovableStorageAttached( ...@@ -143,8 +143,10 @@ void SystemInfoEventRouter::OnRemovableStorageAttached(
void SystemInfoEventRouter::OnRemovableStorageDetached( void SystemInfoEventRouter::OnRemovableStorageDetached(
const StorageInfo& info) { const StorageInfo& info) {
scoped_ptr<base::ListValue> args(new base::ListValue); scoped_ptr<base::ListValue> args(new base::ListValue);
args->Append(new base::StringValue(StorageMonitor::GetInstance()-> std::string transient_id =
GetTransientIdForDeviceId(info.device_id()))); StorageMonitor::GetInstance()->GetTransientIdForDeviceId(
info.device_id());
args->AppendString(transient_id);
DispatchEvent(system_storage::OnDetached::kEventName, args.Pass()); DispatchEvent(system_storage::OnDetached::kEventName, args.Pass());
} }
...@@ -180,16 +182,14 @@ static base::LazyInstance<ProfileKeyedAPIFactory<SystemInfoAPI> > ...@@ -180,16 +182,14 @@ static base::LazyInstance<ProfileKeyedAPIFactory<SystemInfoAPI> >
// static // static
ProfileKeyedAPIFactory<SystemInfoAPI>* SystemInfoAPI::GetFactoryInstance() { ProfileKeyedAPIFactory<SystemInfoAPI>* SystemInfoAPI::GetFactoryInstance() {
return &g_factory.Get(); return g_factory.Pointer();
} }
SystemInfoAPI::SystemInfoAPI(Profile* profile) : profile_(profile) { SystemInfoAPI::SystemInfoAPI(Profile* profile) : profile_(profile) {
ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( EventRouter* router = ExtensionSystem::Get(profile_)->event_router();
this, system_storage::OnAttached::kEventName); router->RegisterObserver(this, system_storage::OnAttached::kEventName);
ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( router->RegisterObserver(this, system_storage::OnDetached::kEventName);
this, system_storage::OnDetached::kEventName); router->RegisterObserver(this, system_display::OnDisplayChanged::kEventName);
ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
this, system_display::OnDisplayChanged::kEventName);
} }
SystemInfoAPI::~SystemInfoAPI() { SystemInfoAPI::~SystemInfoAPI() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment