PM: Use base::ScopedObservation in WorkerWatcher.
Also move ScopedObservation into the base namespace. It's an oversight that it wasn't there in the first place. Change-Id: I854bc0c96af72dff096894cd3b82cd7710f6add3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2519271 Reviewed-by: Patrick Monette <pmonette@chromium.org> Reviewed-by: François Doray <fdoray@chromium.org> Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org> Cr-Commit-Position: refs/heads/master@{#824123}
This commit is contained in:

committed by
Commit Bot

parent
f5e1a945a9
commit
80f6e8f595
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include "base/check_op.h"
|
#include "base/check_op.h"
|
||||||
|
|
||||||
|
namespace base {
|
||||||
|
|
||||||
// ScopedObservation is used to keep track of a single observation.
|
// ScopedObservation is used to keep track of a single observation.
|
||||||
// When ScopedObservation is destroyed, it removes the registered observation,
|
// When ScopedObservation is destroyed, it removes the registered observation,
|
||||||
// if any. Basic example (as a member variable):
|
// if any. Basic example (as a member variable):
|
||||||
@ -74,4 +76,6 @@ class ScopedObservation {
|
|||||||
Source* source_ = nullptr;
|
Source* source_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace base
|
||||||
|
|
||||||
#endif // BASE_SCOPED_OBSERVATION_H_
|
#endif // BASE_SCOPED_OBSERVATION_H_
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "base/check_op.h"
|
#include "base/check_op.h"
|
||||||
#include "base/notreached.h"
|
#include "base/notreached.h"
|
||||||
|
#include "base/scoped_observation.h"
|
||||||
#include "content/public/browser/render_process_host.h"
|
#include "content/public/browser/render_process_host.h"
|
||||||
#include "content/public/browser/render_process_host_observer.h"
|
#include "content/public/browser/render_process_host_observer.h"
|
||||||
|
|
||||||
@ -37,8 +38,10 @@ class ServiceWorkerContextAdapter::RunningServiceWorker
|
|||||||
// The adapter that owns |this|. Notified when RenderProcessExited() is
|
// The adapter that owns |this|. Notified when RenderProcessExited() is
|
||||||
// called.
|
// called.
|
||||||
ServiceWorkerContextAdapter* const adapter_;
|
ServiceWorkerContextAdapter* const adapter_;
|
||||||
// The render process host this instance is observing.
|
|
||||||
content::RenderProcessHost* observing_ = nullptr;
|
base::ScopedObservation<content::RenderProcessHost,
|
||||||
|
content::RenderProcessHostObserver>
|
||||||
|
scoped_observation_{this};
|
||||||
};
|
};
|
||||||
|
|
||||||
ServiceWorkerContextAdapter::RunningServiceWorker::RunningServiceWorker(
|
ServiceWorkerContextAdapter::RunningServiceWorker::RunningServiceWorker(
|
||||||
@ -47,20 +50,19 @@ ServiceWorkerContextAdapter::RunningServiceWorker::RunningServiceWorker(
|
|||||||
: version_id_(version_id), adapter_(adapter) {}
|
: version_id_(version_id), adapter_(adapter) {}
|
||||||
|
|
||||||
ServiceWorkerContextAdapter::RunningServiceWorker::~RunningServiceWorker() {
|
ServiceWorkerContextAdapter::RunningServiceWorker::~RunningServiceWorker() {
|
||||||
DCHECK_EQ(observing_, nullptr);
|
DCHECK(!scoped_observation_.IsObserving());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServiceWorkerContextAdapter::RunningServiceWorker::Subscribe(
|
void ServiceWorkerContextAdapter::RunningServiceWorker::Subscribe(
|
||||||
content::RenderProcessHost* worker_process_host) {
|
content::RenderProcessHost* worker_process_host) {
|
||||||
DCHECK_EQ(observing_, nullptr);
|
DCHECK(!scoped_observation_.IsObserving());
|
||||||
worker_process_host->AddObserver(this);
|
scoped_observation_.Observe(worker_process_host);
|
||||||
observing_ = worker_process_host;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServiceWorkerContextAdapter::RunningServiceWorker::Unsubscribe() {
|
void ServiceWorkerContextAdapter::RunningServiceWorker::Unsubscribe() {
|
||||||
DCHECK_NE(observing_, nullptr);
|
DCHECK(scoped_observation_.IsObserving());
|
||||||
observing_->RemoveObserver(this);
|
|
||||||
observing_ = nullptr;
|
scoped_observation_.RemoveObservation();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServiceWorkerContextAdapter::RunningServiceWorker::RenderProcessExited(
|
void ServiceWorkerContextAdapter::RunningServiceWorker::RenderProcessExited(
|
||||||
|
Reference in New Issue
Block a user