Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Unified Diff: components/nacl/browser/pnacl_host.h

Issue 2207683002: Use a raw pointer instead of Singleton for PnaclHost and leak it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b6_sequenced_worker_pool_redirection
Patch Set: typo Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/nacl/browser/pnacl_host.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/nacl/browser/pnacl_host.h
diff --git a/components/nacl/browser/pnacl_host.h b/components/nacl/browser/pnacl_host.h
index 268efeb0de2a5b71ae5440a1b780746cb1f1526a..ff3f04eba7da6a4ccab6193dfc2c4f89be0830c5 100644
--- a/components/nacl/browser/pnacl_host.h
+++ b/components/nacl/browser/pnacl_host.h
@@ -10,11 +10,9 @@
#include <map>
#include <memory>
-#include "base/callback_forward.h"
+#include "base/callback.h"
#include "base/files/file.h"
#include "base/macros.h"
-#include "base/memory/singleton.h"
-#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "components/nacl/browser/nacl_file_host.h"
#include "components/nacl/common/pnacl_types.h"
@@ -38,10 +36,17 @@ class PnaclHost {
typedef base::Callback<void(base::File)> TempFileCallback;
typedef base::Callback<void(const base::File&, bool is_hit)> NexeFdCallback;
+ // Gets the PnaclHost singleton instance (creating it if necessary).
+ // PnaclHost is a singleton because there is only one translation cache, and
+ // so that the BrowsingDataRemover can clear it even if no translation has
+ // ever been started.
static PnaclHost* GetInstance();
- PnaclHost();
- ~PnaclHost();
+ // The PnaclHost instance is intentionally leaked on shutdown. DeInitIfSafe()
+ // attempts to cleanup |disk_cache_| earlier, but if it fails to do so in
+ // time, it will be too late when AtExitManager kicks in anway so subscribing
+ // to it is useless.
+ ~PnaclHost() = delete;
// Initialize cache backend. GetNexeFd will also initialize the backend if
// necessary, but calling Init ahead of time will minimize the latency.
@@ -99,16 +104,15 @@ class PnaclHost {
const base::Closure& callback);
// Return the number of tracked translations or FD requests currently pending.
- size_t pending_translations() { return pending_translations_.size(); }
+ size_t pending_translations() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ return pending_translations_.size();
+ }
private:
- // PnaclHost is a singleton because there is only one translation cache, and
- // so that the BrowsingDataRemover can clear it even if no translation has
- // ever been started.
- friend struct base::DefaultSingletonTraits<PnaclHost>;
friend class FileProxy;
- friend class pnacl::PnaclHostTest;
- friend class pnacl::PnaclHostTestDisk;
+ friend class PnaclHostTest;
+ friend class PnaclHostTestDisk;
enum CacheState {
CacheUninitialized,
CacheInitializing,
@@ -134,6 +138,9 @@ class PnaclHost {
typedef std::pair<int, int> TranslationID;
typedef std::map<TranslationID, PendingTranslation> PendingTranslationMap;
+
+ PnaclHost();
+
static bool TranslationMayBeCached(
const PendingTranslationMap::iterator& entry);
@@ -172,13 +179,12 @@ class PnaclHost {
// Operations which are pending with the cache backend, which we should
// wait for before destroying it (see comment on DeInitIfSafe).
- int pending_backend_operations_;
- CacheState cache_state_;
+ int pending_backend_operations_ = 0;
+ CacheState cache_state_ = CacheUninitialized;
base::FilePath temp_dir_;
- std::unique_ptr<pnacl::PnaclTranslationCache> disk_cache_;
+ std::unique_ptr<PnaclTranslationCache> disk_cache_;
PendingTranslationMap pending_translations_;
base::ThreadChecker thread_checker_;
- base::WeakPtrFactory<PnaclHost> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(PnaclHost);
};
« no previous file with comments | « no previous file | components/nacl/browser/pnacl_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698