[Media Router] Add integration tests and e2e tests for media router and presentation...
[chromium-blink-merge.git] / chrome / service / cloud_print / cloud_print_proxy_backend.h
blob217f842075c81423cd50531de3385523bfe228e3
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_BACKEND_H_
6 #define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_BACKEND_H_
8 #include <list>
9 #include <string>
11 #include "base/threading/thread.h"
12 #include "chrome/service/cloud_print/connector_settings.h"
13 #include "printing/backend/print_backend.h"
15 namespace base {
16 class DictionaryValue;
19 namespace gaia {
20 struct OAuthClientInfo;
23 namespace cloud_print {
25 // CloudPrintProxyFrontend is the interface used by CloudPrintProxyBackend to
26 // communicate with the entity that created it and, presumably, is interested in
27 // cloud print proxy related activity.
28 // NOTE: All methods will be invoked by a CloudPrintProxyBackend on the same
29 // thread used to create that CloudPrintProxyBackend.
30 class CloudPrintProxyFrontend {
31 public:
32 CloudPrintProxyFrontend() {}
34 // We successfully authenticated with the cloud print server. This callback
35 // allows the frontend to persist the tokens.
36 virtual void OnAuthenticated(const std::string& robot_oauth_refresh_token,
37 const std::string& robot_email,
38 const std::string& user_email) = 0;
39 // We have invalid/expired credentials.
40 virtual void OnAuthenticationFailed() = 0;
41 // The print system could not be initialized.
42 virtual void OnPrintSystemUnavailable() = 0;
43 // Receive auth token and list of printers.
44 virtual void OnUnregisterPrinters(
45 const std::string& auth_token,
46 const std::list<std::string>& printer_ids) = 0;
47 // Update and store service settings.
48 virtual void OnXmppPingUpdated(int ping_timeout) = 0;
50 protected:
51 // Don't delete through SyncFrontend interface.
52 virtual ~CloudPrintProxyFrontend() {
54 private:
55 DISALLOW_COPY_AND_ASSIGN(CloudPrintProxyFrontend);
58 class CloudPrintProxyBackend {
59 public:
60 // It is OK for print_system_settings to be NULL. In this case system should
61 // use system default settings.
62 CloudPrintProxyBackend(CloudPrintProxyFrontend* frontend,
63 const ConnectorSettings& settings,
64 const gaia::OAuthClientInfo& oauth_client_info,
65 bool enable_job_poll);
66 ~CloudPrintProxyBackend();
68 // Legacy mechanism when we have saved user credentials but no saved robot
69 // credentials.
70 bool InitializeWithToken(const std::string& cloud_print_token);
71 // Called when we have saved robot credentials.
72 bool InitializeWithRobotToken(const std::string& robot_oauth_refresh_token,
73 const std::string& robot_email);
74 // Called when an external entity passed in the auth code for the robot.
75 bool InitializeWithRobotAuthCode(const std::string& robot_oauth_auth_code,
76 const std::string& robot_email);
77 void Shutdown();
78 void RegisterPrinters(const printing::PrinterList& printer_list);
79 void UnregisterPrinters();
81 private:
82 // The real guts of SyncBackendHost, to keep the public client API clean.
83 class Core;
84 // A thread we dedicate for use to perform initialization and
85 // authentication.
86 base::Thread core_thread_;
87 // Our core, which communicates with AuthWatcher for GAIA authentication and
88 // which contains printer registration code.
89 scoped_refptr<Core> core_;
90 // A reference to the MessageLoop used to construct |this|, so we know how
91 // to safely talk back to the SyncFrontend.
92 base::MessageLoop* const frontend_loop_;
93 // The frontend which is responsible for displaying UI and updating Prefs
94 CloudPrintProxyFrontend* frontend_;
96 friend class base::RefCountedThreadSafe<CloudPrintProxyBackend::Core>;
98 DISALLOW_COPY_AND_ASSIGN(CloudPrintProxyBackend);
101 } // namespace cloud_print
103 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_BACKEND_H_