Commit 772f3e53 authored by hidehiko's avatar hidehiko Committed by Commit bot

Introduce ArcServiceManager::OnShutdown().

For graceful shutdown, this CL introduces OnShutdown
observer callback.
Along with the change, EventRouter now properly calls RemoveObserver
in the callback.
ArcServiceManager::IsInitialized() is now no longer needed. Remove it.

BUG=672829
TEST=Ran bots.

Review-Url: https://codereview.chromium.org/2581953002
Cr-Commit-Position: refs/heads/master@{#439144}
parent a6a24645
...@@ -401,8 +401,13 @@ EventRouter::EventRouter(Profile* profile) ...@@ -401,8 +401,13 @@ EventRouter::EventRouter(Profile* profile)
EventRouter::~EventRouter() = default; EventRouter::~EventRouter() = default;
void EventRouter::OnArcShutdown() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
arc::ArcServiceManager::Get()->RemoveObserver(this);
}
void EventRouter::OnIntentFiltersUpdated() { void EventRouter::OnIntentFiltersUpdated() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK_CURRENTLY_ON(BrowserThread::UI);
BroadcastEvent(profile_, BroadcastEvent(profile_,
extensions::events::FILE_MANAGER_PRIVATE_ON_APPS_UPDATED, extensions::events::FILE_MANAGER_PRIVATE_ON_APPS_UPDATED,
file_manager_private::OnAppsUpdated::kEventName, file_manager_private::OnAppsUpdated::kEventName,
...@@ -412,9 +417,6 @@ void EventRouter::OnIntentFiltersUpdated() { ...@@ -412,9 +417,6 @@ void EventRouter::OnIntentFiltersUpdated() {
void EventRouter::Shutdown() { void EventRouter::Shutdown() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (arc::ArcServiceManager::IsInitialized())
arc::ArcServiceManager::Get()->RemoveObserver(this);
chromeos::system::TimezoneSettings::GetInstance()->RemoveObserver(this); chromeos::system::TimezoneSettings::GetInstance()->RemoveObserver(this);
DLOG_IF(WARNING, !file_watchers_.empty()) DLOG_IF(WARNING, !file_watchers_.empty())
......
...@@ -68,6 +68,7 @@ class EventRouter : public KeyedService, ...@@ -68,6 +68,7 @@ class EventRouter : public KeyedService,
~EventRouter() override; ~EventRouter() override;
// arc::ArcServiceManager::Observer overrides. // arc::ArcServiceManager::Observer overrides.
void OnArcShutdown() override;
void OnIntentFiltersUpdated() override; void OnIntentFiltersUpdated() override;
// KeyedService overrides. // KeyedService overrides.
......
...@@ -83,14 +83,6 @@ ArcServiceManager* ArcServiceManager::Get() { ...@@ -83,14 +83,6 @@ ArcServiceManager* ArcServiceManager::Get() {
return g_arc_service_manager; return g_arc_service_manager;
} }
// static
bool ArcServiceManager::IsInitialized() {
if (!g_arc_service_manager)
return false;
DCHECK(g_arc_service_manager->thread_checker_.CalledOnValidThread());
return true;
}
ArcBridgeService* ArcServiceManager::arc_bridge_service() { ArcBridgeService* ArcServiceManager::arc_bridge_service() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
return arc_bridge_service_.get(); return arc_bridge_service_.get();
...@@ -113,6 +105,11 @@ void ArcServiceManager::RemoveObserver(Observer* observer) { ...@@ -113,6 +105,11 @@ void ArcServiceManager::RemoveObserver(Observer* observer) {
void ArcServiceManager::Shutdown() { void ArcServiceManager::Shutdown() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
// Before actual shutdown, notify observers for clean up.
for (auto& observer : observer_list_)
observer.OnArcShutdown();
icon_loader_ = nullptr; icon_loader_ = nullptr;
activity_resolver_ = nullptr; activity_resolver_ = nullptr;
services_.clear(); services_.clear();
......
...@@ -28,6 +28,11 @@ class ArcServiceManager { ...@@ -28,6 +28,11 @@ class ArcServiceManager {
public: public:
class Observer { class Observer {
public: public:
// Called when ArcServiceManager is being shut down. Observer
// implementation should clean up ARC related stuff here. One of the
// typical use cases is calling ArcServiceManager::RemoveObserver().
virtual void OnArcShutdown() = 0;
// Called when intent filters are added or removed. // Called when intent filters are added or removed.
virtual void OnIntentFiltersUpdated() = 0; virtual void OnIntentFiltersUpdated() = 0;
...@@ -50,12 +55,6 @@ class ArcServiceManager { ...@@ -50,12 +55,6 @@ class ArcServiceManager {
// called on the thread that this class was created on. // called on the thread that this class was created on.
static ArcServiceManager* Get(); static ArcServiceManager* Get();
// Returns if the ARC Service Manager instance exists.
// DO NOT CALL THIS. This function is a dirty workaround for properly shutting
// down chrome/browser/chromeos/extensions/file_manager/event_router.cc, and
// will likely be removed in the future.
static bool IsInitialized();
void AddObserver(Observer* observer); void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
......
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