summaryrefslogtreecommitdiffstats
path: root/cloud_print/service/win/service_controller.h
blob: ab95396678c49bc1093163cf99942094e0dcc003 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CLOUD_PRINT_SERVICE_SERVICE_CONTROLLER_H_
#define CLOUD_PRINT_SERVICE_SERVICE_CONTROLLER_H_

#include <atlbase.h>
#include <string>

#include "base/command_line.h"
#include "base/string16.h"
#include "cloud_print/resources.h"

namespace base {
class FilePath;
}  // base

class ServiceController {
 public:
  enum State {
    STATE_UNKNOWN = 0,
    STATE_NOT_FOUND,
    STATE_STOPPED,
    STATE_RUNNING,
  };

  DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CLOUDPRINTSERVICE,
                                    "{8013FB7C-2E3E-4992-B8BD-05C0C4AB0627}")

  explicit ServiceController(const string16& name);
  ~ServiceController();

  // Installs temporarily service to check pre-requirements.
  HRESULT InstallCheckService(const string16& user,
                              const string16& password,
                              const base::FilePath& user_data_dir);

  // Installs real service that will run connector.
  HRESULT InstallConnectorService(const string16& user,
                                  const string16& password,
                                  const base::FilePath& user_data_dir,
                                  bool enable_logging);

  HRESULT UninstallService();

  HRESULT StartService();
  HRESULT StopService();

  HRESULT UpdateBinaryPath();

  // Query service status and options. Results accessible with getters below.
  void UpdateState();
  State state() const { return state_; }
  const string16& user() const { return user_; }
  bool is_logging_enabled() const;

  base::FilePath GetBinary() const;

 private:
  HRESULT InstallService(const string16& user,
                         const string16& password,
                         bool auto_start,
                         const std::string& run_switch,
                         const base::FilePath& user_data_dir,
                         bool enable_logging);

  const string16 name_;
  State state_;
  string16 user_;
  bool is_logging_enabled_;
  CommandLine command_line_;
};

#endif  // CLOUD_PRINT_SERVICE_SERVICE_CONTROLLER_H_