diff options
author | noamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-26 22:24:31 +0000 |
---|---|---|
committer | noamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-26 22:24:31 +0000 |
commit | ead51fead0f5832bf8167499ba9c58b20e49d992 (patch) | |
tree | 6f1bb835dda8ca644ffa64153714bbbca1dade25 /chrome | |
parent | 8296efb274f6c72ac87ab168b3d74a5d706755e7 (diff) | |
download | chromium_src-ead51fead0f5832bf8167499ba9c58b20e49d992.zip chromium_src-ead51fead0f5832bf8167499ba9c58b20e49d992.tar.gz chromium_src-ead51fead0f5832bf8167499ba9c58b20e49d992.tar.bz2 |
Move Privet printer search timeout to Javascript
Remove timeout for privet printer search from C++ code and add it to Javascript
instead.
BUG=326718
Review URL: https://codereview.chromium.org/103803009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242568 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 56 insertions, 45 deletions
diff --git a/chrome/browser/resources/print_preview/data/destination_store.js b/chrome/browser/resources/print_preview/data/destination_store.js index fce6161..647aac9 100644 --- a/chrome/browser/resources/print_preview/data/destination_store.js +++ b/chrome/browser/resources/print_preview/data/destination_store.js @@ -146,6 +146,15 @@ cr.define('print_preview', function() { */ this.hasLoadedAllPrivetDestinations_ = false; + + /** + * ID of a timeout after the start of a privet search to end that privet + * search. + * @type {?number} + * @private + */ + this.privetSearchTimeout_ = null; + this.addEventListeners_(); this.reset_(); }; @@ -179,6 +188,14 @@ cr.define('print_preview', function() { DestinationStore.AUTO_SELECT_TIMEOUT_ = 15000; /** + * Amount of time spent searching for privet destination, in milliseconds. + * @type {number} + * @const + * @private + */ + DestinationStore.PRIVET_SEARCH_DURATION_ = 2000; + + /** * Creates a local PDF print destination. * @return {!print_preview.Destination} Created print destination. * @private @@ -503,6 +520,9 @@ cr.define('print_preview', function() { this.nativeLayer_.startGetPrivetDestinations(); cr.dispatchSimpleEvent( this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); + this.privetSearchTimeout_ = setTimeout( + this.endPrivetPrinterSearch_.bind(this), + DestinationStore.PRIVET_SEARCH_DURATION_); } }, @@ -521,6 +541,19 @@ cr.define('print_preview', function() { }, /** + * Called when the search for Privet printers is done. + * @private + */ + endPrivetPrinterSearch_: function() { + this.nativeLayer_.stopGetPrivetDestinations(); + this.isPrivetDestinationSearchInProgress_ = false; + this.hasLoadedAllPrivetDestinations_ = true; + cr.dispatchSimpleEvent( + this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); + }, + + + /** * Inserts a destination into the store without dispatching any events. * @return {boolean} Whether the inserted destination was not already in the * store. @@ -571,10 +604,6 @@ cr.define('print_preview', function() { this.onPrivetPrinterAdded_.bind(this)); this.tracker_.add( this.nativeLayer_, - print_preview.NativeLayer.EventType.PRIVET_PRINTER_SEARCH_DONE, - this.onPrivetPrinterSearchDone_.bind(this)); - this.tracker_.add( - this.nativeLayer_, print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET, this.onPrivetCapabilitiesSet_.bind(this)); }, @@ -751,17 +780,6 @@ cr.define('print_preview', function() { }, /** - * Called when the search for Privet printers is done. - * @private - */ - onPrivetPrinterSearchDone_: function() { - this.isPrivetDestinationSearchInProgress_ = false; - this.hasLoadedAllPrivetDestinations_ = true; - cr.dispatchSimpleEvent( - this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); - }, - - /** * Called from native layer after the user was requested to sign in, and did * so successfully. * @private diff --git a/chrome/browser/resources/print_preview/native_layer.js b/chrome/browser/resources/print_preview/native_layer.js index cd54c897..526e14f 100644 --- a/chrome/browser/resources/print_preview/native_layer.js +++ b/chrome/browser/resources/print_preview/native_layer.js @@ -43,8 +43,6 @@ cr.define('print_preview', function() { global['onDidGetAccessToken'] = this.onDidGetAccessToken_.bind(this); global['autoCancelForTesting'] = this.autoCancelForTesting_.bind(this); global['onPrivetPrinterChanged'] = this.onPrivetPrinterChanged_.bind(this); - global['onPrivetPrinterSearchDone'] = - this.onPrivetPrinterSearchDone_.bind(this); global['onPrivetCapabilitiesSet'] = this.onPrivetCapabilitiesSet_.bind(this); global['onPrivetPrintFailed'] = this.onPrivetPrintFailed_.bind(this); @@ -77,8 +75,6 @@ cr.define('print_preview', function() { PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', - PRIVET_PRINTER_SEARCH_DONE: - 'print_preview.NativeLayer.PRIVET_PRINTER_SEARCH_DONE', PRIVET_CAPABILITIES_SET: 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED' @@ -146,6 +142,14 @@ cr.define('print_preview', function() { }, /** + * Requests that the privet print stack stop searching for privet print + * destinations. + */ + stopGetPrivetDestinations: function() { + chrome.send('stopGetPrivetPrinters'); + }, + + /** * Requests the privet destination's printing capabilities. A * PRIVET_CAPABILITIES_SET event will be dispatched in response. * @param {string} destinationId ID of the destination. @@ -642,16 +646,6 @@ cr.define('print_preview', function() { }, /** - * Called when the privet printer search is over. - * @private - */ - onPrivetPrinterSearchDone_: function() { - var privetPrinterSearchDoneEvent = - new Event(NativeLayer.EventType.PRIVET_PRINTER_SEARCH_DONE); - this.dispatchEvent(privetPrinterSearchDoneEvent); - }, - - /** * @param {Object} printer Specifies information about the printer that was * added. * @private diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc index e913c6b..eb9bea2 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc +++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc @@ -184,10 +184,6 @@ const char kCUPSsColorModel[] = "cupsColorModel"; const char kCUPSsBWModel[] = "cupsBWModel"; #endif -#if defined(ENABLE_MDNS) -const int kPrivetPrinterSearchDurationSeconds = 3; -#endif - // Get the print job settings dictionary from |args|. The caller takes // ownership of the returned DictionaryValue. Returns NULL on failure. base::DictionaryValue* GetSettingsDictionary(const base::ListValue* args) { @@ -548,6 +544,9 @@ void PrintPreviewHandler::RegisterMessages() { web_ui()->RegisterMessageCallback("getPrivetPrinters", base::Bind(&PrintPreviewHandler::HandleGetPrivetPrinters, base::Unretained(this))); + web_ui()->RegisterMessageCallback("stopGetPrivetPrinters", + base::Bind(&PrintPreviewHandler::HandleStopGetPrivetPrinters, + base::Unretained(this))); web_ui()->RegisterMessageCallback("getPrivetPrinterCapabilities", base::Bind(&PrintPreviewHandler::HandleGetPrivetPrinterCapabilities, base::Unretained(this))); @@ -589,12 +588,6 @@ void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { profile->GetRequestContext(), this)); printer_lister_->Start(); - - base::MessageLoop::current()->PostDelayedTask( - FROM_HERE, - base::Bind(&PrintPreviewHandler::StopPrivetPrinterSearch, - weak_factory_.GetWeakPtr()), - base::TimeDelta::FromSeconds(kPrivetPrinterSearchDurationSeconds)); } #endif @@ -603,6 +596,15 @@ void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { } } +void PrintPreviewHandler::HandleStopGetPrivetPrinters( + const base::ListValue* args) { +#if defined(ENABLE_MDNS) + if (PrivetPrintingEnabled()) { + printer_lister_->Stop(); + } +#endif +} + void PrintPreviewHandler::HandleGetPrivetPrinterCapabilities( const base::ListValue* args) { #if defined(ENABLE_MDNS) @@ -1392,11 +1394,6 @@ void PrintPreviewHandler::LocalPrinterRemoved(const std::string& name) { void PrintPreviewHandler::LocalPrinterCacheFlushed() { } -void PrintPreviewHandler::StopPrivetPrinterSearch() { - printer_lister_->Stop(); - web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone"); -} - void PrintPreviewHandler::PrivetCapabilitiesUpdateClient( scoped_ptr<local_discovery::PrivetHTTPClient> http_client) { if (!PrivetUpdateClient(http_client.Pass())) diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.h b/chrome/browser/ui/webui/print_preview/print_preview_handler.h index a35df5d..a894662 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_handler.h +++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.h @@ -123,6 +123,9 @@ class PrintPreviewHandler // Starts getting all local privet printers. |arg| is unused. void HandleGetPrivetPrinters(const base::ListValue* args); + // Stops getting all local privet printers. |arg| is unused. + void HandleStopGetPrivetPrinters(const base::ListValue* args); + // Asks the initiator renderer to generate a preview. First element of |args| // is a job settings JSON string. void HandleGetPreview(const base::ListValue* args); @@ -252,7 +255,6 @@ class PrintPreviewHandler #endif #if defined(ENABLE_MDNS) - void StopPrivetPrinterSearch(); void PrivetCapabilitiesUpdateClient( scoped_ptr<local_discovery::PrivetHTTPClient> http_client); void PrivetLocalPrintUpdateClient( |