fix: browser contexts live forever (#24964)

This commit is contained in:
Jeremy Rose 2020-08-17 13:21:53 -07:00 committed by GitHub
parent befbbc27d8
commit bac2f46ba9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 68 additions and 73 deletions

View file

@ -10,7 +10,6 @@
#include <string>
#include <vector>
#include "base/memory/ref_counted_delete_on_sequence.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/predictors/preconnect_manager.h"
#include "content/public/browser/browser_context.h"
@ -50,8 +49,7 @@ class WebViewManager;
class ProtocolRegistry;
class ElectronBrowserContext
: public base::RefCountedDeleteOnSequence<ElectronBrowserContext>,
public content::BrowserContext,
: public content::BrowserContext,
public network::mojom::TrustedURLLoaderAuthClient {
public:
// partition_id => browser_context
@ -73,19 +71,17 @@ class ElectronBrowserContext
}
};
using BrowserContextMap =
std::map<PartitionKey, base::WeakPtr<ElectronBrowserContext>>;
std::map<PartitionKey, std::unique_ptr<ElectronBrowserContext>>;
// Get or create the BrowserContext according to its |partition| and
// |in_memory|. The |options| will be passed to constructor when there is no
// existing BrowserContext.
static scoped_refptr<ElectronBrowserContext> From(
static ElectronBrowserContext* From(
const std::string& partition,
bool in_memory,
base::DictionaryValue options = base::DictionaryValue());
static BrowserContextMap browser_context_map() {
return browser_context_map_;
}
static BrowserContextMap& browser_context_map();
void SetUserAgent(const std::string& user_agent);
std::string GetUserAgent() const;
@ -151,15 +147,12 @@ class ElectronBrowserContext
return protocol_registry_.get();
}
protected:
ElectronBrowserContext(const std::string& partition,
bool in_memory,
base::DictionaryValue options);
~ElectronBrowserContext() override;
private:
friend class base::RefCountedDeleteOnSequence<ElectronBrowserContext>;
friend class base::DeleteHelper<ElectronBrowserContext>;
ElectronBrowserContext(const std::string& partition,
bool in_memory,
base::DictionaryValue options);
void OnLoaderCreated(int32_t request_id,
mojo::PendingReceiver<network::mojom::TrustedAuthClient>
@ -168,8 +161,6 @@ class ElectronBrowserContext
// Initialize pref registry.
void InitPrefs();
static BrowserContextMap browser_context_map_;
ValueMapPrefStore* in_memory_pref_store_;
std::unique_ptr<content::ResourceContext> resource_context_;