Commit c37009c3 authored by noms's avatar noms Committed by Commit bot

Unload the ScopedGaiaAuthExtension asynchronously.

If we don't do this, then we have a race condition between unloading
this extension, and trying to use it because we have manually
navigated to it.

BUG=460431

Committed: https://crrev.com/1805c4c5c4b5292cca51a54f379cde498db7238b
Cr-Commit-Position: refs/heads/master@{#318140}

Review URL: https://codereview.chromium.org/961443003

Cr-Commit-Position: refs/heads/master@{#320937}
parent 0cf4c5c1
......@@ -8,6 +8,8 @@
#include "base/files/file_path.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/signin/signin_promo.h"
......@@ -86,7 +88,11 @@ void UnloadGaiaAuthExtension(BrowserContext* context) {
namespace extensions {
GaiaAuthExtensionLoader::GaiaAuthExtensionLoader(BrowserContext* context)
: browser_context_(context), load_count_(0), last_data_id_(0) {}
: browser_context_(context),
load_count_(0),
last_data_id_(0),
weak_ptr_factory_(this) {
}
GaiaAuthExtensionLoader::~GaiaAuthExtensionLoader() {
DCHECK_EQ(0, load_count_);
......@@ -98,6 +104,13 @@ void GaiaAuthExtensionLoader::LoadIfNeeded() {
++load_count_;
}
void GaiaAuthExtensionLoader::UnloadIfNeededAsync() {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(&GaiaAuthExtensionLoader::UnloadIfNeeded,
weak_ptr_factory_.GetWeakPtr()));
}
void GaiaAuthExtensionLoader::UnloadIfNeeded() {
--load_count_;
if (load_count_ == 0) {
......
......@@ -9,6 +9,7 @@
#include <string>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
namespace content {
......@@ -31,6 +32,7 @@ class GaiaAuthExtensionLoader : public BrowserContextKeyedAPI {
void LoadIfNeeded();
// Unload the gaia auth extension if no pending reference.
void UnloadIfNeeded();
void UnloadIfNeededAsync();
// Add a string data for gaia auth extension. Returns an ID that
// could be used to get the data. All strings are cleared when gaia auth
......@@ -65,6 +67,8 @@ class GaiaAuthExtensionLoader : public BrowserContextKeyedAPI {
int last_data_id_;
std::map<int, std::string> data_;
base::WeakPtrFactory<GaiaAuthExtensionLoader> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(GaiaAuthExtensionLoader);
};
......
......@@ -20,5 +20,5 @@ ScopedGaiaAuthExtension::~ScopedGaiaAuthExtension() {
extensions::GaiaAuthExtensionLoader* loader =
extensions::GaiaAuthExtensionLoader::Get(browser_context_);
if (loader)
loader->UnloadIfNeeded();
loader->UnloadIfNeededAsync();
}
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