• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H_
7 
8 #include "chrome/browser/extensions/chrome_extension_function.h"
9 #include "chrome/common/extensions/api/feedback_private.h"
10 #include "extensions/browser/browser_context_keyed_api_factory.h"
11 #include "ui/gfx/rect.h"
12 
13 namespace extensions {
14 
15 extern char kFeedbackExtensionId[];
16 
17 class FeedbackService;
18 
19 using extensions::api::feedback_private::SystemInformation;
20 
21 class FeedbackPrivateAPI : public BrowserContextKeyedAPI {
22  public:
23   explicit FeedbackPrivateAPI(content::BrowserContext* context);
24   virtual ~FeedbackPrivateAPI();
25 
26   FeedbackService* GetService() const;
27   void RequestFeedback(const std::string& description_template,
28                        const std::string& category_tag,
29                        const GURL& page_url);
30 
31   // BrowserContextKeyedAPI implementation.
32   static BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>*
33       GetFactoryInstance();
34 
35  private:
36   friend class BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>;
37 
38   // BrowserContextKeyedAPI implementation.
service_name()39   static const char* service_name() {
40     return "FeedbackPrivateAPI";
41   }
42 
43   static const bool kServiceHasOwnInstanceInIncognito = true;
44 
45   content::BrowserContext* const browser_context_;
46   FeedbackService* service_;
47 };
48 
49 // Feedback strings.
50 class FeedbackPrivateGetStringsFunction : public ChromeSyncExtensionFunction {
51  public:
52   DECLARE_EXTENSION_FUNCTION("feedbackPrivate.getStrings",
53                              FEEDBACKPRIVATE_GETSTRINGS)
54 
55   // Invoke this callback when this function is called - used for testing.
set_test_callback(base::Closure * const callback)56   static void set_test_callback(base::Closure* const callback) {
57     test_callback_ = callback;
58   }
59 
60  protected:
~FeedbackPrivateGetStringsFunction()61   virtual ~FeedbackPrivateGetStringsFunction() {}
62 
63   // SyncExtensionFunction overrides.
64   virtual bool RunSync() OVERRIDE;
65 
66  private:
67   static base::Closure* test_callback_;
68 };
69 
70 class FeedbackPrivateGetUserEmailFunction : public ChromeSyncExtensionFunction {
71  public:
72   DECLARE_EXTENSION_FUNCTION("feedbackPrivate.getUserEmail",
73                              FEEDBACKPRIVATE_GETUSEREMAIL);
74 
75  protected:
~FeedbackPrivateGetUserEmailFunction()76   virtual ~FeedbackPrivateGetUserEmailFunction() {}
77   virtual bool RunSync() OVERRIDE;
78 };
79 
80 class FeedbackPrivateGetSystemInformationFunction
81     : public ChromeAsyncExtensionFunction {
82  public:
83   DECLARE_EXTENSION_FUNCTION("feedbackPrivate.getSystemInformation",
84                              FEEDBACKPRIVATE_GETSYSTEMINFORMATION);
85 
86  protected:
~FeedbackPrivateGetSystemInformationFunction()87   virtual ~FeedbackPrivateGetSystemInformationFunction() {}
88   virtual bool RunAsync() OVERRIDE;
89 
90  private:
91   void OnCompleted(
92       const std::vector<linked_ptr<SystemInformation> >& sys_info);
93 };
94 
95 class FeedbackPrivateSendFeedbackFunction
96     : public ChromeAsyncExtensionFunction {
97  public:
98   DECLARE_EXTENSION_FUNCTION("feedbackPrivate.sendFeedback",
99                              FEEDBACKPRIVATE_SENDFEEDBACK);
100 
101  protected:
~FeedbackPrivateSendFeedbackFunction()102   virtual ~FeedbackPrivateSendFeedbackFunction() {}
103   virtual bool RunAsync() OVERRIDE;
104 
105  private:
106   void OnCompleted(bool success);
107 };
108 
109 }  // namespace extensions
110 
111 #endif  // CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H_
112