Add GCMChannelStatusSyncer to schedule requests and enable/disable GCM
[chromium-blink-merge.git] / chrome / browser / printing / cloud_print / cloud_print_proxy_service.h
blobcef60be929c5823feae018bf5a452ab914115a9a
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.
5 #ifndef CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_PROXY_SERVICE_H_
6 #define CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_PROXY_SERVICE_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h"
15 #include "base/prefs/pref_change_registrar.h"
16 #include "components/keyed_service/core/keyed_service.h"
18 class Profile;
19 class ServiceProcessControl;
21 namespace base {
22 class DictionaryValue;
23 } // namespace base
25 namespace cloud_print {
26 struct CloudPrintProxyInfo;
27 } // namespace cloud_print
29 // Layer between the browser user interface and the cloud print proxy code
30 // running in the service process.
31 class CloudPrintProxyService : public KeyedService {
32 public:
33 explicit CloudPrintProxyService(Profile* profile);
34 virtual ~CloudPrintProxyService();
36 typedef base::Callback<void(const std::vector<std::string>&)>
37 PrintersCallback;
39 // Initializes the object. This should be called every time an object of this
40 // class is constructed.
41 void Initialize();
43 // Returns list of printer names available for registration.
44 void GetPrinters(const PrintersCallback& callback);
46 // Enables/disables cloud printing for the user
47 virtual void EnableForUserWithRobot(
48 const std::string& robot_auth_code,
49 const std::string& robot_email,
50 const std::string& user_email,
51 const base::DictionaryValue& user_settings);
52 virtual void DisableForUser();
54 // Query the service process for the status of the cloud print proxy and
55 // update the browser prefs.
56 void RefreshStatusFromService();
58 // Disable the service if the policy to do so is set, and once the
59 // disablement is verified, quit the browser. Returns true if the policy is
60 // not set or the connector was not enabled.
61 bool EnforceCloudPrintConnectorPolicyAndQuit();
63 std::string proxy_id() const { return proxy_id_; }
65 private:
66 // NotificationDelegate implementation for the token expired notification.
67 class TokenExpiredNotificationDelegate;
68 friend class TokenExpiredNotificationDelegate;
70 // Methods that send an IPC to the service.
71 void GetCloudPrintProxyPrinters(const PrintersCallback& callback);
72 void RefreshCloudPrintProxyStatus();
73 void EnableCloudPrintProxyWithRobot(
74 const std::string& robot_auth_code,
75 const std::string& robot_email,
76 const std::string& user_email,
77 const base::DictionaryValue* user_preferences);
78 void DisableCloudPrintProxy();
80 // Callback that gets the cloud print proxy info.
81 void ProxyInfoCallback(
82 const cloud_print::CloudPrintProxyInfo& proxy_info);
84 // Invoke a task that gets run after the service process successfully
85 // launches. The task typically involves sending an IPC to the service
86 // process.
87 bool InvokeServiceTask(const base::Closure& task);
89 // Checks the policy. Returns true if nothing needs to be done (the policy is
90 // not set or the connector is not enabled).
91 bool ApplyCloudPrintConnectorPolicy();
93 Profile* profile_;
94 std::string proxy_id_;
96 // Virtual for testing.
97 virtual ServiceProcessControl* GetServiceProcessControl();
99 // For watching for connector policy changes.
100 PrefChangeRegistrar pref_change_registrar_;
102 // If set, continue trying to disable the connector, and quit the process
103 // once successful.
104 bool enforcing_connector_policy_;
106 base::WeakPtrFactory<CloudPrintProxyService> weak_factory_;
108 DISALLOW_COPY_AND_ASSIGN(CloudPrintProxyService);
111 #endif // CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_PROXY_SERVICE_H_