| OLD | NEW |
| 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" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 GetComponentLoader(context)->Remove(extensions::kGaiaAuthExtensionId); | 61 GetComponentLoader(context)->Remove(extensions::kGaiaAuthExtensionId); |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 namespace extensions { | 66 namespace extensions { |
| 67 | 67 |
| 68 GaiaAuthExtensionLoader::GaiaAuthExtensionLoader(BrowserContext* context) | 68 GaiaAuthExtensionLoader::GaiaAuthExtensionLoader(BrowserContext* context) |
| 69 : browser_context_(context), | 69 : browser_context_(context), |
| 70 load_count_(0), | 70 load_count_(0), |
| 71 last_data_id_(0), | |
| 72 weak_ptr_factory_(this) { | 71 weak_ptr_factory_(this) { |
| 73 } | 72 } |
| 74 | 73 |
| 75 GaiaAuthExtensionLoader::~GaiaAuthExtensionLoader() { | 74 GaiaAuthExtensionLoader::~GaiaAuthExtensionLoader() { |
| 76 DCHECK_EQ(0, load_count_); | 75 DCHECK_EQ(0, load_count_); |
| 77 } | 76 } |
| 78 | 77 |
| 79 void GaiaAuthExtensionLoader::LoadIfNeeded() { | 78 void GaiaAuthExtensionLoader::LoadIfNeeded() { |
| 80 if (load_count_ == 0) | 79 if (load_count_ == 0) |
| 81 LoadGaiaAuthExtension(browser_context_); | 80 LoadGaiaAuthExtension(browser_context_); |
| 82 ++load_count_; | 81 ++load_count_; |
| 83 } | 82 } |
| 84 | 83 |
| 85 void GaiaAuthExtensionLoader::UnloadIfNeededAsync() { | 84 void GaiaAuthExtensionLoader::UnloadIfNeededAsync() { |
| 86 base::ThreadTaskRunnerHandle::Get()->PostTask( | 85 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 87 FROM_HERE, | 86 FROM_HERE, |
| 88 base::Bind(&GaiaAuthExtensionLoader::UnloadIfNeeded, | 87 base::Bind(&GaiaAuthExtensionLoader::UnloadIfNeeded, |
| 89 weak_ptr_factory_.GetWeakPtr())); | 88 weak_ptr_factory_.GetWeakPtr())); |
| 90 } | 89 } |
| 91 | 90 |
| 92 void GaiaAuthExtensionLoader::UnloadIfNeeded() { | 91 void GaiaAuthExtensionLoader::UnloadIfNeeded() { |
| 93 --load_count_; | 92 --load_count_; |
| 94 if (load_count_ == 0) { | 93 if (load_count_ == 0) { |
| 95 UnloadGaiaAuthExtension(browser_context_); | 94 UnloadGaiaAuthExtension(browser_context_); |
| 96 data_.clear(); | |
| 97 } | 95 } |
| 98 } | 96 } |
| 99 | 97 |
| 100 void GaiaAuthExtensionLoader::Shutdown() { | 98 void GaiaAuthExtensionLoader::Shutdown() { |
| 101 if (load_count_ > 0) { | 99 if (load_count_ > 0) { |
| 102 UnloadGaiaAuthExtension(browser_context_); | 100 UnloadGaiaAuthExtension(browser_context_); |
| 103 load_count_ = 0; | 101 load_count_ = 0; |
| 104 } | 102 } |
| 105 data_.clear(); | |
| 106 } | 103 } |
| 107 | 104 |
| 108 // static | 105 // static |
| 109 GaiaAuthExtensionLoader* GaiaAuthExtensionLoader::Get(BrowserContext* context) { | 106 GaiaAuthExtensionLoader* GaiaAuthExtensionLoader::Get(BrowserContext* context) { |
| 110 return BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>::Get(context); | 107 return BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>::Get(context); |
| 111 } | 108 } |
| 112 | 109 |
| 113 static base::LazyInstance< | 110 static base::LazyInstance< |
| 114 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader> > g_factory = | 111 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader> > g_factory = |
| 115 LAZY_INSTANCE_INITIALIZER; | 112 LAZY_INSTANCE_INITIALIZER; |
| 116 | 113 |
| 117 // static | 114 // static |
| 118 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>* | 115 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>* |
| 119 GaiaAuthExtensionLoader::GetFactoryInstance() { | 116 GaiaAuthExtensionLoader::GetFactoryInstance() { |
| 120 return g_factory.Pointer(); | 117 return g_factory.Pointer(); |
| 121 } | 118 } |
| 122 | 119 |
| 123 } // namespace extensions | 120 } // namespace extensions |
| OLD | NEW |