Roll PDFium 6f34355..bca779d
[chromium-blink-merge.git] / chrome / service / cloud_print / cloud_print_proxy.h
blobd25d4fdf30063abfc53f7aaf20e383ab84df411f
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_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_H_
6 #define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_H_
8 #include <list>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "chrome/service/cloud_print/cloud_print_proxy_backend.h"
16 #include "chrome/service/cloud_print/cloud_print_wipeout.h"
18 class ServiceProcessPrefs;
20 namespace cloud_print {
22 struct CloudPrintProxyInfo;
24 // CloudPrintProxy is the layer between the service process UI thread
25 // and the cloud print proxy backend.
26 class CloudPrintProxy : public CloudPrintProxyFrontend,
27 public CloudPrintWipeout::Client,
28 public base::NonThreadSafe {
29 public:
30 class Client {
31 public:
32 virtual ~Client() {}
33 virtual void OnCloudPrintProxyEnabled(bool persist_state) {}
34 virtual void OnCloudPrintProxyDisabled(bool persist_state) {}
36 CloudPrintProxy();
37 ~CloudPrintProxy() override;
39 // Provides a CloudPrintProxy instance, which may be lazily instantiated.
40 class Provider {
41 public:
42 virtual CloudPrintProxy* GetCloudPrintProxy() = 0;
45 // Initializes the object. This should be called every time an object of this
46 // class is constructed.
47 void Initialize(ServiceProcessPrefs* service_prefs, Client* client);
49 // Enables/disables cloud printing for the user
50 void EnableForUser();
51 void EnableForUserWithRobot(
52 const std::string& robot_auth_code,
53 const std::string& robot_email,
54 const std::string& user_email,
55 const base::DictionaryValue& user_settings);
56 void UnregisterPrintersAndDisableForUser();
57 void DisableForUser();
58 // Returns the proxy info.
59 void GetProxyInfo(CloudPrintProxyInfo* info);
60 // Return accessible printers.
61 void GetPrinters(std::vector<std::string>* printers);
63 const std::string& user_email() const {
64 return user_email_;
67 // CloudPrintProxyFrontend implementation. Called on UI thread.
68 void OnAuthenticated(const std::string& robot_oauth_refresh_token,
69 const std::string& robot_email,
70 const std::string& user_email) override;
71 void OnAuthenticationFailed() override;
72 void OnPrintSystemUnavailable() override;
73 void OnUnregisterPrinters(const std::string& auth_token,
74 const std::list<std::string>& printer_ids) override;
75 void OnXmppPingUpdated(int ping_timeout) override;
77 // CloudPrintWipeout::Client implementation.
78 void OnUnregisterPrintersComplete() override;
80 protected:
81 void ShutdownBackend();
82 bool CreateBackend();
84 // Our asynchronous backend to communicate with sync components living on
85 // other threads.
86 scoped_ptr<CloudPrintProxyBackend> backend_;
87 // This class does not own this. It is guaranteed to remain valid for the
88 // lifetime of this class.
89 ServiceProcessPrefs* service_prefs_;
90 // This class does not own this. If non-NULL, It is guaranteed to remain
91 // valid for the lifetime of this class.
92 Client* client_;
93 // The email address of the account used to authenticate to the Cloud Print
94 // service.
95 std::string user_email_;
96 // This is set to true when the Cloud Print proxy is enabled and after
97 // successful authentication with the Cloud Print service.
98 bool enabled_;
99 // This is a cleanup class for unregistering printers on proxy disable.
100 scoped_ptr<CloudPrintWipeout> wipeout_;
102 DISALLOW_COPY_AND_ASSIGN(CloudPrintProxy);
105 } // namespace cloud_print
107 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_H_