diff options
author | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 16:59:11 +0000 |
---|---|---|
committer | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 16:59:11 +0000 |
commit | 7b2720bda84d6a798e68e08d23f667d8a060f193 (patch) | |
tree | a51d1da71bafee97d70edcc6362d113547f0d537 /chrome | |
parent | ab4306e4ffec234fb7e4e8aa887ac3bf0bcf3295 (diff) | |
download | chromium_src-7b2720bda84d6a798e68e08d23f667d8a060f193.zip chromium_src-7b2720bda84d6a798e68e08d23f667d8a060f193.tar.gz chromium_src-7b2720bda84d6a798e68e08d23f667d8a060f193.tar.bz2 |
RefCounted types should not have public destructors, chrome/ edition
BUG=123295
TEST=none
Review URL: http://codereview.chromium.org/10065040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133927 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
26 files changed, 460 insertions, 395 deletions
diff --git a/chrome/common/extensions/extension_permission_set.cc b/chrome/common/extensions/extension_permission_set.cc index 170d0ec5..1f51c72 100644 --- a/chrome/common/extensions/extension_permission_set.cc +++ b/chrome/common/extensions/extension_permission_set.cc @@ -145,13 +145,14 @@ ExtensionPermissionMessage::ExtensionPermissionMessage( : id_(id), message_(message) { } -ExtensionPermissionMessage::~ExtensionPermissionMessage() { -} +ExtensionPermissionMessage::~ExtensionPermissionMessage() {} // // ExtensionPermission // +ExtensionAPIPermission::~ExtensionAPIPermission() {} + ExtensionPermissionMessage ExtensionAPIPermission::GetMessage() const { return ExtensionPermissionMessage( message_id_, l10n_util::GetStringUTF16(l10n_message_id_)); @@ -169,8 +170,6 @@ ExtensionAPIPermission::ExtensionAPIPermission( l10n_message_id_(l10n_message_id), message_id_(message_id) {} -ExtensionAPIPermission::~ExtensionAPIPermission() {} - // static void ExtensionAPIPermission::RegisterAllPermissions( ExtensionPermissionsInfo* info) { @@ -405,7 +404,8 @@ ExtensionPermissionsInfo::ExtensionPermissionsInfo() } void ExtensionPermissionsInfo::RegisterAlias( - const char* name, const char* alias) { + const char* name, + const char* alias) { DCHECK(name_map_.find(name) != name_map_.end()); DCHECK(name_map_.find(alias) == name_map_.end()); name_map_[alias] = name_map_[name]; @@ -435,8 +435,7 @@ ExtensionAPIPermission* ExtensionPermissionsInfo::RegisterPermission( // ExtensionPermissionSet // -ExtensionPermissionSet::ExtensionPermissionSet() { -} +ExtensionPermissionSet::ExtensionPermissionSet() {} ExtensionPermissionSet::ExtensionPermissionSet( const Extension* extension, @@ -479,8 +478,6 @@ ExtensionPermissionSet::ExtensionPermissionSet( InitEffectiveHosts(); } -ExtensionPermissionSet::~ExtensionPermissionSet() {} - // static ExtensionPermissionSet* ExtensionPermissionSet::CreateDifference( const ExtensionPermissionSet* set1, @@ -801,6 +798,8 @@ bool ExtensionPermissionSet::HasLessPrivilegesThan( return false; } +ExtensionPermissionSet::~ExtensionPermissionSet() {} + // static std::set<std::string> ExtensionPermissionSet::GetDistinctHosts( const URLPatternSet& host_patterns, @@ -855,13 +854,6 @@ std::set<std::string> ExtensionPermissionSet::GetDistinctHosts( return distinct_hosts; } -void ExtensionPermissionSet::InitEffectiveHosts() { - effective_hosts_.ClearPatterns(); - - URLPatternSet::CreateUnion( - explicit_hosts(), scriptable_hosts(), &effective_hosts_); -} - void ExtensionPermissionSet::InitImplicitExtensionPermissions( const Extension* extension) { // Add the implied permissions. @@ -882,6 +874,13 @@ void ExtensionPermissionSet::InitImplicitExtensionPermissions( } } +void ExtensionPermissionSet::InitEffectiveHosts() { + effective_hosts_.ClearPatterns(); + + URLPatternSet::CreateUnion( + explicit_hosts(), scriptable_hosts(), &effective_hosts_); +} + std::set<ExtensionPermissionMessage> ExtensionPermissionSet::GetSimplePermissionMessages() const { std::set<ExtensionPermissionMessage> messages; diff --git a/chrome/common/extensions/extension_permission_set.h b/chrome/common/extensions/extension_permission_set.h index 1016fbf..79e8742f 100644 --- a/chrome/common/extensions/extension_permission_set.h +++ b/chrome/common/extensions/extension_permission_set.h @@ -196,9 +196,6 @@ class ExtensionAPIPermission { // Instances should only be constructed from within ExtensionPermissionsInfo. friend class ExtensionPermissionsInfo; - // Register ALL the permissions! - static void RegisterAllPermissions(ExtensionPermissionsInfo* info); - explicit ExtensionAPIPermission( ID id, const char* name, @@ -206,6 +203,9 @@ class ExtensionAPIPermission { ExtensionPermissionMessage::ID message_id, int flags); + // Register ALL the permissions! + static void RegisterAllPermissions(ExtensionPermissionsInfo* info); + ID id_; const char* name_; int flags_; @@ -307,8 +307,6 @@ class ExtensionPermissionSet // Creates a new permission set containing only oauth scopes. explicit ExtensionPermissionSet(const ExtensionOAuth2Scopes& scopes); - ~ExtensionPermissionSet(); - // Creates a new permission set equal to |set1| - |set2|, passing ownership of // the new set to the caller. static ExtensionPermissionSet* CreateDifference( @@ -400,9 +398,10 @@ class ExtensionPermissionSet private: FRIEND_TEST_ALL_PREFIXES(ExtensionPermissionsTest, HasLessHostPrivilegesThan); - friend class base::RefCountedThreadSafe<ExtensionPermissionSet>; + ~ExtensionPermissionSet(); + static std::set<std::string> GetDistinctHosts( const URLPatternSet& host_patterns, bool include_rcd, diff --git a/chrome/common/json_pref_store.cc b/chrome/common/json_pref_store.cc index 488d7c7..65f4e10 100644 --- a/chrome/common/json_pref_store.cc +++ b/chrome/common/json_pref_store.cc @@ -79,6 +79,7 @@ class FileThreadDeserializer private: friend class base::RefCountedThreadSafe<FileThreadDeserializer>; + ~FileThreadDeserializer() {} bool no_dir_; PersistentPrefStore::PrefReadError error_; @@ -148,10 +149,6 @@ JsonPrefStore::JsonPrefStore(const FilePath& filename, read_error_(PREF_READ_ERROR_OTHER) { } -JsonPrefStore::~JsonPrefStore() { - CommitPendingWrite(); -} - PrefStore::ReadResult JsonPrefStore::GetValue(const std::string& key, const Value** result) const { Value* tmp = NULL; @@ -224,6 +221,45 @@ PersistentPrefStore::PrefReadError JsonPrefStore::GetReadError() const { return read_error_; } +PersistentPrefStore::PrefReadError JsonPrefStore::ReadPrefs() { + if (path_.empty()) { + OnFileRead(NULL, PREF_READ_ERROR_FILE_NOT_SPECIFIED, false); + return PREF_READ_ERROR_FILE_NOT_SPECIFIED; + } + + PrefReadError error; + bool no_dir; + Value* value = FileThreadDeserializer::DoReading(path_, &error, &no_dir); + OnFileRead(value, error, no_dir); + return error; +} + +void JsonPrefStore::ReadPrefsAsync(ReadErrorDelegate *error_delegate) { + initialized_ = false; + error_delegate_.reset(error_delegate); + if (path_.empty()) { + OnFileRead(NULL, PREF_READ_ERROR_FILE_NOT_SPECIFIED, false); + return; + } + + // Start async reading of the preferences file. It will delete itself + // in the end. + scoped_refptr<FileThreadDeserializer> deserializer( + new FileThreadDeserializer(this, file_message_loop_proxy_.get())); + deserializer->Start(path_); +} + +void JsonPrefStore::CommitPendingWrite() { + if (writer_.HasPendingWrite() && !read_only_) + writer_.DoScheduledWrite(); +} + +void JsonPrefStore::ReportValueChanged(const std::string& key) { + FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key)); + if (!read_only_) + writer_.ScheduleWrite(this); +} + void JsonPrefStore::OnFileRead(Value* value_owned, PersistentPrefStore::PrefReadError error, bool no_dir) { @@ -269,43 +305,8 @@ void JsonPrefStore::OnFileRead(Value* value_owned, OnInitializationCompleted(true)); } -void JsonPrefStore::ReadPrefsAsync(ReadErrorDelegate *error_delegate) { - initialized_ = false; - error_delegate_.reset(error_delegate); - if (path_.empty()) { - OnFileRead(NULL, PREF_READ_ERROR_FILE_NOT_SPECIFIED, false); - return; - } - - // Start async reading of the preferences file. It will delete itself - // in the end. - scoped_refptr<FileThreadDeserializer> deserializer( - new FileThreadDeserializer(this, file_message_loop_proxy_.get())); - deserializer->Start(path_); -} - -PersistentPrefStore::PrefReadError JsonPrefStore::ReadPrefs() { - if (path_.empty()) { - OnFileRead(NULL, PREF_READ_ERROR_FILE_NOT_SPECIFIED, false); - return PREF_READ_ERROR_FILE_NOT_SPECIFIED; - } - - PrefReadError error; - bool no_dir; - Value* value = FileThreadDeserializer::DoReading(path_, &error, &no_dir); - OnFileRead(value, error, no_dir); - return error; -} - -void JsonPrefStore::CommitPendingWrite() { - if (writer_.HasPendingWrite() && !read_only_) - writer_.DoScheduledWrite(); -} - -void JsonPrefStore::ReportValueChanged(const std::string& key) { - FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key)); - if (!read_only_) - writer_.ScheduleWrite(this); +JsonPrefStore::~JsonPrefStore() { + CommitPendingWrite(); } bool JsonPrefStore::SerializeData(std::string* output) { diff --git a/chrome/common/json_pref_store.h b/chrome/common/json_pref_store.h index 21198cc..9f71a0e 100644 --- a/chrome/common/json_pref_store.h +++ b/chrome/common/json_pref_store.h @@ -33,7 +33,6 @@ class JsonPrefStore : public PersistentPrefStore, // file I/O can be done. JsonPrefStore(const FilePath& pref_filename, base::MessageLoopProxy* file_message_loop_proxy); - virtual ~JsonPrefStore(); // PrefStore overrides: virtual ReadResult GetValue(const std::string& key, @@ -65,6 +64,8 @@ class JsonPrefStore : public PersistentPrefStore, void OnFileRead(base::Value* value_owned, PrefReadError error, bool no_dir); private: + virtual ~JsonPrefStore(); + // ImportantFileWriter::DataSerializer overrides: virtual bool SerializeData(std::string* output) OVERRIDE; diff --git a/chrome/common/net/gaia/gaia_oauth_client.cc b/chrome/common/net/gaia/gaia_oauth_client.cc index eb4179d..d657b3f 100644 --- a/chrome/common/net/gaia/gaia_oauth_client.cc +++ b/chrome/common/net/gaia/gaia_oauth_client.cc @@ -34,8 +34,6 @@ class GaiaOAuthClient::Core request_context_getter_(request_context_getter), delegate_(NULL) {} - virtual ~Core() { } - void GetTokensFromAuthCode(const OAuthClientInfo& oauth_client_info, const std::string& auth_code, int max_retries, @@ -49,6 +47,9 @@ class GaiaOAuthClient::Core virtual void OnURLFetchComplete(const content::URLFetcher* source); private: + friend class base::RefCountedThreadSafe<Core>; + virtual ~Core() {} + void MakeGaiaRequest(std::string post_body, int max_retries, GaiaOAuthClient::Delegate* delegate); diff --git a/chrome/common/persistent_pref_store.h b/chrome/common/persistent_pref_store.h index 8b8b87b..9408344 100644 --- a/chrome/common/persistent_pref_store.h +++ b/chrome/common/persistent_pref_store.h @@ -15,8 +15,6 @@ // the data to some backing store. class PersistentPrefStore : public PrefStore { public: - virtual ~PersistentPrefStore() {} - // Unique integer code for each type of error so we can report them // distinctly in a histogram. // NOTE: Don't change the order here as it will change the server's meaning @@ -89,6 +87,9 @@ class PersistentPrefStore : public PrefStore { // Lands any pending writes to disk. virtual void CommitPendingWrite() = 0; + + protected: + virtual ~PersistentPrefStore() {} }; #endif // CHROME_COMMON_PERSISTENT_PREF_STORE_H_ diff --git a/chrome/common/service_process_util_mac.mm b/chrome/common/service_process_util_mac.mm index 4100bcb..72f0f21 100644 --- a/chrome/common/service_process_util_mac.mm +++ b/chrome/common/service_process_util_mac.mm @@ -75,13 +75,14 @@ bool RemoveFromLaunchd() { class ExecFilePathWatcherDelegate : public FilePathWatcher::Delegate { public: - ExecFilePathWatcherDelegate() { } - virtual ~ExecFilePathWatcherDelegate() { } + ExecFilePathWatcherDelegate() {} bool Init(const FilePath& path); virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; private: + virtual ~ExecFilePathWatcherDelegate() {} + FSRef executable_fsref_; }; diff --git a/chrome/service/cloud_print/cloud_print_auth.cc b/chrome/service/cloud_print/cloud_print_auth.cc index 53e263d..c8032c9 100644 --- a/chrome/service/cloud_print/cloud_print_auth.cc +++ b/chrome/service/cloud_print/cloud_print_auth.cc @@ -31,9 +31,6 @@ CloudPrintAuth::CloudPrintAuth( } } -CloudPrintAuth::~CloudPrintAuth() { -} - void CloudPrintAuth::AuthenticateWithLsid( const std::string& lsid, const std::string& last_robot_refresh_token, @@ -203,3 +200,5 @@ std::string CloudPrintAuth::GetAuthHeader() { return header; } +CloudPrintAuth::~CloudPrintAuth() {} + diff --git a/chrome/service/cloud_print/cloud_print_auth.h b/chrome/service/cloud_print/cloud_print_auth.h index 1fb3336..b0df145 100644 --- a/chrome/service/cloud_print/cloud_print_auth.h +++ b/chrome/service/cloud_print/cloud_print_auth.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. @@ -41,7 +41,6 @@ class CloudPrintAuth const base::DictionaryValue* print_sys_settings, const gaia::OAuthClientInfo& oauth_client_info, const std::string& proxy_id); - virtual ~CloudPrintAuth(); // Note: // @@ -83,6 +82,9 @@ class CloudPrintAuth virtual std::string GetAuthHeader() OVERRIDE; private: + friend class base::RefCountedThreadSafe<CloudPrintAuth>; + virtual ~CloudPrintAuth(); + Client* client_; gaia::OAuthClientInfo oauth_client_info_; scoped_ptr<gaia::GaiaOAuthClient> oauth_client_; diff --git a/chrome/service/cloud_print/cloud_print_connector.cc b/chrome/service/cloud_print/cloud_print_connector.cc index 244babf..59845e8 100644 --- a/chrome/service/cloud_print/cloud_print_connector.cc +++ b/chrome/service/cloud_print/cloud_print_connector.cc @@ -34,9 +34,6 @@ CloudPrintConnector::CloudPrintConnector( } } -CloudPrintConnector::~CloudPrintConnector() { -} - bool CloudPrintConnector::Start() { DCHECK(!print_system_.get()); VLOG(1) << "CP_CONNECTOR: Starting connector, id: " << proxy_id_; @@ -145,6 +142,17 @@ CloudPrintURLFetcher::ResponseAction CloudPrintConnector::HandleJSONData( return (this->*next_response_handler_)(source, url, json_data, succeeded); } +CloudPrintURLFetcher::ResponseAction CloudPrintConnector::OnRequestAuthError() { + OnAuthError(); + return CloudPrintURLFetcher::STOP_PROCESSING; +} + +std::string CloudPrintConnector::GetAuthHeader() { + return CloudPrintHelpers::GetCloudPrintAuthHeader(); +} + +CloudPrintConnector::~CloudPrintConnector() {} + CloudPrintURLFetcher::ResponseAction CloudPrintConnector::HandlePrinterListResponse( const content::URLFetcher* source, @@ -246,15 +254,6 @@ CloudPrintConnector::HandleRegisterPrinterResponse( } -CloudPrintURLFetcher::ResponseAction CloudPrintConnector::OnRequestAuthError() { - OnAuthError(); - return CloudPrintURLFetcher::STOP_PROCESSING; -} - -std::string CloudPrintConnector::GetAuthHeader() { - return CloudPrintHelpers::GetCloudPrintAuthHeader(); -} - void CloudPrintConnector::StartGetRequest(const GURL& url, int max_retries, ResponseHandler handler) { @@ -409,6 +408,18 @@ void CloudPrintConnector::ProcessPendingTask() { } } +void CloudPrintConnector::ContinuePendingTaskProcessing() { + if (pending_tasks_.size() == 0) + return; // No pending tasks. + + // Delete current task and repost if we have more task available. + pending_tasks_.pop_front(); + if (pending_tasks_.size() != 0) { + MessageLoop::current()->PostTask( + FROM_HERE, base::Bind(&CloudPrintConnector::ProcessPendingTask, this)); + } +} + void CloudPrintConnector::OnPrintersAvailable() { GURL printer_list_url = CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_, @@ -455,18 +466,6 @@ void CloudPrintConnector::OnPrinterDelete(const std::string& printer_id) { &CloudPrintConnector::HandlePrinterDeleteResponse); } -void CloudPrintConnector::ContinuePendingTaskProcessing() { - if (pending_tasks_.size() == 0) - return; // No pending tasks. - - // Delete current task and repost if we have more task available. - pending_tasks_.pop_front(); - if (pending_tasks_.size() != 0) { - MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(&CloudPrintConnector::ProcessPendingTask, this)); - } -} - void CloudPrintConnector::OnReceivePrinterCaps( bool succeeded, const std::string& printer_name, diff --git a/chrome/service/cloud_print/cloud_print_connector.h b/chrome/service/cloud_print/cloud_print_connector.h index a734b21..ae98499 100644 --- a/chrome/service/cloud_print/cloud_print_connector.h +++ b/chrome/service/cloud_print/cloud_print_connector.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. @@ -39,7 +39,6 @@ class CloudPrintConnector const std::string& proxy_id, const GURL& cloud_print_server_url, const DictionaryValue* print_system_settings); - virtual ~CloudPrintConnector(); bool Start(); void Stop(); @@ -63,7 +62,6 @@ class CloudPrintConnector const content::URLFetcher* source, const GURL& url, const std::string& data) OVERRIDE; - virtual CloudPrintURLFetcher::ResponseAction HandleJSONData( const content::URLFetcher* source, const GURL& url, @@ -73,6 +71,8 @@ class CloudPrintConnector virtual std::string GetAuthHeader() OVERRIDE; private: + friend class base::RefCountedThreadSafe<CloudPrintConnector>; + // Prototype for a response handler. typedef CloudPrintURLFetcher::ResponseAction (CloudPrintConnector::*ResponseHandler)( @@ -81,6 +81,26 @@ class CloudPrintConnector DictionaryValue* json_data, bool succeeded); + enum PendingTaskType { + PENDING_PRINTERS_NONE, + PENDING_PRINTERS_AVAILABLE, + PENDING_PRINTER_REGISTER, + PENDING_PRINTER_DELETE + }; + + // TODO(jhawkins): This name conflicts with base::PendingTask. + struct PendingTask { + PendingTaskType type; + // Optional members, depending on type. + std::string printer_id; // For pending delete. + printing::PrinterBasicInfo printer_info; // For pending registration. + + PendingTask() : type(PENDING_PRINTERS_NONE) {} + ~PendingTask() {} + }; + + virtual ~CloudPrintConnector(); + // Begin response handlers CloudPrintURLFetcher::ResponseAction HandlePrinterListResponse( const content::URLFetcher* source, @@ -120,24 +140,6 @@ class CloudPrintConnector void InitJobHandlerForPrinter(DictionaryValue* printer_data); - enum PendingTaskType { - PENDING_PRINTERS_NONE, - PENDING_PRINTERS_AVAILABLE, - PENDING_PRINTER_REGISTER, - PENDING_PRINTER_DELETE - }; - - // TODO(jhawkins): This name conflicts with base::PendingTask. - struct PendingTask { - PendingTaskType type; - // Optional members, depending on type. - std::string printer_id; // For pending delete. - printing::PrinterBasicInfo printer_info; // For pending registration. - - PendingTask() : type(PENDING_PRINTERS_NONE) {} - ~PendingTask() {} - }; - void AddPendingAvailableTask(); void AddPendingDeleteTask(const std::string& id); void AddPendingRegisterTask(const printing::PrinterBasicInfo& info); diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc index 21c5c00..40eb68e 100644 --- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc +++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc @@ -93,6 +93,10 @@ class CloudPrintProxyBackend::Core virtual void OnOutgoingNotification(); private: + friend class base::RefCountedThreadSafe<Core>; + + virtual ~Core() {} + // NotifyXXX is how the Core communicates with the frontend across // threads. void NotifyPrinterListAvailable( diff --git a/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc b/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc index 5103ec8..ebe768f 100644 --- a/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc +++ b/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc @@ -51,7 +51,10 @@ class TestCloudPrintURLFetcher : public CloudPrintURLFetcher { return new TrackingTestURLRequestContextGetter( io_message_loop_proxy_.get()); } + private: + virtual ~TestCloudPrintURLFetcher() {} + scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; }; diff --git a/chrome/service/cloud_print/job_status_updater.cc b/chrome/service/cloud_print/job_status_updater.cc index 81de7b1..7a7309c 100644 --- a/chrome/service/cloud_print/job_status_updater.cc +++ b/chrome/service/cloud_print/job_status_updater.cc @@ -26,8 +26,6 @@ JobStatusUpdater::JobStatusUpdater(const std::string& printer_name, DCHECK(delegate_); } -JobStatusUpdater::~JobStatusUpdater() {} - // Start checking the status of the local print job. void JobStatusUpdater::UpdateStatus() { // It does not matter if we had already sent out an update and are waiting for @@ -103,3 +101,4 @@ std::string JobStatusUpdater::GetAuthHeader() { return CloudPrintHelpers::GetCloudPrintAuthHeader(); } +JobStatusUpdater::~JobStatusUpdater() {} diff --git a/chrome/service/cloud_print/job_status_updater.h b/chrome/service/cloud_print/job_status_updater.h index a6ad103..190eb7d 100644 --- a/chrome/service/cloud_print/job_status_updater.h +++ b/chrome/service/cloud_print/job_status_updater.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. @@ -38,7 +38,6 @@ class JobStatusUpdater : public base::RefCountedThreadSafe<JobStatusUpdater>, const GURL& cloud_print_server_url, cloud_print::PrintSystem* print_system, Delegate* delegate); - virtual ~JobStatusUpdater(); // Checks the status of the local print job and sends an update. void UpdateStatus(); @@ -54,6 +53,9 @@ class JobStatusUpdater : public base::RefCountedThreadSafe<JobStatusUpdater>, virtual std::string GetAuthHeader() OVERRIDE; private: + friend class base::RefCountedThreadSafe<JobStatusUpdater>; + virtual ~JobStatusUpdater(); + std::string printer_name_; std::string job_id_; cloud_print::PlatformJobId local_job_id_; diff --git a/chrome/service/cloud_print/print_system.h b/chrome/service/cloud_print/print_system.h index f1ba324..3f35cf2 100644 --- a/chrome/service/cloud_print/print_system.h +++ b/chrome/service/cloud_print/print_system.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. @@ -84,9 +84,12 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { virtual ~Delegate() {} }; - virtual ~PrintServerWatcher(); virtual bool StartWatching(PrintServerWatcher::Delegate* delegate) = 0; virtual bool StopWatching() = 0; + + protected: + friend class base::RefCountedThreadSafe<PrintServerWatcher>; + virtual ~PrintServerWatcher(); }; class PrinterWatcher : public base::RefCountedThreadSafe<PrinterWatcher> { @@ -102,11 +105,14 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { virtual ~Delegate() {} }; - virtual ~PrinterWatcher(); virtual bool StartWatching(PrinterWatcher::Delegate* delegate) = 0; virtual bool StopWatching() = 0; virtual bool GetCurrentPrinterInfo( printing::PrinterBasicInfo* printer_info) = 0; + + protected: + friend class base::RefCountedThreadSafe<PrinterWatcher>; + virtual ~PrinterWatcher(); }; class JobSpooler : public base::RefCountedThreadSafe<JobSpooler> { @@ -119,7 +125,6 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { virtual void OnJobSpoolFailed() = 0; }; - virtual ~JobSpooler(); // Spool job to the printer asynchronously. Caller will be notified via // |delegate|. Note that only one print job can be in progress at any given // time. Subsequent calls to Spool (before the Delegate::OnJobSpoolSucceeded @@ -131,6 +136,9 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { const std::string& job_title, const std::vector<std::string>& tags, JobSpooler::Delegate* delegate) = 0; + protected: + friend class base::RefCountedThreadSafe<JobSpooler>; + virtual ~JobSpooler(); }; class PrintSystemResult { @@ -141,10 +149,10 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { std::string message() const { return message_; } private: + PrintSystemResult() {} + bool succeeded_; std::string message_; - - PrintSystemResult() { } }; typedef base::Callback<void(bool, @@ -152,8 +160,6 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { const printing::PrinterCapsAndDefaults&)> PrinterCapsAndDefaultsCallback; - virtual ~PrintSystem(); - // Initialize print system. This need to be called before any other function // of PrintSystem. virtual PrintSystemResult Init() = 0; @@ -199,6 +205,10 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { // Return NULL if no print system available. static scoped_refptr<PrintSystem> CreateInstance( const base::DictionaryValue* print_system_settings); + + protected: + friend class base::RefCountedThreadSafe<PrintSystem>; + virtual ~PrintSystem(); }; diff --git a/chrome/service/cloud_print/print_system_cups.cc b/chrome/service/cloud_print/print_system_cups.cc index cbaf2cd..cb69be6 100644 --- a/chrome/service/cloud_print/print_system_cups.cc +++ b/chrome/service/cloud_print/print_system_cups.cc @@ -127,6 +127,8 @@ class PrintSystemCUPS : public PrintSystem { } private: + virtual ~PrintSystemCUPS() {} + // Following functions are wrappers around corresponding CUPS functions. // <functions>2() are called when print server is specified, and plain // version in another case. There is an issue specifing CUPS_HTTP_DEFAULT @@ -173,9 +175,6 @@ class PrintServerWatcherCUPS : print_system_(print_system), delegate_(NULL) { } - ~PrintServerWatcherCUPS() { - StopWatching(); - } // PrintSystem::PrintServerWatcher implementation. virtual bool StartWatching( @@ -209,6 +208,11 @@ class PrintServerWatcherCUPS print_system_->GetUpdateTimeout()); } + protected: + virtual ~PrintServerWatcherCUPS() { + StopWatching(); + } + private: std::string GetPrintersHash() { printing::PrinterList printer_list; @@ -245,10 +249,6 @@ class PrinterWatcherCUPS print_system_(print_system) { } - ~PrinterWatcherCUPS() { - StopWatching(); - } - // PrintSystem::PrinterWatcher implementation. virtual bool StartWatching( PrintSystem::PrinterWatcher::Delegate* delegate) OVERRIDE{ @@ -320,6 +320,11 @@ class PrinterWatcherCUPS print_system_->GetUpdateTimeout()); } + protected: + virtual ~PrinterWatcherCUPS() { + StopWatching(); + } + private: std::string GetSettingsHash() { printing::PrinterBasicInfo info; @@ -387,6 +392,9 @@ class JobSpoolerCUPS : public PrintSystem::JobSpooler { delegate->OnJobSpoolFailed(); } + protected: + virtual ~JobSpoolerCUPS() {} + private: scoped_refptr<PrintSystemCUPS> print_system_; diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc index b9d5c52..7ae902c 100644 --- a/chrome/service/cloud_print/print_system_win.cc +++ b/chrome/service/cloud_print/print_system_win.cc @@ -290,6 +290,9 @@ class PrintSystemWin : public PrintSystem { virtual void OnPrinterChanged() OVERRIDE {} virtual void OnJobChanged() OVERRIDE {} + protected: + virtual ~PrintServerWatcherWin() {} + private: PrintSystem::PrintServerWatcher::Delegate* delegate_; PrintSystemWatcherWin watcher_; @@ -338,6 +341,9 @@ class PrintSystemWin : public PrintSystem { delegate_->OnJobChanged(); } + protected: + virtual ~PrinterWatcherWin() {} + private: std::string printer_name_; PrintSystem::PrinterWatcher::Delegate* delegate_; @@ -368,6 +374,9 @@ class PrintSystemWin : public PrintSystem { delegate); } + protected: + virtual ~JobSpoolerWin() {} + private: // We use a Core class because we want a separate RefCountedThreadSafe // implementation for ServiceUtilityProcessHost::Client. diff --git a/chrome/service/cloud_print/printer_job_handler.cc b/chrome/service/cloud_print/printer_job_handler.cc index d7f562d..b071de4 100644 --- a/chrome/service/cloud_print/printer_job_handler.cc +++ b/chrome/service/cloud_print/printer_job_handler.cc @@ -69,73 +69,10 @@ bool PrinterJobHandler::Initialize() { return true; } -PrinterJobHandler::~PrinterJobHandler() { - if (printer_watcher_) - printer_watcher_->StopWatching(); -} - -void PrinterJobHandler::Reset() { - print_data_url_.clear(); - job_details_.Clear(); - request_ = NULL; - print_thread_.Stop(); -} - std::string PrinterJobHandler::GetPrinterName() const { return printer_info_.printer_name; } -void PrinterJobHandler::Start() { - VLOG(1) << "CP_CONNECTOR: Start printer job handler, id: " - << printer_info_cloud_.printer_id - << ", task in progress: " << task_in_progress_; - if (task_in_progress_) { - // Multiple Starts can get posted because of multiple notifications - // We want to ignore the other ones that happen when a task is in progress. - return; - } - Reset(); - if (!shutting_down_) { - // Check if we have work to do. - if (HavePendingTasks()) { - if (!task_in_progress_ && printer_update_pending_) { - printer_update_pending_ = false; - task_in_progress_ = UpdatePrinterInfo(); - } - if (!task_in_progress_ && job_check_pending_) { - task_in_progress_ = true; - job_check_pending_ = false; - // We need to fetch any pending jobs for this printer - SetNextJSONHandler(&PrinterJobHandler::HandleJobMetadataResponse); - request_ = new CloudPrintURLFetcher; - request_->StartGetRequest( - CloudPrintHelpers::GetUrlForJobFetch( - cloud_print_server_url_, printer_info_cloud_.printer_id, - job_fetch_reason_), - this, - kCloudPrintAPIMaxRetryCount, - std::string()); - last_job_fetch_time_ = base::TimeTicks::Now(); - VLOG(1) << "Last job fetch time for printer " - << printer_info_.printer_name.c_str() << " is " - << last_job_fetch_time_.ToInternalValue(); - job_fetch_reason_.clear(); - } - } - } -} - -void PrinterJobHandler::Stop() { - VLOG(1) << "CP_CONNECTOR: Stop printer job handler, id: " - << printer_info_cloud_.printer_id; - task_in_progress_ = false; - Reset(); - if (HavePendingTasks()) { - MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(&PrinterJobHandler::Start, this)); - } -} - void PrinterJobHandler::CheckForJobs(const std::string& reason) { VLOG(1) << "CP_CONNECTOR: CheckForJobs, id: " << printer_info_cloud_.printer_id @@ -149,114 +86,15 @@ void PrinterJobHandler::CheckForJobs(const std::string& reason) { } } -bool PrinterJobHandler::UpdatePrinterInfo() { - if (!printer_watcher_) { - LOG(ERROR) << "CP_CONNECTOR: Printer watcher is missing." - << "Check printer server url for printer id: " - << printer_info_cloud_.printer_id; - return false; - } - - VLOG(1) << "CP_CONNECTOR: Update printer info, id: " +void PrinterJobHandler::Shutdown() { + VLOG(1) << "CP_CONNECTOR: Printer job handler shutdown, id: " << printer_info_cloud_.printer_id; - // We need to update the parts of the printer info that have changed - // (could be printer name, description, status or capabilities). - // First asynchronously fetch the capabilities. - printing::PrinterBasicInfo printer_info; - printer_watcher_->GetCurrentPrinterInfo(&printer_info); - - // Asynchronously fetch the printer caps and defaults. The story will - // continue in OnReceivePrinterCaps. - print_system_->GetPrinterCapsAndDefaults( - printer_info.printer_name.c_str(), - base::Bind(&PrinterJobHandler::OnReceivePrinterCaps, - weak_ptr_factory_.GetWeakPtr())); - - // While we are waiting for the data, pretend we have work to do and return - // true. - return true; -} - -void PrinterJobHandler::OnReceivePrinterCaps( - bool succeeded, - const std::string& printer_name, - const printing::PrinterCapsAndDefaults& caps_and_defaults) { - printing::PrinterBasicInfo printer_info; - if (printer_watcher_) - printer_watcher_->GetCurrentPrinterInfo(&printer_info); - - std::string post_data; - std::string mime_boundary; - cloud_print::CreateMimeBoundaryForUpload(&mime_boundary); - - if (succeeded) { - std::string caps_hash = - base::MD5String(caps_and_defaults.printer_capabilities); - if (caps_hash != printer_info_cloud_.caps_hash) { - // Hashes don't match, we need to upload new capabilities (the defaults - // go for free along with the capabilities) - printer_info_cloud_.caps_hash = caps_hash; - cloud_print::AddMultipartValueForUpload(kPrinterCapsValue, - caps_and_defaults.printer_capabilities, mime_boundary, - caps_and_defaults.caps_mime_type, &post_data); - cloud_print::AddMultipartValueForUpload(kPrinterDefaultsValue, - caps_and_defaults.printer_defaults, mime_boundary, - caps_and_defaults.defaults_mime_type, &post_data); - cloud_print::AddMultipartValueForUpload(kPrinterCapsHashValue, - caps_hash, mime_boundary, std::string(), &post_data); - } - } else { - LOG(ERROR) << "Failed to get printer caps and defaults for printer: " - << printer_name; - } - - std::string tags_hash = - CloudPrintHelpers::GenerateHashOfStringMap(printer_info.options); - if (tags_hash != printer_info_cloud_.tags_hash) { - printer_info_cloud_.tags_hash = tags_hash; - CloudPrintHelpers::GenerateMultipartPostDataForPrinterTags( - printer_info.options, mime_boundary, &post_data); - // Remove all the exising proxy tags. - std::string cp_tag_wildcard(kProxyTagPrefix); - cp_tag_wildcard += ".*"; - cloud_print::AddMultipartValueForUpload(kPrinterRemoveTagValue, - cp_tag_wildcard, mime_boundary, std::string(), &post_data); - } - - if (printer_info.printer_name != printer_info_.printer_name) { - cloud_print::AddMultipartValueForUpload(kPrinterNameValue, - printer_info.printer_name, mime_boundary, std::string(), &post_data); - } - if (printer_info.printer_description != printer_info_.printer_description) { - cloud_print::AddMultipartValueForUpload(kPrinterDescValue, - printer_info.printer_description, mime_boundary, - std::string(), &post_data); - } - if (printer_info.printer_status != printer_info_.printer_status) { - cloud_print::AddMultipartValueForUpload(kPrinterStatusValue, - base::StringPrintf("%d", printer_info.printer_status), mime_boundary, - std::string(), &post_data); - } - printer_info_ = printer_info; - if (!post_data.empty()) { - // Terminate the request body - post_data.append("--" + mime_boundary + "--\r\n"); - std::string mime_type("multipart/form-data; boundary="); - mime_type += mime_boundary; - SetNextJSONHandler(&PrinterJobHandler::HandlePrinterUpdateResponse); - request_ = new CloudPrintURLFetcher; - request_->StartPostRequest( - CloudPrintHelpers::GetUrlForPrinterUpdate( - cloud_print_server_url_, printer_info_cloud_.printer_id), - this, - kCloudPrintAPIMaxRetryCount, - mime_type, - post_data, - std::string()); - } else { - // We are done here. Go to the Stop state - MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); + Reset(); + shutting_down_ = true; + while (!job_status_updater_list_.empty()) { + // Calling Stop() will cause the OnJobCompleted to be called which will + // remove the updater object from the list. + job_status_updater_list_.front()->Stop(); } } @@ -363,6 +201,26 @@ void PrinterJobHandler::OnJobChanged() { } } +void PrinterJobHandler::OnJobSpoolSucceeded( + const cloud_print::PlatformJobId& job_id) { + DCHECK(MessageLoop::current() == print_thread_.message_loop()); + job_spooler_ = NULL; + job_handler_message_loop_proxy_->PostTask( + FROM_HERE, base::Bind(&PrinterJobHandler::JobSpooled, this, job_id)); +} + +void PrinterJobHandler::OnJobSpoolFailed() { + DCHECK(MessageLoop::current() == print_thread_.message_loop()); + job_spooler_ = NULL; + job_handler_message_loop_proxy_->PostTask( + FROM_HERE, base::Bind(&PrinterJobHandler::JobFailed, this, PRINT_FAILED)); +} + +PrinterJobHandler::~PrinterJobHandler() { + if (printer_watcher_) + printer_watcher_->StopWatching(); +} + // Begin Response handlers CloudPrintURLFetcher::ResponseAction PrinterJobHandler::HandlePrinterUpdateResponse( @@ -517,7 +375,57 @@ PrinterJobHandler::HandleFailureStatusUpdateResponse( FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); return CloudPrintURLFetcher::STOP_PROCESSING; } -// End Response handlers + +void PrinterJobHandler::Start() { + VLOG(1) << "CP_CONNECTOR: Start printer job handler, id: " + << printer_info_cloud_.printer_id + << ", task in progress: " << task_in_progress_; + if (task_in_progress_) { + // Multiple Starts can get posted because of multiple notifications + // We want to ignore the other ones that happen when a task is in progress. + return; + } + Reset(); + if (!shutting_down_) { + // Check if we have work to do. + if (HavePendingTasks()) { + if (!task_in_progress_ && printer_update_pending_) { + printer_update_pending_ = false; + task_in_progress_ = UpdatePrinterInfo(); + } + if (!task_in_progress_ && job_check_pending_) { + task_in_progress_ = true; + job_check_pending_ = false; + // We need to fetch any pending jobs for this printer + SetNextJSONHandler(&PrinterJobHandler::HandleJobMetadataResponse); + request_ = new CloudPrintURLFetcher; + request_->StartGetRequest( + CloudPrintHelpers::GetUrlForJobFetch( + cloud_print_server_url_, printer_info_cloud_.printer_id, + job_fetch_reason_), + this, + kCloudPrintAPIMaxRetryCount, + std::string()); + last_job_fetch_time_ = base::TimeTicks::Now(); + VLOG(1) << "Last job fetch time for printer " + << printer_info_.printer_name.c_str() << " is " + << last_job_fetch_time_.ToInternalValue(); + job_fetch_reason_.clear(); + } + } + } +} + +void PrinterJobHandler::Stop() { + VLOG(1) << "CP_CONNECTOR: Stop printer job handler, id: " + << printer_info_cloud_.printer_id; + task_in_progress_ = false; + Reset(); + if (HavePendingTasks()) { + MessageLoop::current()->PostTask( + FROM_HERE, base::Bind(&PrinterJobHandler::Start, this)); + } +} void PrinterJobHandler::StartPrinting() { VLOG(1) << "CP_CONNECTOR: Start printing, id: " @@ -535,33 +443,11 @@ void PrinterJobHandler::StartPrinting() { } } -void PrinterJobHandler::JobFailed(PrintJobError error) { - VLOG(1) << "CP_CONNECTOR: Job failed, id: " << printer_info_cloud_.printer_id; - if (!shutting_down_) { - UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_ERROR, error); - } -} - -void PrinterJobHandler::JobSpooled(cloud_print::PlatformJobId local_job_id) { - VLOG(1) << "CP_CONNECTOR: Job spooled, printer id: " - << printer_info_cloud_.printer_id << ", job id: " << local_job_id; - if (!shutting_down_) { - local_job_id_ = local_job_id; - UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_IN_PROGRESS, SUCCESS); - print_thread_.Stop(); - } -} - -void PrinterJobHandler::Shutdown() { - VLOG(1) << "CP_CONNECTOR: Printer job handler shutdown, id: " - << printer_info_cloud_.printer_id; - Reset(); - shutting_down_ = true; - while (!job_status_updater_list_.empty()) { - // Calling Stop() will cause the OnJobCompleted to be called which will - // remove the updater object from the list. - job_status_updater_list_.front()->Stop(); - } +void PrinterJobHandler::Reset() { + print_data_url_.clear(); + job_details_.Clear(); + request_ = NULL; + print_thread_.Stop(); } void PrinterJobHandler::UpdateJobStatus(cloud_print::PrintJobStatus status, @@ -601,6 +487,51 @@ void PrinterJobHandler::SetNextDataHandler(DataHandler handler) { next_json_data_handler_ = NULL; } +void PrinterJobHandler::JobFailed(PrintJobError error) { + VLOG(1) << "CP_CONNECTOR: Job failed, id: " << printer_info_cloud_.printer_id; + if (!shutting_down_) { + UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_ERROR, error); + } +} + +void PrinterJobHandler::JobSpooled(cloud_print::PlatformJobId local_job_id) { + VLOG(1) << "CP_CONNECTOR: Job spooled, printer id: " + << printer_info_cloud_.printer_id << ", job id: " << local_job_id; + if (!shutting_down_) { + local_job_id_ = local_job_id; + UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_IN_PROGRESS, SUCCESS); + print_thread_.Stop(); + } +} + +bool PrinterJobHandler::UpdatePrinterInfo() { + if (!printer_watcher_) { + LOG(ERROR) << "CP_CONNECTOR: Printer watcher is missing." + << "Check printer server url for printer id: " + << printer_info_cloud_.printer_id; + return false; + } + + VLOG(1) << "CP_CONNECTOR: Update printer info, id: " + << printer_info_cloud_.printer_id; + // We need to update the parts of the printer info that have changed + // (could be printer name, description, status or capabilities). + // First asynchronously fetch the capabilities. + printing::PrinterBasicInfo printer_info; + printer_watcher_->GetCurrentPrinterInfo(&printer_info); + + // Asynchronously fetch the printer caps and defaults. The story will + // continue in OnReceivePrinterCaps. + print_system_->GetPrinterCapsAndDefaults( + printer_info.printer_name.c_str(), + base::Bind(&PrinterJobHandler::OnReceivePrinterCaps, + weak_ptr_factory_.GetWeakPtr())); + + // While we are waiting for the data, pretend we have work to do and return + // true. + return true; +} + bool PrinterJobHandler::HavePendingTasks() { return (job_check_pending_ || printer_update_pending_); } @@ -613,6 +544,89 @@ void PrinterJobHandler::FailedFetchingJobData() { } } +void PrinterJobHandler::OnReceivePrinterCaps( + bool succeeded, + const std::string& printer_name, + const printing::PrinterCapsAndDefaults& caps_and_defaults) { + printing::PrinterBasicInfo printer_info; + if (printer_watcher_) + printer_watcher_->GetCurrentPrinterInfo(&printer_info); + + std::string post_data; + std::string mime_boundary; + cloud_print::CreateMimeBoundaryForUpload(&mime_boundary); + + if (succeeded) { + std::string caps_hash = + base::MD5String(caps_and_defaults.printer_capabilities); + if (caps_hash != printer_info_cloud_.caps_hash) { + // Hashes don't match, we need to upload new capabilities (the defaults + // go for free along with the capabilities) + printer_info_cloud_.caps_hash = caps_hash; + cloud_print::AddMultipartValueForUpload(kPrinterCapsValue, + caps_and_defaults.printer_capabilities, mime_boundary, + caps_and_defaults.caps_mime_type, &post_data); + cloud_print::AddMultipartValueForUpload(kPrinterDefaultsValue, + caps_and_defaults.printer_defaults, mime_boundary, + caps_and_defaults.defaults_mime_type, &post_data); + cloud_print::AddMultipartValueForUpload(kPrinterCapsHashValue, + caps_hash, mime_boundary, std::string(), &post_data); + } + } else { + LOG(ERROR) << "Failed to get printer caps and defaults for printer: " + << printer_name; + } + + std::string tags_hash = + CloudPrintHelpers::GenerateHashOfStringMap(printer_info.options); + if (tags_hash != printer_info_cloud_.tags_hash) { + printer_info_cloud_.tags_hash = tags_hash; + CloudPrintHelpers::GenerateMultipartPostDataForPrinterTags( + printer_info.options, mime_boundary, &post_data); + // Remove all the exising proxy tags. + std::string cp_tag_wildcard(kProxyTagPrefix); + cp_tag_wildcard += ".*"; + cloud_print::AddMultipartValueForUpload(kPrinterRemoveTagValue, + cp_tag_wildcard, mime_boundary, std::string(), &post_data); + } + + if (printer_info.printer_name != printer_info_.printer_name) { + cloud_print::AddMultipartValueForUpload(kPrinterNameValue, + printer_info.printer_name, mime_boundary, std::string(), &post_data); + } + if (printer_info.printer_description != printer_info_.printer_description) { + cloud_print::AddMultipartValueForUpload(kPrinterDescValue, + printer_info.printer_description, mime_boundary, + std::string(), &post_data); + } + if (printer_info.printer_status != printer_info_.printer_status) { + cloud_print::AddMultipartValueForUpload(kPrinterStatusValue, + base::StringPrintf("%d", printer_info.printer_status), mime_boundary, + std::string(), &post_data); + } + printer_info_ = printer_info; + if (!post_data.empty()) { + // Terminate the request body + post_data.append("--" + mime_boundary + "--\r\n"); + std::string mime_type("multipart/form-data; boundary="); + mime_type += mime_boundary; + SetNextJSONHandler(&PrinterJobHandler::HandlePrinterUpdateResponse); + request_ = new CloudPrintURLFetcher; + request_->StartPostRequest( + CloudPrintHelpers::GetUrlForPrinterUpdate( + cloud_print_server_url_, printer_info_cloud_.printer_id), + this, + kCloudPrintAPIMaxRetryCount, + mime_type, + post_data, + std::string()); + } else { + // We are done here. Go to the Stop state + MessageLoop::current()->PostTask( + FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); + } +} + // The following methods are called on |print_thread_|. It is not safe to // access any members other than |job_handler_message_loop_proxy_|, // |job_spooler_| and |print_system_|. @@ -630,18 +644,3 @@ void PrinterJobHandler::DoPrint(const JobDetails& job_details, OnJobSpoolFailed(); } } - -void PrinterJobHandler::OnJobSpoolSucceeded( - const cloud_print::PlatformJobId& job_id) { - DCHECK(MessageLoop::current() == print_thread_.message_loop()); - job_spooler_ = NULL; - job_handler_message_loop_proxy_->PostTask( - FROM_HERE, base::Bind(&PrinterJobHandler::JobSpooled, this, job_id)); -} - -void PrinterJobHandler::OnJobSpoolFailed() { - DCHECK(MessageLoop::current() == print_thread_.message_loop()); - job_spooler_ = NULL; - job_handler_message_loop_proxy_->PostTask( - FROM_HERE, base::Bind(&PrinterJobHandler::JobFailed, this, PRINT_FAILED)); -} diff --git a/chrome/service/cloud_print/printer_job_handler.h b/chrome/service/cloud_print/printer_job_handler.h index a818c83..f093998 100644 --- a/chrome/service/cloud_print/printer_job_handler.h +++ b/chrome/service/cloud_print/printer_job_handler.h @@ -67,25 +67,6 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>, public JobStatusUpdaterDelegate, public cloud_print::PrinterWatcherDelegate, public cloud_print::JobSpoolerDelegate { - enum PrintJobError { - SUCCESS, - JOB_DOWNLOAD_FAILED, - INVALID_JOB_DATA, - PRINT_FAILED, - }; - struct JobDetails { - JobDetails(); - ~JobDetails(); - void Clear(); - - std::string job_id_; - std::string job_title_; - std::string print_ticket_; - FilePath print_data_file_path_; - std::string print_data_mime_type_; - std::vector<std::string> tags_; - }; - public: class Delegate { public: @@ -110,14 +91,18 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>, const GURL& cloud_print_server_url, cloud_print::PrintSystem* print_system, Delegate* delegate); - virtual ~PrinterJobHandler(); + bool Initialize(); + std::string GetPrinterName() const; + // Requests a job check. |reason| is the reason for fetching the job. Used // for logging and diagnostc purposes. void CheckForJobs(const std::string& reason); + // Shutdown everything (the process is exiting). void Shutdown(); + base::TimeTicks last_job_fetch_time() const { return last_job_fetch_time_; } // End public interface @@ -162,6 +147,15 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>, // End Delegate implementations private: + friend class base::RefCountedThreadSafe<PrinterJobHandler>; + + enum PrintJobError { + SUCCESS, + JOB_DOWNLOAD_FAILED, + INVALID_JOB_DATA, + PRINT_FAILED, + }; + // Prototype for a JSON data handler. typedef CloudPrintURLFetcher::ResponseAction (PrinterJobHandler::*JSONDataHandler)(const content::URLFetcher* source, @@ -173,6 +167,22 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>, (PrinterJobHandler::*DataHandler)(const content::URLFetcher* source, const GURL& url, const std::string& data); + + struct JobDetails { + JobDetails(); + ~JobDetails(); + void Clear(); + + std::string job_id_; + std::string job_title_; + std::string print_ticket_; + FilePath print_data_file_path_; + std::string print_data_mime_type_; + std::vector<std::string> tags_; + }; + + virtual ~PrinterJobHandler(); + // Begin request handlers for each state in the state machine CloudPrintURLFetcher::ResponseAction HandlePrinterUpdateResponse( const content::URLFetcher* source, @@ -219,7 +229,6 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>, void Stop(); void StartPrinting(); - void HandleServerError(const GURL& url); void Reset(); void UpdateJobStatus(cloud_print::PrintJobStatus status, PrintJobError error); diff --git a/chrome/service/gaia/service_gaia_authenticator.cc b/chrome/service/gaia/service_gaia_authenticator.cc index a77f224..49704f9 100644 --- a/chrome/service/gaia/service_gaia_authenticator.cc +++ b/chrome/service/gaia/service_gaia_authenticator.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. @@ -21,7 +21,19 @@ ServiceGaiaAuthenticator::ServiceGaiaAuthenticator( http_response_code_(0) { } -ServiceGaiaAuthenticator::~ServiceGaiaAuthenticator() { +// content::URLFetcherDelegate implementation +void ServiceGaiaAuthenticator::OnURLFetchComplete( + const content::URLFetcher* source) { + DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); + http_response_code_ = source->GetResponseCode(); + source->GetResponseAsString(&response_data_); + delete source; + // Add an extra reference because we want http_post_completed_ to remain + // valid until after Signal() returns. + scoped_refptr<ServiceGaiaAuthenticator> keep_alive(this); + // Wake the blocked thread in Post. + http_post_completed_.Signal(); + // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! } bool ServiceGaiaAuthenticator::Post(const GURL& url, @@ -61,6 +73,8 @@ int ServiceGaiaAuthenticator::GetBackoffDelaySeconds( return ret; } +ServiceGaiaAuthenticator::~ServiceGaiaAuthenticator() {} + void ServiceGaiaAuthenticator::DoPost(const GURL& post_url, const std::string& post_body) { DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); @@ -71,18 +85,3 @@ void ServiceGaiaAuthenticator::DoPost(const GURL& post_url, request->SetUploadData("application/x-www-form-urlencoded", post_body); request->Start(); } - -// content::URLFetcherDelegate implementation -void ServiceGaiaAuthenticator::OnURLFetchComplete( - const content::URLFetcher* source) { - DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); - http_response_code_ = source->GetResponseCode(); - source->GetResponseAsString(&response_data_); - delete source; - // Add an extra reference because we want http_post_completed_ to remain - // valid until after Signal() returns. - scoped_refptr<ServiceGaiaAuthenticator> keep_alive(this); - // Wake the blocked thread in Post. - http_post_completed_.Signal(); - // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! -} diff --git a/chrome/service/gaia/service_gaia_authenticator.h b/chrome/service/gaia/service_gaia_authenticator.h index 142e322..81517b4a 100644 --- a/chrome/service/gaia/service_gaia_authenticator.h +++ b/chrome/service/gaia/service_gaia_authenticator.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. @@ -29,7 +29,6 @@ class ServiceGaiaAuthenticator const std::string& service_id, const std::string& gaia_url, base::MessageLoopProxy* io_message_loop_proxy); - virtual ~ServiceGaiaAuthenticator(); // content::URLFetcherDelegate implementation. virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; @@ -43,6 +42,9 @@ class ServiceGaiaAuthenticator virtual int GetBackoffDelaySeconds(int current_backoff_delay) OVERRIDE; private: + friend class base::RefCountedThreadSafe<ServiceGaiaAuthenticator>; + virtual ~ServiceGaiaAuthenticator(); + void DoPost(const GURL& post_url, const std::string& post_body); base::WaitableEvent http_post_completed_; diff --git a/chrome/test/base/chrome_test_suite.cc b/chrome/test/base/chrome_test_suite.cc index 51001105d..0efafbc 100644 --- a/chrome/test/base/chrome_test_suite.cc +++ b/chrome/test/base/chrome_test_suite.cc @@ -57,8 +57,7 @@ void RemoveSharedMemoryFile(const std::string& filename) { // lookup result. class LocalHostResolverProc : public net::HostResolverProc { public: - LocalHostResolverProc() : HostResolverProc(NULL) { - } + LocalHostResolverProc() : HostResolverProc(NULL) {} virtual int Resolve(const std::string& host, net::AddressFamily address_family, @@ -92,6 +91,9 @@ class LocalHostResolverProc : public net::HostResolverProc { return ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, os_error); } + + private: + virtual ~LocalHostResolverProc() {} }; class ChromeTestSuiteInitializer : public testing::EmptyTestEventListener { diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index 7d26924..d08a71d 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -99,6 +99,9 @@ class TestExtensionURLRequestContext : public net::URLRequestContext { cookie_monster->SetCookieableSchemes(schemes, 1); set_cookie_store(cookie_monster); } + + private: + virtual ~TestExtensionURLRequestContext() {} }; class TestExtensionURLRequestContextGetter diff --git a/chrome/test/base/thread_observer_helper.h b/chrome/test/base/thread_observer_helper.h index a5e5bf8..a491c57 100644 --- a/chrome/test/base/thread_observer_helper.h +++ b/chrome/test/base/thread_observer_helper.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. @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/memory/ref_counted.h" +#include "base/sequenced_task_runner_helpers.h" #include "base/synchronization/waitable_event.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_registrar.h" @@ -68,6 +69,13 @@ class DBThreadObserverHelper : public DBThreadObserverHelperBase { public: DBThreadObserverHelper() : DBThreadObserverHelperBase(content::BrowserThread::DB) {} + + protected: + friend struct content::BrowserThread::DeleteOnThread< + content::BrowserThread::DB>; + friend class base::DeleteHelper<DBThreadObserverHelper>; + + virtual ~DBThreadObserverHelper() {} }; #endif // CHROME_TEST_BASE_THREAD_OBSERVER_HELPER_H_ diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc index b00e443..eede450 100644 --- a/chrome/test/base/ui_test_utils.cc +++ b/chrome/test/base/ui_test_utils.cc @@ -209,6 +209,9 @@ class InProcessJavaScriptExecutionController } private: + friend class base::RefCounted<InProcessJavaScriptExecutionController>; + virtual ~InProcessJavaScriptExecutionController() {} + // Weak pointer to the associated RenderViewHost. RenderViewHost* render_view_host_; }; |