Home | History | Annotate | Download | only in win
      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 CLOUD_PRINT_SERVICE_SETUP_LISTENER_H_
      6 #define CLOUD_PRINT_SERVICE_SETUP_LISTENER_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/compiler_specific.h"
     12 #include "base/files/file_path.h"
     13 #include "base/memory/scoped_ptr.h"
     14 #include "base/strings/string16.h"
     15 #include "ipc/ipc_listener.h"
     16 
     17 namespace base {
     18 class Thread;
     19 class TimeDelta;
     20 class WaitableEvent;
     21 }  // base
     22 
     23 namespace IPC {
     24 class Channel;
     25 }  // IPC
     26 
     27 // Simple IPC listener to run on setup utility size wait message with data about
     28 // environment from service process.
     29 class SetupListener : public IPC::Listener {
     30  public:
     31   static const char kXpsAvailableJsonValueName[];
     32   static const char kChromePathJsonValueName[];
     33   static const char kPrintersJsonValueName[];
     34   static const char kUserDataDirJsonValueName[];
     35   static const char kUserNameJsonValueName[];
     36   static const wchar_t kSetupPipeName[];
     37 
     38   explicit SetupListener(const base::string16& user);
     39   virtual ~SetupListener();
     40 
     41   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
     42   virtual void OnChannelError() OVERRIDE;
     43 
     44   bool WaitResponce(const base::TimeDelta& delta);
     45 
     46   const base::FilePath& chrome_path() const {
     47     return chrome_path_;
     48   }
     49 
     50   const base::FilePath& user_data_dir() const {
     51     return user_data_dir_;
     52   }
     53 
     54   const base::string16& user_name() const {
     55     return user_name_;
     56   }
     57 
     58   const std::vector<std::string>& printers() const {
     59     return printers_;
     60   }
     61 
     62   bool is_xps_available() const {
     63     return is_xps_available_;
     64   }
     65 
     66  private:
     67   void Disconnect();
     68   void Connect(const base::string16& user);
     69 
     70   base::FilePath chrome_path_;
     71   base::FilePath user_data_dir_;
     72   base::string16 user_name_;
     73   std::vector<std::string> printers_;
     74   bool is_xps_available_;
     75   bool succeded_;
     76 
     77   scoped_ptr<base::WaitableEvent> done_event_;
     78   scoped_ptr<base::Thread> ipc_thread_;
     79   scoped_ptr<IPC::Channel> channel_;
     80 };
     81 
     82 #endif  // CLOUD_PRINT_SERVICE_SETUP_LISTENER_H_
     83 
     84