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

Side by Side Diff: chrome/browser/extensions/signin/gaia_auth_extension_loader.cc

Issue 961443003: Unload the ScopedGaiaAuthExtension asynchronously. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix whitespace Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/signin/gaia_auth_extension_loader.h" 5 #include "chrome/browser/extensions/signin/gaia_auth_extension_loader.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
11 #include "chrome/browser/extensions/component_loader.h" 13 #include "chrome/browser/extensions/component_loader.h"
12 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/signin/signin_promo.h" 15 #include "chrome/browser/signin/signin_promo.h"
14 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
17 #include "content/public/browser/browser_context.h" 19 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/storage_partition.h" 21 #include "content/public/browser/storage_partition.h"
20 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 base::Bind(&base::DoNothing)); 81 base::Bind(&base::DoNothing));
80 } 82 }
81 GetComponentLoader(context)->Remove(extensions::kGaiaAuthExtensionId); 83 GetComponentLoader(context)->Remove(extensions::kGaiaAuthExtensionId);
82 } 84 }
83 85
84 } // namespace 86 } // namespace
85 87
86 namespace extensions { 88 namespace extensions {
87 89
88 GaiaAuthExtensionLoader::GaiaAuthExtensionLoader(BrowserContext* context) 90 GaiaAuthExtensionLoader::GaiaAuthExtensionLoader(BrowserContext* context)
89 : browser_context_(context), load_count_(0), last_data_id_(0) {} 91 : browser_context_(context),
92 load_count_(0),
93 last_data_id_(0),
94 weak_ptr_factory_(this) {
95 }
90 96
91 GaiaAuthExtensionLoader::~GaiaAuthExtensionLoader() { 97 GaiaAuthExtensionLoader::~GaiaAuthExtensionLoader() {
92 DCHECK_EQ(0, load_count_); 98 DCHECK_EQ(0, load_count_);
93 } 99 }
94 100
95 void GaiaAuthExtensionLoader::LoadIfNeeded() { 101 void GaiaAuthExtensionLoader::LoadIfNeeded() {
96 if (load_count_ == 0) 102 if (load_count_ == 0)
97 LoadGaiaAuthExtension(browser_context_); 103 LoadGaiaAuthExtension(browser_context_);
98 ++load_count_; 104 ++load_count_;
99 } 105 }
100 106
107 void GaiaAuthExtensionLoader::UnloadIfNeededAsync() {
108 base::ThreadTaskRunnerHandle::Get()->PostTask(
109 FROM_HERE,
110 base::Bind(&GaiaAuthExtensionLoader::UnloadIfNeeded,
111 weak_ptr_factory_.GetWeakPtr()));
112 }
113
101 void GaiaAuthExtensionLoader::UnloadIfNeeded() { 114 void GaiaAuthExtensionLoader::UnloadIfNeeded() {
102 --load_count_; 115 --load_count_;
103 if (load_count_ == 0) { 116 if (load_count_ == 0) {
104 UnloadGaiaAuthExtension(browser_context_); 117 UnloadGaiaAuthExtension(browser_context_);
105 data_.clear(); 118 data_.clear();
106 } 119 }
107 } 120 }
108 121
109 int GaiaAuthExtensionLoader::AddData(const std::string& data) { 122 int GaiaAuthExtensionLoader::AddData(const std::string& data) {
110 ++last_data_id_; 123 ++last_data_id_;
(...skipping 27 matching lines...) Expand all
138 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader> > g_factory = 151 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader> > g_factory =
139 LAZY_INSTANCE_INITIALIZER; 152 LAZY_INSTANCE_INITIALIZER;
140 153
141 // static 154 // static
142 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>* 155 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>*
143 GaiaAuthExtensionLoader::GetFactoryInstance() { 156 GaiaAuthExtensionLoader::GetFactoryInstance() {
144 return g_factory.Pointer(); 157 return g_factory.Pointer();
145 } 158 }
146 159
147 } // namespace extensions 160 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698