Commit e7fc0d39 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

AppCache: Disable construction, copying and destruction in interfaces.

Interfaces are base classes that only consist of virtual methods. This
CL adds the following:
* deleted copy constructor and assignment - prevent unintended slicing
* protected constructors - prevent unintended direct instantiation
* protected destructors - prohibit the user of an interface
  implementation from destructing the implementation, enforcing that
  the user does not own the implementation

Change-Id: I2bb093e430cacb870846c74397051917ce50c83e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1663462
Commit-Queue: Victor Costan <pwnall@chromium.org>
Auto-Submit: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarStaphany Park <staphany@chromium.org>
Cr-Commit-Position: refs/heads/master@{#670255}
parent 7c8bd14d
......@@ -47,9 +47,17 @@ class CONTENT_EXPORT AppCacheGroup
class CONTENT_EXPORT UpdateObserver {
public:
UpdateObserver(const UpdateObserver&) = delete;
UpdateObserver& operator=(const UpdateObserver&) = delete;
// Called just after an appcache update has completed.
virtual void OnUpdateComplete(AppCacheGroup* group) = 0;
virtual ~UpdateObserver() {}
protected:
// The constructor and destructor exist to facilitate subclassing, and
// should not be called directly.
UpdateObserver() noexcept = default;
virtual ~UpdateObserver() = default;
};
enum UpdateAppCacheStatus {
......
......@@ -61,13 +61,20 @@ class CONTENT_EXPORT AppCacheHost : public blink::mojom::AppCacheHost,
public:
class CONTENT_EXPORT Observer {
public:
Observer(const Observer&) = delete;
Observer& operator=(const Observer&) = delete;
// Called just after the cache selection algorithm completes.
virtual void OnCacheSelectionComplete(AppCacheHost* host) = 0;
// Called just prior to the instance being deleted.
virtual void OnDestructionImminent(AppCacheHost* host) = 0;
virtual ~Observer() {}
protected:
// The constructor and destructor exist to facilitate subclassing, and
// should not be called directly.
Observer() noexcept = default;
virtual ~Observer() = default;
};
AppCacheHost(const base::UnguessableToken& host_id,
......
......@@ -73,6 +73,9 @@ class CONTENT_EXPORT AppCacheServiceImpl : public AppCacheService {
class CONTENT_EXPORT Observer {
public:
Observer(const Observer&) = delete;
Observer& operator=(const Observer&) = delete;
// Called just prior to the instance being deleted.
virtual void OnServiceDestructionImminent(AppCacheServiceImpl* service) {}
......@@ -82,7 +85,12 @@ class CONTENT_EXPORT AppCacheServiceImpl : public AppCacheService {
// ref provided.
virtual void OnServiceReinitialized(
AppCacheStorageReference* old_storage_ref) {}
virtual ~Observer() {}
protected:
// The constructor and destructor exist to facilitate subclassing, and
// should not be called directly.
Observer() noexcept = default;
virtual ~Observer() = default;
};
// If not using quota management, the proxy may be NULL.
......
......@@ -48,6 +48,9 @@ class CONTENT_EXPORT AppCacheStorage {
class CONTENT_EXPORT Delegate {
public:
Delegate(const Delegate&) = delete;
Delegate& operator=(const Delegate&) = delete;
// If retrieval fails, 'collection' will be NULL.
virtual void OnAllInfo(AppCacheInfoCollection* collection) {}
......@@ -87,7 +90,10 @@ class CONTENT_EXPORT AppCacheStorage {
const GURL& mainfest_url) {}
protected:
virtual ~Delegate() {}
// The constructor and destructor exist to facilitate subclassing, and
// should not be called directly.
Delegate() noexcept = default;
virtual ~Delegate() = default;
};
explicit AppCacheStorage(AppCacheServiceImpl* service);
......
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