Home | History | Annotate | Download | only in dbus
      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_CHROMEOS_DBUS_PRINTER_SERVICE_PROVIDER_H_
      6 #define CHROME_BROWSER_CHROMEOS_DBUS_PRINTER_SERVICE_PROVIDER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/memory/weak_ptr.h"
     11 #include "chrome/browser/chromeos/dbus/cros_dbus_service.h"
     12 #include "dbus/exported_object.h"
     13 
     14 namespace dbus {
     15 class MethodCall;
     16 class Response;
     17 }
     18 
     19 namespace chromeos {
     20 
     21 // This class provides printer service for CrosDBusService.
     22 // It detects attached printers and show user help page.
     23 //
     24 // The following methods are exported.
     25 //
     26 // Interface: org.chromium.LibCrosServiceInterface (kLibCrosServiceInterface)
     27 // Method: PrinterAdded (kPrinterAdded)
     28 // Parameters: string:vendor Optional, USB vendor ID.
     29 //             string:product Optional, USB product ID.
     30 //
     31 //   Display help page to advice user to use Cloud Print.
     32 //
     33 //   The returned signal will contain the three values:
     34 //
     35 // This service can be manually tested dbus-send on ChromeOS.
     36 //
     37 // 1. Open a terminal and run the following:
     38 //
     39 //   % dbus-send --system --type=method_call
     40 //       --dest=org.chromium.LibCrosService /org/chromium/LibCrosService
     41 //       org.chromium.LibCrosServiceInterface.PrinterAdded
     42 //       string:123 string:456
     43 //
     44 // 2. Go back to ChromeOS and check if new tab with information is opened.
     45 
     46 class PrinterServiceProvider
     47     : public CrosDBusService::ServiceProviderInterface {
     48  public:
     49   PrinterServiceProvider();
     50   virtual ~PrinterServiceProvider();
     51 
     52   // CrosDBusService::ServiceProviderInterface override.
     53   virtual void Start(
     54       scoped_refptr<dbus::ExportedObject> exported_object) OVERRIDE;
     55 
     56  protected:
     57   virtual void ShowCloudPrintHelp(const std::string& vendor,
     58                                   const std::string& product);
     59 
     60  private:
     61   // Called from ExportedObject, when PrinterAdded() is exported as
     62   // a D-Bus method, or failed to be exported.
     63   void OnExported(const std::string& interface_name,
     64                   const std::string& method_name,
     65                   bool success);
     66 
     67   // Invoked when usb printer is detected.
     68   // Called on UI thread from dbus request.
     69   void PrinterAdded(dbus::MethodCall* method_call,
     70                     dbus::ExportedObject::ResponseSender response_sender);
     71 
     72   scoped_refptr<dbus::ExportedObject> exported_object_;
     73   base::WeakPtrFactory<PrinterServiceProvider> weak_ptr_factory_;
     74 
     75   DISALLOW_COPY_AND_ASSIGN(PrinterServiceProvider);
     76 };
     77 
     78 }  // namespace chromeos
     79 
     80 #endif  // CHROME_BROWSER_CHROMEOS_DBUS_PRINTER_SERVICE_PROVIDER_H_
     81 
     82