diff options
author | gene@chromium.org <gene@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-04 20:54:35 +0000 |
---|---|---|
committer | gene@chromium.org <gene@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-04 20:54:35 +0000 |
commit | cf5dea543fbe1849bf29c24d84b9fdf2b0df0156 (patch) | |
tree | 2168e1fe7b0062c7422d5a06c92df371e2431ca4 /chrome/service | |
parent | 75dc4c35e277bf2e0d89ff18406142f26ca1c02f (diff) | |
download | chromium_src-cf5dea543fbe1849bf29c24d84b9fdf2b0df0156.zip chromium_src-cf5dea543fbe1849bf29c24d84b9fdf2b0df0156.tar.gz chromium_src-cf5dea543fbe1849bf29c24d84b9fdf2b0df0156.tar.bz2 |
Added wipeout functionality when Cloud Print Connector get disabled by user in settings.
This will unregister all local printers from the server.
TEST=Disable CLoud Print in Chrome and verify printers get unregistered.
Review URL: http://codereview.chromium.org/10373002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135420 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service')
-rw-r--r-- | chrome/service/cloud_print/cloud_print_connector.cc | 15 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_connector.h | 3 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_helpers.cc | 21 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_helpers.h | 8 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_helpers_unittest.cc | 7 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy.cc | 41 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy.h | 16 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy_backend.cc | 80 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy_backend.h | 8 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_wipeout.cc | 66 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_wipeout.h | 60 | ||||
-rw-r--r-- | chrome/service/cloud_print/job_status_updater.cc | 2 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_win.cc | 3 | ||||
-rw-r--r-- | chrome/service/cloud_print/printer_job_handler.cc | 2 | ||||
-rw-r--r-- | chrome/service/service_ipc_server.cc | 7 |
15 files changed, 301 insertions, 38 deletions
diff --git a/chrome/service/cloud_print/cloud_print_connector.cc b/chrome/service/cloud_print/cloud_print_connector.cc index 59845e8..85f3d07 100644 --- a/chrome/service/cloud_print/cloud_print_connector.cc +++ b/chrome/service/cloud_print/cloud_print_connector.cc @@ -72,12 +72,22 @@ void CloudPrintConnector::Stop() { print_server_watcher_.release(); print_system_.release(); } + request_ = NULL; } bool CloudPrintConnector::IsRunning() { return print_system_.get() != NULL; } +void CloudPrintConnector::GetPrinterIds(std::list<std::string>* printer_ids) { + DCHECK(printer_ids); + printer_ids->clear(); + for (JobHandlerMap::const_iterator iter = job_handler_map_.begin(); + iter != job_handler_map_.end(); ++iter) { + printer_ids->push_back(iter->first); + } +} + void CloudPrintConnector::RegisterPrinters( const printing::PrinterList& printers) { if (!IsRunning()) @@ -148,7 +158,7 @@ CloudPrintURLFetcher::ResponseAction CloudPrintConnector::OnRequestAuthError() { } std::string CloudPrintConnector::GetAuthHeader() { - return CloudPrintHelpers::GetCloudPrintAuthHeader(); + return CloudPrintHelpers::GetCloudPrintAuthHeaderFromStore(); } CloudPrintConnector::~CloudPrintConnector() {} @@ -460,7 +470,8 @@ void CloudPrintConnector::OnPrinterDelete(const std::string& printer_id) { // twice should be enough. // Bug: http://code.google.com/p/chromium/issues/detail?id=101850 GURL url = CloudPrintHelpers::GetUrlForPrinterDelete(cloud_print_server_url_, - printer_id); + printer_id, + "printer_deleted"); StartGetRequest(url, kCloudPrintAPIMaxRetryCount, &CloudPrintConnector::HandlePrinterDeleteResponse); diff --git a/chrome/service/cloud_print/cloud_print_connector.h b/chrome/service/cloud_print/cloud_print_connector.h index ae98499..2281f0f 100644 --- a/chrome/service/cloud_print/cloud_print_connector.h +++ b/chrome/service/cloud_print/cloud_print_connector.h @@ -44,6 +44,9 @@ class CloudPrintConnector void Stop(); bool IsRunning(); + // Return list of printer ids registered with CloudPrint. + void GetPrinterIds(std::list<std::string>* printer_ids); + // Register printer from the list. void RegisterPrinters(const printing::PrinterList& printers); diff --git a/chrome/service/cloud_print/cloud_print_helpers.cc b/chrome/service/cloud_print/cloud_print_helpers.cc index 3376f4c..0f60c47 100644 --- a/chrome/service/cloud_print/cloud_print_helpers.cc +++ b/chrome/service/cloud_print/cloud_print_helpers.cc @@ -58,12 +58,14 @@ GURL CloudPrintHelpers::GetUrlForPrinterUpdate( GURL CloudPrintHelpers::GetUrlForPrinterDelete( const GURL& cloud_print_server_url, - const std::string& printer_id) { + const std::string& printer_id, + const std::string& reason) { std::string path( cloud_print::AppendPathToUrl(cloud_print_server_url, "delete")); GURL::Replacements replacements; replacements.SetPathStr(path); - std::string query = StringPrintf("printerid=%s", printer_id.c_str()); + std::string query = StringPrintf("printerid=%s&reason=%s", + printer_id.c_str(), reason.c_str()); replacements.SetQueryStr(query); return cloud_print_server_url.ReplaceComponents(replacements); } @@ -215,18 +217,21 @@ bool CloudPrintHelpers::IsDryRunJob(const std::vector<std::string>& tags) { return false; } -std::string CloudPrintHelpers::GetCloudPrintAuthHeader() { - std::string header; +std::string CloudPrintHelpers::GetCloudPrintAuthHeaderFromStore() { CloudPrintTokenStore* token_store = CloudPrintTokenStore::current(); if (!token_store || token_store->token().empty()) { // Using LOG here for critical errors. GCP connector may run in the headless // mode and error indication might be useful for user in that case. LOG(ERROR) << "CP_PROXY: Missing OAuth token for request"; + return std::string(); } + return GetCloudPrintAuthHeader(token_store->token()); +} - if (token_store) { - header = "Authorization: OAuth "; - header += token_store->token(); - } +std::string CloudPrintHelpers::GetCloudPrintAuthHeader( + const std::string& auth_token) { + std::string header; + header = "Authorization: OAuth "; + header += auth_token; return header; } diff --git a/chrome/service/cloud_print/cloud_print_helpers.h b/chrome/service/cloud_print/cloud_print_helpers.h index 33887e4..2e750a2 100644 --- a/chrome/service/cloud_print/cloud_print_helpers.h +++ b/chrome/service/cloud_print/cloud_print_helpers.h @@ -24,7 +24,8 @@ class CloudPrintHelpers { static GURL GetUrlForPrinterUpdate(const GURL& cloud_print_server_url, const std::string& printer_id); static GURL GetUrlForPrinterDelete(const GURL& cloud_print_server_url, - const std::string& printer_id); + const std::string& printer_id, + const std::string& reason); static GURL GetUrlForPrinterList(const GURL& cloud_print_server_url, const std::string& proxy_id); static GURL GetUrlForJobFetch(const GURL& cloud_print_server_url, @@ -54,7 +55,10 @@ class CloudPrintHelpers { // Returns true is tags indicate a dry run (test) job. static bool IsDryRunJob(const std::vector<std::string>& tags); - static std::string GetCloudPrintAuthHeader(); + // Created CloudPrint auth header from the auth token stored in the store. + static std::string GetCloudPrintAuthHeaderFromStore(); + // Created CloudPrint auth header from the auth token. + static std::string GetCloudPrintAuthHeader(const std::string& auth_token); private: CloudPrintHelpers() {} diff --git a/chrome/service/cloud_print/cloud_print_helpers_unittest.cc b/chrome/service/cloud_print/cloud_print_helpers_unittest.cc index d9d0772..429b3f5 100644 --- a/chrome/service/cloud_print/cloud_print_helpers_unittest.cc +++ b/chrome/service/cloud_print/cloud_print_helpers_unittest.cc @@ -26,9 +26,10 @@ void CheckURLs(const GURL& server_base_url) { EXPECT_EQ(expected_url, url.spec()); url = CloudPrintHelpers::GetUrlForPrinterDelete(server_base_url, - "printeridbar"); - expected_url = base::StringPrintf("%sdelete?printerid=printeridbar", - expected_url_base.c_str()); + "printeridbar", "deleted"); + expected_url = base::StringPrintf( + "%sdelete?printerid=printeridbar&reason=deleted", + expected_url_base.c_str()); EXPECT_EQ(expected_url, url.spec()); url = CloudPrintHelpers::GetUrlForPrinterList(server_base_url, "demoproxy"); diff --git a/chrome/service/cloud_print/cloud_print_proxy.cc b/chrome/service/cloud_print/cloud_print_proxy.cc index 81f9114..516e780 100644 --- a/chrome/service/cloud_print/cloud_print_proxy.cc +++ b/chrome/service/cloud_print/cloud_print_proxy.cc @@ -62,7 +62,7 @@ CloudPrintProxy::CloudPrintProxy() CloudPrintProxy::~CloudPrintProxy() { DCHECK(CalledOnValidThread()); - Shutdown(); + ShutdownBackend(); } void CloudPrintProxy::Initialize(ServiceProcessPrefs* service_prefs, @@ -169,16 +169,28 @@ bool CloudPrintProxy::CreateBackend() { oauth_client_info.client_id = kDefaultCloudPrintOAuthClientId; oauth_client_info.client_secret = kDefaultCloudPrintOAuthClientSecret; - GURL cloud_print_server_url(cloud_print_server_url_str.c_str()); - DCHECK(cloud_print_server_url.is_valid()); + cloud_print_server_url_ = GURL(cloud_print_server_url_str.c_str()); + DCHECK(cloud_print_server_url_.is_valid()); backend_.reset(new CloudPrintProxyBackend(this, proxy_id_, - cloud_print_server_url, + cloud_print_server_url_, print_system_settings, oauth_client_info, enable_job_poll)); return true; } +void CloudPrintProxy::UnregisterPrintersAndDisableForUser() { + DCHECK(CalledOnValidThread()); + if (backend_.get()) { + // Try getting auth and printers info from the backend. + // We'll get notified in this case. + backend_->UnregisterPrinters(); + } else { + // If no backend avaialble, disable connector immidiately. + DisableForUser(); + } +} + void CloudPrintProxy::DisableForUser() { DCHECK(CalledOnValidThread()); user_email_.clear(); @@ -186,7 +198,7 @@ void CloudPrintProxy::DisableForUser() { if (client_) { client_->OnCloudPrintProxyDisabled(true); } - Shutdown(); + ShutdownBackend(); } void CloudPrintProxy::GetProxyInfo(cloud_print::CloudPrintProxyInfo* info) { @@ -228,6 +240,7 @@ void CloudPrintProxy::OnAuthenticated( void CloudPrintProxy::OnAuthenticationFailed() { DCHECK(CalledOnValidThread()); // If authenticated failed, we will disable the cloud print proxy. + // We can't delete printers at this point. DisableForUser(); // Also delete the cached robot credentials since they may not be valid any // longer. @@ -245,13 +258,27 @@ void CloudPrintProxy::OnAuthenticationFailed() { void CloudPrintProxy::OnPrintSystemUnavailable() { // If the print system is unavailable, we want to shutdown the proxy and // disable it non-persistently. - Shutdown(); + ShutdownBackend(); if (client_) { client_->OnCloudPrintProxyDisabled(false); } } -void CloudPrintProxy::Shutdown() { +void CloudPrintProxy::OnUnregisterPrinters( + const std::string& auth_token, + const std::list<std::string> printer_ids) { + ShutdownBackend(); + wipeout_.reset(new CloudPrintWipeout(this, cloud_print_server_url_)); + wipeout_->UnregisterPrinters(auth_token, printer_ids); +} + +void CloudPrintProxy::OnUnregisterPrintersComplete() { + wipeout_.reset(); + // Finish disabling cloud print for this user. + DisableForUser(); +} + +void CloudPrintProxy::ShutdownBackend() { DCHECK(CalledOnValidThread()); if (backend_.get()) backend_->Shutdown(); diff --git a/chrome/service/cloud_print/cloud_print_proxy.h b/chrome/service/cloud_print/cloud_print_proxy.h index 0fe6d9c..6816540 100644 --- a/chrome/service/cloud_print/cloud_print_proxy.h +++ b/chrome/service/cloud_print/cloud_print_proxy.h @@ -6,12 +6,14 @@ #define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_H_ #pragma once +#include <list> #include <string> #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/threading/non_thread_safe.h" #include "chrome/service/cloud_print/cloud_print_proxy_backend.h" +#include "chrome/service/cloud_print/cloud_print_wipeout.h" class ServiceProcessPrefs; @@ -22,6 +24,7 @@ struct CloudPrintProxyInfo; // CloudPrintProxy is the layer between the service process UI thread // and the cloud print proxy backend. class CloudPrintProxy : public CloudPrintProxyFrontend, + public CloudPrintWipeout::Client, public base::NonThreadSafe { public: class Client { @@ -43,6 +46,7 @@ class CloudPrintProxy : public CloudPrintProxyFrontend, const std::string& robot_auth_code, const std::string& robot_email, const std::string& user_email); + void UnregisterPrintersAndDisableForUser(); void DisableForUser(); // Returns the proxy info. void GetProxyInfo(cloud_print::CloudPrintProxyInfo* info); @@ -60,9 +64,15 @@ class CloudPrintProxy : public CloudPrintProxyFrontend, const std::string& user_email) OVERRIDE; virtual void OnAuthenticationFailed() OVERRIDE; virtual void OnPrintSystemUnavailable() OVERRIDE; + virtual void OnUnregisterPrinters( + const std::string& auth_token, + const std::list<std::string> printer_ids) OVERRIDE; + + // CloudPrintWipeout::Client implementation. + virtual void OnUnregisterPrintersComplete() OVERRIDE; protected: - void Shutdown(); + void ShutdownBackend(); bool CreateBackend(); // Our asynchronous backend to communicate with sync components living on @@ -83,6 +93,10 @@ class CloudPrintProxy : public CloudPrintProxyFrontend, // This is initialized after a successful call to one of the Enable* methods. // It is not cleared in DisableUser. std::string proxy_id_; + // Cloud Print server url. + GURL cloud_print_server_url_; + // This is a cleanup class for unregistering printers on proxy disable. + scoped_ptr<CloudPrintWipeout> wipeout_; DISALLOW_COPY_AND_ASSIGN(CloudPrintProxy); }; diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc index 40eb68e..e4cc182 100644 --- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc +++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc @@ -73,6 +73,7 @@ class CloudPrintProxyBackend::Core void DoShutdown(); void DoRegisterSelectedPrinters( const printing::PrinterList& printer_list); + void DoUnregisterPrinters(); // CloudPrintAuth::Client implementation. virtual void OnAuthenticationComplete( @@ -97,6 +98,9 @@ class CloudPrintProxyBackend::Core virtual ~Core() {} + void CreateAuthAndConnector(); + void DestroyAuthAndConnector(); + // NotifyXXX is how the Core communicates with the frontend across // threads. void NotifyPrinterListAvailable( @@ -107,6 +111,8 @@ class CloudPrintProxyBackend::Core const std::string& user_email); void NotifyAuthenticationFailed(); void NotifyPrintSystemUnavailable(); + void NotifyUnregisterPrinters(const std::string& auth_token, + const std::list<std::string> printer_ids); // Init XMPP channel void InitNotifications(const std::string& robot_email, @@ -132,6 +138,10 @@ class CloudPrintProxyBackend::Core GURL cloud_print_server_url_; // Proxy Id. std::string proxy_id_; + // Print system settings. + scoped_ptr<DictionaryValue> print_system_settings_; + // OAuth client info. + gaia::OAuthClientInfo oauth_client_info_; // Notification (xmpp) handler. scoped_ptr<notifier::TalkMediator> talk_mediator_; // Indicates whether XMPP notifications are currently enabled. @@ -234,6 +244,13 @@ void CloudPrintProxyBackend::Shutdown() { core_ = NULL; // Releases reference to core_. } +void CloudPrintProxyBackend::UnregisterPrinters() { + core_thread_.message_loop()->PostTask( + FROM_HERE, + base::Bind(&CloudPrintProxyBackend::Core::DoUnregisterPrinters, + core_.get())); +} + CloudPrintProxyBackend::Core::Core( CloudPrintProxyBackend* backend, const std::string& proxy_id, @@ -244,17 +261,35 @@ CloudPrintProxyBackend::Core::Core( : backend_(backend), cloud_print_server_url_(cloud_print_server_url), proxy_id_(proxy_id), + oauth_client_info_(oauth_client_info), job_poll_scheduled_(false), enable_job_poll_(enable_job_poll) { - auth_ = new CloudPrintAuth(this, - cloud_print_server_url, - print_system_settings, - oauth_client_info, - proxy_id); - connector_ = new CloudPrintConnector(this, - proxy_id, - cloud_print_server_url, - print_system_settings); + if (print_system_settings) { + // It is possible to have no print settings specified. + print_system_settings_.reset(print_system_settings->DeepCopy()); + } +} + +void CloudPrintProxyBackend::Core::CreateAuthAndConnector() { + if (!auth_.get()) { + auth_ = new CloudPrintAuth(this, + cloud_print_server_url_, + print_system_settings_.get(), + oauth_client_info_, + proxy_id_); + } + + if (!connector_.get()) { + connector_ = new CloudPrintConnector(this, + proxy_id_, + cloud_print_server_url_, + print_system_settings_.get()); + } +} + +void CloudPrintProxyBackend::Core::DestroyAuthAndConnector() { + auth_ = NULL; + connector_ = NULL; } void CloudPrintProxyBackend::Core::DoInitializeWithLsid( @@ -264,6 +299,7 @@ void CloudPrintProxyBackend::Core::DoInitializeWithLsid( const std::string& last_robot_email, const std::string& last_user_email) { DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); + CreateAuthAndConnector(); // Note: The GAIA login is synchronous but that should be OK because we are in // the CloudPrintProxyCoreThread and we cannot really do anything else until // the GAIA signin is successful. @@ -275,6 +311,7 @@ void CloudPrintProxyBackend::Core::DoInitializeWithToken( const std::string& cloud_print_token, const std::string& proxy_id) { DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); + CreateAuthAndConnector(); auth_->AuthenticateWithToken(cloud_print_token); } @@ -283,6 +320,7 @@ void CloudPrintProxyBackend::Core::DoInitializeWithRobotToken( const std::string& robot_email, const std::string& proxy_id) { DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); + CreateAuthAndConnector(); auth_->AuthenticateWithRobotToken(robot_oauth_refresh_token, robot_email); } @@ -291,6 +329,7 @@ void CloudPrintProxyBackend::Core::DoInitializeWithRobotAuthCode( const std::string& robot_email, const std::string& proxy_id) { DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); + CreateAuthAndConnector(); auth_->AuthenticateWithRobotAuthCode(robot_oauth_auth_code, robot_email); } @@ -379,6 +418,22 @@ void CloudPrintProxyBackend::Core::DoShutdown() { notifications_enabled_ = false; notifications_enabled_since_ = base::TimeTicks(); token_store_.reset(); + + DestroyAuthAndConnector(); +} + +void CloudPrintProxyBackend::Core::DoUnregisterPrinters() { + DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); + + std::string access_token = GetTokenStore()->token(); + + std::list<std::string> printer_ids; + connector_->GetPrinterIds(&printer_ids); + + backend_->frontend_loop_->PostTask( + FROM_HERE, + base::Bind(&Core::NotifyUnregisterPrinters, + this, access_token, printer_ids)); } void CloudPrintProxyBackend::Core::HandlePrinterNotification( @@ -440,6 +495,13 @@ void CloudPrintProxyBackend::Core::NotifyPrintSystemUnavailable() { backend_->frontend_->OnPrintSystemUnavailable(); } +void CloudPrintProxyBackend::Core::NotifyUnregisterPrinters( + const std::string& auth_token, + const std::list<std::string> printer_ids) { + DCHECK(MessageLoop::current() == backend_->frontend_loop_); + backend_->frontend_->OnUnregisterPrinters(auth_token, printer_ids); +} + void CloudPrintProxyBackend::Core::OnNotificationStateChange( bool notification_enabled) { DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.h b/chrome/service/cloud_print/cloud_print_proxy_backend.h index 1b465fd..1218438 100644 --- a/chrome/service/cloud_print/cloud_print_proxy_backend.h +++ b/chrome/service/cloud_print/cloud_print_proxy_backend.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -6,6 +6,7 @@ #define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_BACKEND_H_ #pragma once +#include <list> #include <string> #include "base/threading/thread.h" @@ -39,6 +40,10 @@ class CloudPrintProxyFrontend { virtual void OnAuthenticationFailed() = 0; // The print system could not be initialized. virtual void OnPrintSystemUnavailable() = 0; + // Receive auth token and list of printers. + virtual void OnUnregisterPrinters( + const std::string& auth_token, + const std::list<std::string> printer_ids) = 0; protected: // Don't delete through SyncFrontend interface. @@ -84,6 +89,7 @@ class CloudPrintProxyBackend { const std::string& proxy_id); void Shutdown(); void RegisterPrinters(const printing::PrinterList& printer_list); + void UnregisterPrinters(); private: // The real guts of SyncBackendHost, to keep the public client API clean. diff --git a/chrome/service/cloud_print/cloud_print_wipeout.cc b/chrome/service/cloud_print/cloud_print_wipeout.cc new file mode 100644 index 0000000..9824f82 --- /dev/null +++ b/chrome/service/cloud_print/cloud_print_wipeout.cc @@ -0,0 +1,66 @@ +// Copyright (c) 2012 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. + +#include "chrome/service/cloud_print/cloud_print_wipeout.h" + +#include "chrome/service/cloud_print/cloud_print_consts.h" +#include "chrome/service/cloud_print/cloud_print_helpers.h" + +const int kMaxWipeoutAttempts = 3; + +CloudPrintWipeout::CloudPrintWipeout(Client* client, + const GURL& cloud_print_server_url) + : client_(client), cloud_print_server_url_(cloud_print_server_url) { +} +CloudPrintWipeout::~CloudPrintWipeout() { +} + +void CloudPrintWipeout::UnregisterPrinters( + const std::string& auth_token, + const std::list<std::string>& printer_ids) { + auth_token_ = auth_token; + printer_ids_ = printer_ids; + UnregisterNextPrinter(); +} + +void CloudPrintWipeout::UnregisterNextPrinter() { + if (printer_ids_.empty()) { + client_->OnUnregisterPrintersComplete(); + return; + } + + std::string printer_id = printer_ids_.front(); + printer_ids_.pop_front(); + + GURL url = CloudPrintHelpers::GetUrlForPrinterDelete(cloud_print_server_url_, + printer_id, + "connector_disabled"); + request_ = new CloudPrintURLFetcher; + request_->StartGetRequest(url, this, kMaxWipeoutAttempts, std::string()); +} + +CloudPrintURLFetcher::ResponseAction CloudPrintWipeout::HandleJSONData( + const content::URLFetcher* source, + const GURL& url, + base::DictionaryValue* json_data, + bool succeeded) { + // We don't care if delete was sucessful or not here. + UnregisterNextPrinter(); + return CloudPrintURLFetcher::STOP_PROCESSING; +} + +void CloudPrintWipeout::OnRequestGiveUp() { + UnregisterNextPrinter(); +} + +CloudPrintURLFetcher::ResponseAction CloudPrintWipeout::OnRequestAuthError() { + // We can't recover from auth rrror. Report complition to stop service. + client_->OnUnregisterPrintersComplete(); + return CloudPrintURLFetcher::STOP_PROCESSING; +} + +std::string CloudPrintWipeout::GetAuthHeader() { + return CloudPrintHelpers::GetCloudPrintAuthHeader(auth_token_); +} + diff --git a/chrome/service/cloud_print/cloud_print_wipeout.h b/chrome/service/cloud_print/cloud_print_wipeout.h new file mode 100644 index 0000000..6c663b0 --- /dev/null +++ b/chrome/service/cloud_print/cloud_print_wipeout.h @@ -0,0 +1,60 @@ +// Copyright (c) 2012 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 CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_WIPEOUT_H_ +#define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_WIPEOUT_H_ +#pragma once + +#include <list> +#include <string> + +#include "base/basictypes.h" +#include "chrome/service/cloud_print/cloud_print_url_fetcher.h" +#include "googleurl/src/gurl.h" + +// CloudPrintWipeout unregisters list of printers from the cloudprint service. +class CloudPrintWipeout : public CloudPrintURLFetcherDelegate { + public: + class Client { + public: + virtual void OnUnregisterPrintersComplete() = 0; + protected: + virtual ~Client() {} + }; + + CloudPrintWipeout(Client* client, const GURL& cloud_print_server_url); + virtual ~CloudPrintWipeout(); + + void UnregisterPrinters(const std::string& auth_token, + const std::list<std::string>& printer_ids); + + // CloudPrintURLFetcher::Delegate implementation. + virtual CloudPrintURLFetcher::ResponseAction HandleJSONData( + const content::URLFetcher* source, + const GURL& url, + base::DictionaryValue* json_data, + bool succeeded) OVERRIDE; + virtual void OnRequestGiveUp() OVERRIDE; + virtual CloudPrintURLFetcher::ResponseAction OnRequestAuthError() OVERRIDE; + virtual std::string GetAuthHeader() OVERRIDE; + + private: + void UnregisterNextPrinter(); + + // CloudPrintWipeout client. + Client* client_; + // Cloud Print server url. + GURL cloud_print_server_url_; + // The CloudPrintURLFetcher instance for the current request. + scoped_refptr<CloudPrintURLFetcher> request_; + // Auth token. + std::string auth_token_; + // List of printer to unregister + std::list<std::string> printer_ids_; + + DISALLOW_COPY_AND_ASSIGN(CloudPrintWipeout); +}; + +#endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_WIPEOUT_H_ + diff --git a/chrome/service/cloud_print/job_status_updater.cc b/chrome/service/cloud_print/job_status_updater.cc index 7a7309c..984f6ae 100644 --- a/chrome/service/cloud_print/job_status_updater.cc +++ b/chrome/service/cloud_print/job_status_updater.cc @@ -98,7 +98,7 @@ CloudPrintURLFetcher::ResponseAction JobStatusUpdater::OnRequestAuthError() { } std::string JobStatusUpdater::GetAuthHeader() { - return CloudPrintHelpers::GetCloudPrintAuthHeader(); + return CloudPrintHelpers::GetCloudPrintAuthHeaderFromStore(); } JobStatusUpdater::~JobStatusUpdater() {} diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc index 3a38016..1509c77 100644 --- a/chrome/service/cloud_print/print_system_win.cc +++ b/chrome/service/cloud_print/print_system_win.cc @@ -39,7 +39,8 @@ class PrinterChangeHandleTraits { typedef HANDLE Handle; static bool CloseHandle(HANDLE handle) { - return ::FindClosePrinterChangeNotification(handle) != FALSE; + ::FindClosePrinterChangeNotification(handle); + return true; } static bool IsHandleValid(HANDLE handle) { diff --git a/chrome/service/cloud_print/printer_job_handler.cc b/chrome/service/cloud_print/printer_job_handler.cc index b071de4..cbbfa66 100644 --- a/chrome/service/cloud_print/printer_job_handler.cc +++ b/chrome/service/cloud_print/printer_job_handler.cc @@ -156,7 +156,7 @@ CloudPrintURLFetcher::ResponseAction PrinterJobHandler::OnRequestAuthError() { } std::string PrinterJobHandler::GetAuthHeader() { - return CloudPrintHelpers::GetCloudPrintAuthHeader(); + return CloudPrintHelpers::GetCloudPrintAuthHeaderFromStore(); } // JobStatusUpdater::Delegate implementation diff --git a/chrome/service/service_ipc_server.cc b/chrome/service/service_ipc_server.cc index 01b5deb..fc00655 100644 --- a/chrome/service/service_ipc_server.cc +++ b/chrome/service/service_ipc_server.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -139,7 +139,10 @@ void ServiceIPCServer::OnGetCloudPrintProxyInfo() { } void ServiceIPCServer::OnDisableCloudPrintProxy() { - g_service_process->GetCloudPrintProxy()->DisableForUser(); + // User disabled CloudPrint proxy explicitly. Delete printers + // registered from this proxy and disable proxy. + g_service_process->GetCloudPrintProxy()-> + UnregisterPrintersAndDisableForUser(); } void ServiceIPCServer::OnShutdown() { |