• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_AUTOTEST_PRIVATE_AUTOTEST_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_AUTOTEST_PRIVATE_AUTOTEST_PRIVATE_API_H_
7 
8 #include <string>
9 
10 #include "base/compiler_specific.h"
11 #include "chrome/browser/extensions/chrome_extension_function.h"
12 #include "extensions/browser/browser_context_keyed_api_factory.h"
13 
14 namespace extensions {
15 
16 class AutotestPrivateLogoutFunction : public ChromeSyncExtensionFunction {
17  public:
18   DECLARE_EXTENSION_FUNCTION("autotestPrivate.logout", AUTOTESTPRIVATE_LOGOUT)
19 
20  private:
~AutotestPrivateLogoutFunction()21   virtual ~AutotestPrivateLogoutFunction() {}
22   virtual bool RunSync() OVERRIDE;
23 };
24 
25 class AutotestPrivateRestartFunction : public ChromeSyncExtensionFunction {
26  public:
27   DECLARE_EXTENSION_FUNCTION("autotestPrivate.restart", AUTOTESTPRIVATE_RESTART)
28 
29  private:
~AutotestPrivateRestartFunction()30   virtual ~AutotestPrivateRestartFunction() {}
31   virtual bool RunSync() OVERRIDE;
32 };
33 
34 class AutotestPrivateShutdownFunction : public ChromeSyncExtensionFunction {
35  public:
36   DECLARE_EXTENSION_FUNCTION("autotestPrivate.shutdown",
37                              AUTOTESTPRIVATE_SHUTDOWN)
38 
39  private:
~AutotestPrivateShutdownFunction()40   virtual ~AutotestPrivateShutdownFunction() {}
41   virtual bool RunSync() OVERRIDE;
42 };
43 
44 class AutotestPrivateLoginStatusFunction : public ChromeSyncExtensionFunction {
45  public:
46   DECLARE_EXTENSION_FUNCTION("autotestPrivate.loginStatus",
47                              AUTOTESTPRIVATE_LOGINSTATUS)
48 
49  private:
~AutotestPrivateLoginStatusFunction()50   virtual ~AutotestPrivateLoginStatusFunction() {}
51   virtual bool RunSync() OVERRIDE;
52 };
53 
54 class AutotestPrivateLockScreenFunction : public ChromeSyncExtensionFunction {
55  public:
56   DECLARE_EXTENSION_FUNCTION("autotestPrivate.lockScreen",
57                              AUTOTESTPRIVATE_LOCKSCREEN)
58 
59  private:
~AutotestPrivateLockScreenFunction()60   virtual ~AutotestPrivateLockScreenFunction() {}
61   virtual bool RunSync() OVERRIDE;
62 };
63 
64 class AutotestPrivateGetExtensionsInfoFunction
65     : public ChromeSyncExtensionFunction {
66  public:
67   DECLARE_EXTENSION_FUNCTION("autotestPrivate.getExtensionsInfo",
68                              AUTOTESTPRIVATE_GETEXTENSIONSINFO)
69 
70  private:
~AutotestPrivateGetExtensionsInfoFunction()71   virtual ~AutotestPrivateGetExtensionsInfoFunction() {}
72   virtual bool RunSync() OVERRIDE;
73 };
74 
75 class AutotestPrivateSimulateAsanMemoryBugFunction
76     : public ChromeSyncExtensionFunction {
77  public:
78   DECLARE_EXTENSION_FUNCTION("autotestPrivate.simulateAsanMemoryBug",
79                              AUTOTESTPRIVATE_SIMULATEASANMEMORYBUG)
80 
81  private:
~AutotestPrivateSimulateAsanMemoryBugFunction()82   virtual ~AutotestPrivateSimulateAsanMemoryBugFunction() {}
83   virtual bool RunSync() OVERRIDE;
84 };
85 
86 // Don't kill the browser when we're in a browser test.
87 void SetAutotestPrivateTest();
88 
89 // The profile-keyed service that manages the autotestPrivate extension API.
90 class AutotestPrivateAPI : public BrowserContextKeyedAPI {
91  public:
92   static BrowserContextKeyedAPIFactory<AutotestPrivateAPI>*
93       GetFactoryInstance();
94 
95   // TODO(achuith): Replace these with a mock object for system calls.
test_mode()96   bool test_mode() const { return test_mode_; }
set_test_mode(bool test_mode)97   void set_test_mode(bool test_mode) { test_mode_ = test_mode; }
98 
99  private:
100   friend class BrowserContextKeyedAPIFactory<AutotestPrivateAPI>;
101 
102   AutotestPrivateAPI();
103   virtual ~AutotestPrivateAPI();
104 
105   // BrowserContextKeyedAPI implementation.
service_name()106   static const char* service_name() { return "AutotestPrivateAPI"; }
107   static const bool kServiceIsNULLWhileTesting = true;
108   static const bool kServiceRedirectedInIncognito = true;
109 
110   bool test_mode_;  // true for ExtensionApiTest.AutotestPrivate browser test.
111 };
112 
113 template <>
114 KeyedService*
115     BrowserContextKeyedAPIFactory<AutotestPrivateAPI>::BuildServiceInstanceFor(
116         content::BrowserContext* context) const;
117 
118 }  // namespace extensions
119 
120 #endif  // CHROME_BROWSER_EXTENSIONS_API_AUTOTEST_PRIVATE_AUTOTEST_PRIVATE_API_H_
121