diff --git a/startupcache/StartupCache.cpp b/startupcache/StartupCache.cpp index 1cf954a0d65f..c7fcc9ae9a99 100644 --- a/startupcache/StartupCache.cpp +++ b/startupcache/StartupCache.cpp @@ -137,6 +137,7 @@ nsresult StartupCache::InitSingleton() { StaticRefPtr StartupCache::gStartupCache; bool StartupCache::gShutdownInitiated; bool StartupCache::gIgnoreDiskCache; +bool StartupCache::gFoundDiskCacheOnInit; NS_IMPL_ISUPPORTS(StartupCache, nsIMemoryReporter) @@ -211,6 +212,8 @@ nsresult StartupCache::Init() { auto result = LoadArchive(); rv = result.isErr() ? result.unwrapErr() : NS_OK; + gFoundDiskCacheOnInit = rv != NS_ERROR_FILE_NOT_FOUND; + // Sometimes we don't have a cache yet, that's ok. // If it's corrupted, just remove it and start over. if (gIgnoreDiskCache || (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND)) { diff --git a/startupcache/StartupCache.h b/startupcache/StartupCache.h index 19386c9c8e14..153000a7330a 100644 --- a/startupcache/StartupCache.h +++ b/startupcache/StartupCache.h @@ -193,6 +193,8 @@ class StartupCache : public nsIMemoryReporter { StartupCache(); virtual ~StartupCache(); + friend class StartupCacheInfo; + Result LoadArchive(); nsresult Init(); @@ -238,6 +240,7 @@ class StartupCache : public nsIMemoryReporter { static StaticRefPtr gStartupCache; static bool gShutdownInitiated; static bool gIgnoreDiskCache; + static bool gFoundDiskCacheOnInit; PRThread* mWriteThread; PRThread* mPrefetchThread; UniquePtr mDecompressionContext; diff --git a/startupcache/StartupCacheInfo.cpp b/startupcache/StartupCacheInfo.cpp new file mode 100644 index 000000000000..461948d9c2f2 --- /dev/null +++ b/startupcache/StartupCacheInfo.cpp @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "StartupCacheInfo.h" + +#include "mozilla/Components.h" +#include "mozilla/RefPtr.h" + +using namespace mozilla; +using namespace mozilla::scache; + +NS_IMPL_ISUPPORTS(StartupCacheInfo, nsIStartupCacheInfo) + +nsresult StartupCacheInfo::GetIgnoreDiskCache(bool* aIgnore) { + *aIgnore = StartupCache::gIgnoreDiskCache; + return NS_OK; +} + +nsresult StartupCacheInfo::GetFoundDiskCacheOnInit(bool* aFound) { + *aFound = StartupCache::gFoundDiskCacheOnInit; + return NS_OK; +} + +nsresult StartupCacheInfo::GetWroteToDiskCache(bool* aWrote) { + if (!StartupCache::gStartupCache) { + *aWrote = false; + } else { + *aWrote = StartupCache::gStartupCache->mWrittenOnce; + } + return NS_OK; +} + +nsresult StartupCacheInfo::GetDiskCachePath(nsAString& aResult) { + if (!StartupCache::gStartupCache || !StartupCache::gStartupCache->mFile) { + return NS_OK; + } + nsAutoString path; + StartupCache::gStartupCache->mFile->GetPath(path); + aResult.Assign(path); + return NS_OK; +} + +NS_IMPL_COMPONENT_FACTORY(nsIStartupCacheInfo) { + return MakeAndAddRef().downcast(); +} diff --git a/startupcache/StartupCacheInfo.h b/startupcache/StartupCacheInfo.h new file mode 100644 index 000000000000..98a342ce8847 --- /dev/null +++ b/startupcache/StartupCacheInfo.h @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef StartupCacheInfo_h_ +#define StartupCacheInfo_h_ + +#include "nsIStartupCacheInfo.h" + +namespace mozilla { +namespace scache { + +class StartupCacheInfo final : public nsIStartupCacheInfo { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSISTARTUPCACHEINFO + + StartupCacheInfo() = default; + + private: + ~StartupCacheInfo() = default; +}; + +} // namespace scache +} // namespace mozilla + +#endif // StartupCache_h_ diff --git a/startupcache/components.conf b/startupcache/components.conf new file mode 100644 index 000000000000..e85ccf192ce0 --- /dev/null +++ b/startupcache/components.conf @@ -0,0 +1,13 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +Classes = [ + { + 'cid': '{a6b2f8b0-7438-11ea-bc55-0242ac130003}', + 'contract_ids': ['@mozilla.org/startupcacheinfo;1'], + 'type': 'nsIStartupCacheInfo', + }, +] diff --git a/startupcache/moz.build b/startupcache/moz.build index f32d53935bf0..7cf14b18cc40 100644 --- a/startupcache/moz.build +++ b/startupcache/moz.build @@ -17,7 +17,18 @@ EXPORTS.mozilla.scache += [ UNIFIED_SOURCES += [ 'StartupCache.cpp', + 'StartupCacheInfo.cpp', 'StartupCacheUtils.cpp', ] +XPCOM_MANIFESTS += [ + 'components.conf', +] + +XPIDL_MODULE = 'startupcache' + +XPIDL_SOURCES += [ + 'nsIStartupCacheInfo.idl', +] + FINAL_LIBRARY = 'xul' diff --git a/startupcache/nsIStartupCacheInfo.idl b/startupcache/nsIStartupCacheInfo.idl new file mode 100644 index 000000000000..d7fe0a71f7ac --- /dev/null +++ b/startupcache/nsIStartupCacheInfo.idl @@ -0,0 +1,38 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" + +/* NOTE: this interface is completely undesigned, not stable and likely to change */ +[scriptable, builtinclass, uuid(a6b2f8b0-7438-11ea-bc55-0242ac130003)] +interface nsIStartupCacheInfo : nsISupports +{ + /** + * Returns true if the startup cache will not load from the cache from disk. + * This can happen if the cache file is corrupt or has been invalidated. + */ + readonly attribute boolean IgnoreDiskCache; + + /** + * Returns true if during initialization of the startup cache an existing + * cache file was found on disk. This does NOT indicate if the file loaded + * successfully. + */ + readonly attribute boolean FoundDiskCacheOnInit; + + /** + * Returns true once the current cache file as been written to disk at least + * once. If the cache was loaded from disk and never changed this may never + * be set to true. + */ + readonly attribute boolean WroteToDiskCache; + + /** + * The full path and filename of the startup cache file that will be stored on + * disk. + */ + readonly attribute AString DiskCachePath; +}; diff --git a/toolkit/content/aboutSupport.js b/toolkit/content/aboutSupport.js index 9c94af74737f..1737fb239811 100644 --- a/toolkit/content/aboutSupport.js +++ b/toolkit/content/aboutSupport.js @@ -959,6 +959,14 @@ var snapshotFormatters = { } }, + startupCache(data) { + $("startup-cache-disk-cache-path").textContent = data.DiskCachePath; + $("startup-cache-ignore-disk-cache").textContent = data.IgnoreDiskCache; + $("startup-cache-found-disk-cache-on-init").textContent = + data.FoundDiskCacheOnInit; + $("startup-cache-wrote-to-disk-cache").textContent = data.WroteToDiskCache; + }, + libraryVersions(data) { let trs = [ $.new("tr", [ diff --git a/toolkit/content/aboutSupport.xhtml b/toolkit/content/aboutSupport.xhtml index 80ebc27b5b8f..f46cb25af561 100644 --- a/toolkit/content/aboutSupport.xhtml +++ b/toolkit/content/aboutSupport.xhtml @@ -608,6 +608,37 @@ #endif #endif +

+ + + + + + + + + + + + + + + + +
+ + +
+ + +
+ + +
+ + +
+

diff --git a/toolkit/locales/en-US/toolkit/about/aboutSupport.ftl b/toolkit/locales/en-US/toolkit/about/aboutSupport.ftl index 8786b2c48053..8c7bbb084477 100644 --- a/toolkit/locales/en-US/toolkit/about/aboutSupport.ftl +++ b/toolkit/locales/en-US/toolkit/about/aboutSupport.ftl @@ -300,6 +300,12 @@ sandbox-proc-type-file = file content sandbox-proc-type-media-plugin = media plugin sandbox-proc-type-data-decoder = data decoder +startup-cache-title = Startup Cache +startup-cache-disk-cache-path = Disk Cache Path +startup-cache-ignore-disk-cache = Ignore Disk Cache +startup-cache-found-disk-cache-on-init = Found Disk Cache on Init +startup-cache-wrote-to-disk-cache = Wrote to Disk Cache + launcher-process-status-0 = Enabled launcher-process-status-1 = Disabled due to failure launcher-process-status-2 = Disabled forcibly diff --git a/toolkit/modules/Troubleshoot.jsm b/toolkit/modules/Troubleshoot.jsm index fbf432a31627..d7b2cb1d922a 100644 --- a/toolkit/modules/Troubleshoot.jsm +++ b/toolkit/modules/Troubleshoot.jsm @@ -714,6 +714,12 @@ var dataProviders = { done(data); }, + startupCache: function startupCache(done) { + done( + Cc["@mozilla.org/startupcacheinfo;1"].getService(Ci.nsIStartupCacheInfo) + ); + }, + libraryVersions: function libraryVersions(done) { let data = {}; let verInfo = Cc["@mozilla.org/security/nssversion;1"].getService(