Home | History | Annotate | Download | only in cloud_print
      1 // Copyright (c) 2011 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 CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_PROXY_SERVICE_H_
      6 #define CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_PROXY_SERVICE_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/memory/ref_counted.h"
     13 #include "base/observer_list.h"
     14 #include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h"
     15 
     16 class Profile;
     17 
     18 // Layer between the browser user interface and the cloud print proxy code
     19 // running in the service process.
     20 class CloudPrintProxyService
     21     : public CloudPrintSetupHandlerDelegate,
     22       public base::RefCountedThreadSafe<CloudPrintProxyService> {
     23  public:
     24   explicit CloudPrintProxyService(Profile* profile);
     25   virtual ~CloudPrintProxyService();
     26 
     27   // Initializes the object. This should be called every time an object of this
     28   // class is constructed.
     29   void Initialize();
     30 
     31   // Enables/disables cloud printing for the user
     32   virtual void EnableForUser(const std::string& lsid, const std::string& email);
     33   virtual void DisableForUser();
     34 
     35   // Query the service process for the status of the cloud print proxy and
     36   // update the browser prefs.
     37   void RefreshStatusFromService();
     38 
     39   bool ShowTokenExpiredNotification();
     40 
     41   // CloudPrintSetupHandler::Delegate implementation.
     42   virtual void OnCloudPrintSetupClosed();
     43 
     44  private:
     45   // NotificationDelegate implementation for the token expired notification.
     46   class TokenExpiredNotificationDelegate;
     47   friend class TokenExpiredNotificationDelegate;
     48 
     49   Profile* profile_;
     50   scoped_refptr<TokenExpiredNotificationDelegate> token_expired_delegate_;
     51   scoped_ptr<CloudPrintSetupHandler> cloud_print_setup_handler_;
     52 
     53   // Methods that send an IPC to the service.
     54   void RefreshCloudPrintProxyStatus();
     55   void EnableCloudPrintProxy(const std::string& lsid, const std::string& email);
     56   void DisableCloudPrintProxy();
     57 
     58   // Callback that gets the cloud print proxy status.
     59   void StatusCallback(bool enabled, std::string email);
     60   // Invoke a task that gets run after the service process successfully
     61   // launches. The task typically involves sending an IPC to the service
     62   // process.
     63   bool InvokeServiceTask(Task* task);
     64 
     65   void OnTokenExpiredNotificationError();
     66   void OnTokenExpiredNotificationClosed(bool by_user);
     67   void OnTokenExpiredNotificationClick();
     68   void TokenExpiredNotificationDone(bool keep_alive);
     69 
     70   DISALLOW_COPY_AND_ASSIGN(CloudPrintProxyService);
     71 };
     72 
     73 #endif  // CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_PROXY_SERVICE_H_
     74