Home | History | Annotate | Download | only in feedback_private
      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/api/profile_keyed_api_factory.h"
      9 #include "chrome/browser/extensions/chrome_extension_function.h"
     10 #include "chrome/common/extensions/api/feedback_private.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 ProfileKeyedAPI {
     22  public:
     23   explicit FeedbackPrivateAPI(Profile* profile);
     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   // ProfileKeyedAPI implementation.
     32   static ProfileKeyedAPIFactory<FeedbackPrivateAPI>* GetFactoryInstance();
     33 
     34  private:
     35   friend class ProfileKeyedAPIFactory<FeedbackPrivateAPI>;
     36 
     37   // ProfileKeyedAPI implementation.
     38   static const char* service_name() {
     39     return "FeedbackPrivateAPI";
     40   }
     41 
     42   static const bool kServiceHasOwnInstanceInIncognito = true;
     43 
     44   Profile* const profile_;
     45   FeedbackService* service_;
     46 };
     47 
     48 // Feedback strings.
     49 class FeedbackPrivateGetStringsFunction : public ChromeSyncExtensionFunction {
     50  public:
     51   DECLARE_EXTENSION_FUNCTION("feedbackPrivate.getStrings",
     52                              FEEDBACKPRIVATE_GETSTRINGS)
     53 
     54   // Invoke this callback when this function is called - used for testing.
     55   static void set_test_callback(base::Closure* const callback) {
     56     test_callback_ = callback;
     57   }
     58 
     59  protected:
     60   virtual ~FeedbackPrivateGetStringsFunction() {}
     61 
     62   // SyncExtensionFunction overrides.
     63   virtual bool RunImpl() OVERRIDE;
     64 
     65  private:
     66   static base::Closure* test_callback_;
     67 };
     68 
     69 class FeedbackPrivateGetUserEmailFunction : public ChromeSyncExtensionFunction {
     70  public:
     71   DECLARE_EXTENSION_FUNCTION("feedbackPrivate.getUserEmail",
     72                              FEEDBACKPRIVATE_GETUSEREMAIL);
     73 
     74  protected:
     75   virtual ~FeedbackPrivateGetUserEmailFunction() {}
     76   virtual bool RunImpl() OVERRIDE;
     77 };
     78 
     79 class FeedbackPrivateGetSystemInformationFunction
     80     : public ChromeAsyncExtensionFunction {
     81  public:
     82   DECLARE_EXTENSION_FUNCTION("feedbackPrivate.getSystemInformation",
     83                              FEEDBACKPRIVATE_GETSYSTEMINFORMATION);
     84 
     85  protected:
     86   virtual ~FeedbackPrivateGetSystemInformationFunction() {}
     87   virtual bool RunImpl() OVERRIDE;
     88 
     89  private:
     90   void OnCompleted(
     91       const std::vector<linked_ptr<SystemInformation> >& sys_info);
     92 };
     93 
     94 class FeedbackPrivateSendFeedbackFunction
     95     : public ChromeAsyncExtensionFunction {
     96  public:
     97   DECLARE_EXTENSION_FUNCTION("feedbackPrivate.sendFeedback",
     98                              FEEDBACKPRIVATE_SENDFEEDBACK);
     99 
    100  protected:
    101   virtual ~FeedbackPrivateSendFeedbackFunction() {}
    102   virtual bool RunImpl() OVERRIDE;
    103 
    104  private:
    105   void OnCompleted(bool success);
    106 };
    107 
    108 }  // namespace extensions
    109 
    110 #endif  // CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H_
    111