| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 base::Bind(&base::DoNothing)); | 79 base::Bind(&base::DoNothing)); |
| 80 } | 80 } |
| 81 GetComponentLoader(context)->Remove(extensions::kGaiaAuthExtensionId); | 81 GetComponentLoader(context)->Remove(extensions::kGaiaAuthExtensionId); |
| 82 } | 82 } |
| 83 | 83 |
| 84 } // namespace | 84 } // namespace |
| 85 | 85 |
| 86 namespace extensions { | 86 namespace extensions { |
| 87 | 87 |
| 88 GaiaAuthExtensionLoader::GaiaAuthExtensionLoader(BrowserContext* context) | 88 GaiaAuthExtensionLoader::GaiaAuthExtensionLoader(BrowserContext* context) |
| 89 : browser_context_(context), load_count_(0) {} | 89 : browser_context_(context), load_count_(0), last_data_id_(0) {} |
| 90 | 90 |
| 91 GaiaAuthExtensionLoader::~GaiaAuthExtensionLoader() { | 91 GaiaAuthExtensionLoader::~GaiaAuthExtensionLoader() { |
| 92 DCHECK_EQ(0, load_count_); | 92 DCHECK_EQ(0, load_count_); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void GaiaAuthExtensionLoader::LoadIfNeeded() { | 95 void GaiaAuthExtensionLoader::LoadIfNeeded() { |
| 96 if (load_count_ == 0) | 96 if (load_count_ == 0) |
| 97 LoadGaiaAuthExtension(browser_context_); | 97 LoadGaiaAuthExtension(browser_context_); |
| 98 ++load_count_; | 98 ++load_count_; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void GaiaAuthExtensionLoader::UnloadIfNeeded() { | 101 void GaiaAuthExtensionLoader::UnloadIfNeeded() { |
| 102 --load_count_; | 102 --load_count_; |
| 103 if (load_count_ == 0) | 103 if (load_count_ == 0) { |
| 104 UnloadGaiaAuthExtension(browser_context_); | 104 UnloadGaiaAuthExtension(browser_context_); |
| 105 data_.clear(); |
| 106 } |
| 107 } |
| 108 |
| 109 int GaiaAuthExtensionLoader::AddData(const std::string& data) { |
| 110 ++last_data_id_; |
| 111 data_[last_data_id_] = data; |
| 112 return last_data_id_; |
| 113 } |
| 114 |
| 115 bool GaiaAuthExtensionLoader::GetData(int data_id, std::string* data) { |
| 116 auto it = data_.find(data_id); |
| 117 if (it == data_.end()) |
| 118 return false; |
| 119 |
| 120 *data = it->second; |
| 121 return true; |
| 105 } | 122 } |
| 106 | 123 |
| 107 void GaiaAuthExtensionLoader::Shutdown() { | 124 void GaiaAuthExtensionLoader::Shutdown() { |
| 108 if (load_count_ > 0) { | 125 if (load_count_ > 0) { |
| 109 UnloadGaiaAuthExtension(browser_context_); | 126 UnloadGaiaAuthExtension(browser_context_); |
| 110 load_count_ = 0; | 127 load_count_ = 0; |
| 111 } | 128 } |
| 129 data_.clear(); |
| 112 } | 130 } |
| 113 | 131 |
| 114 // static | 132 // static |
| 115 GaiaAuthExtensionLoader* GaiaAuthExtensionLoader::Get(BrowserContext* context) { | 133 GaiaAuthExtensionLoader* GaiaAuthExtensionLoader::Get(BrowserContext* context) { |
| 116 return BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>::Get(context); | 134 return BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>::Get(context); |
| 117 } | 135 } |
| 118 | 136 |
| 119 static base::LazyInstance< | 137 static base::LazyInstance< |
| 120 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader> > g_factory = | 138 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader> > g_factory = |
| 121 LAZY_INSTANCE_INITIALIZER; | 139 LAZY_INSTANCE_INITIALIZER; |
| 122 | 140 |
| 123 // static | 141 // static |
| 124 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>* | 142 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>* |
| 125 GaiaAuthExtensionLoader::GetFactoryInstance() { | 143 GaiaAuthExtensionLoader::GetFactoryInstance() { |
| 126 return g_factory.Pointer(); | 144 return g_factory.Pointer(); |
| 127 } | 145 } |
| 128 | 146 |
| 129 } // namespace extensions | 147 } // namespace extensions |
| OLD | NEW |