Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_EXTENSIONS_SIGNIN_GAIA_AUTH_EXTENSION_LOADER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SIGNIN_GAIA_AUTH_EXTENSION_LOADER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_SIGNIN_GAIA_AUTH_EXTENSION_LOADER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SIGNIN_GAIA_AUTH_EXTENSION_LOADER_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include <map> |
| 9 #include <string> | |
| 10 | |
| 9 #include "extensions/browser/browser_context_keyed_api_factory.h" | 11 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 10 | 12 |
| 11 namespace content { | 13 namespace content { |
| 12 class BrowserContext; | 14 class BrowserContext; |
| 13 } | 15 } |
| 14 | 16 |
| 15 namespace extensions { | 17 namespace extensions { |
| 16 | 18 |
| 17 const char kGaiaAuthExtensionId[] = "mfffpogegjflfpflabcdkioaeobkgjik"; | 19 const char kGaiaAuthExtensionId[] = "mfffpogegjflfpflabcdkioaeobkgjik"; |
| 18 const char kGaiaAuthExtensionOrigin[] = | 20 const char kGaiaAuthExtensionOrigin[] = |
| 19 "chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik"; | 21 "chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik"; |
| 20 | 22 |
| 21 // Manages and registers the gaia auth extension with the extension system. | 23 // Manages and registers the gaia auth extension with the extension system. |
| 22 class GaiaAuthExtensionLoader : public BrowserContextKeyedAPI { | 24 class GaiaAuthExtensionLoader : public BrowserContextKeyedAPI { |
| 23 public: | 25 public: |
| 24 explicit GaiaAuthExtensionLoader(content::BrowserContext* context); | 26 explicit GaiaAuthExtensionLoader(content::BrowserContext* context); |
| 25 ~GaiaAuthExtensionLoader() override; | 27 ~GaiaAuthExtensionLoader() override; |
| 26 | 28 |
| 27 // Load the gaia auth extension if the extension is not loaded yet. | 29 // Load the gaia auth extension if the extension is not loaded yet. |
| 28 void LoadIfNeeded(); | 30 void LoadIfNeeded(); |
| 29 // Unload the gaia auth extension if no pending reference. | 31 // Unload the gaia auth extension if no pending reference. |
| 30 void UnloadIfNeeded(); | 32 void UnloadIfNeeded(); |
| 31 | 33 |
| 34 // Add a string data for gaia_auth extension. Returns an Id that | |
|
Yoyo Zhou
2015/02/04 23:24:15
nit: this is called "gaia auth" rather than "gaia_
xiyuan
2015/02/05 03:57:41
Done.
| |
| 35 // could be used get the data. All strings are cleared when gaia auth | |
|
Yoyo Zhou
2015/02/04 23:24:16
nit: used to
xiyuan
2015/02/05 03:57:41
Done.
| |
| 36 // is unloaded. | |
| 37 int AddData(const std::string& data); | |
| 38 | |
| 39 // Get data for the given id. Returns true if the data is found and | |
|
Yoyo Zhou
2015/02/04 23:24:16
Be consistent here ("ID")
xiyuan
2015/02/05 03:57:41
Done.
| |
| 40 // its value is copied to |data|. Otherwise, returns false. | |
| 41 bool GetData(int data_id, std::string* data); | |
| 42 | |
| 32 static GaiaAuthExtensionLoader* Get(content::BrowserContext* context); | 43 static GaiaAuthExtensionLoader* Get(content::BrowserContext* context); |
| 33 | 44 |
| 34 // BrowserContextKeyedAPI implementation. | 45 // BrowserContextKeyedAPI implementation. |
| 35 static BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>* | 46 static BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>* |
| 36 GetFactoryInstance(); | 47 GetFactoryInstance(); |
| 37 | 48 |
| 38 private: | 49 private: |
| 39 friend class BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>; | 50 friend class BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>; |
| 40 | 51 |
| 41 // KeyedService overrides: | 52 // KeyedService overrides: |
| 42 void Shutdown() override; | 53 void Shutdown() override; |
| 43 | 54 |
| 44 // BrowserContextKeyedAPI implementation. | 55 // BrowserContextKeyedAPI implementation. |
| 45 static const char* service_name() { | 56 static const char* service_name() { |
| 46 return "GaiaAuthExtensionLoader"; | 57 return "GaiaAuthExtensionLoader"; |
| 47 } | 58 } |
| 48 static const bool kServiceRedirectedInIncognito = true; | 59 static const bool kServiceRedirectedInIncognito = true; |
| 49 | 60 |
| 50 content::BrowserContext* browser_context_; | 61 content::BrowserContext* browser_context_; |
| 51 int load_count_; | 62 int load_count_; |
| 52 | 63 |
| 64 int last_data_id_; | |
| 65 std::map<int, std::string> data_; | |
| 66 | |
| 53 DISALLOW_COPY_AND_ASSIGN(GaiaAuthExtensionLoader); | 67 DISALLOW_COPY_AND_ASSIGN(GaiaAuthExtensionLoader); |
|
Yoyo Zhou
2015/02/04 23:24:16
#include "base/macros.h" for this
xiyuan
2015/02/05 03:57:41
Done.
| |
| 54 }; | 68 }; |
| 55 | 69 |
| 56 } // namespace extensions | 70 } // namespace extensions |
| 57 | 71 |
| 58 #endif // CHROME_BROWSER_EXTENSIONS_SIGNIN_GAIA_AUTH_EXTENSION_LOADER_H_ | 72 #endif // CHROME_BROWSER_EXTENSIONS_SIGNIN_GAIA_AUTH_EXTENSION_LOADER_H_ |
| OLD | NEW |