Setting the page title in a plugin, but not outside my plugin

1) I think I solved it: check if the content contains my shortcode:

a) So set up in my top (outer) plugin file with:

add_filter( ‘pre_get_document_title’, ‘dwnz_filter_pagetitle’, 20 );

b) plus later on in same file:

function dwnz_filter_pagetitle ($title) {
// get_post even works in my case when I am expecting a page, not a post
$content = get_post();
if (has_shortcode($content->post_content, ‘my_plugin_shortcode’)) {

   $new_page_title =  get_something_from_my_database();      
   $page_title = $new_page_title;
   return ($page_title);
}

}

2) Plus: I solved a similar problem: how do I ensure that my JS was enqueued only for my plugin content, (whereas I had it being enqueued on all output, unneccessary)

a) So set up in my top (outer) plugin file with:

add_shortcode(‘my_plugin_shortcode’, ‘my_top_function’);

b) In same file:

function my_top_function($atts, $content="", $tag){
   $obj = new my_plugin_class ('my_title', 'my_version');
   $html = $obj->some_method();
   return ($html);

}

c) in my_plugin_class, in some_method, first do something that makes my_html and JS markup based on your inputs and logic. (I’m fetching from a database and making some google JS of marker locations). Then I queue one line for a normal reference to Google, plus another to append my dynamic JS to the WP queue, so that WP issues it in a standards-compliant way.
The point being, all this only happens if your shortcode has invoked your code at the top.

$google_api_key = $this->get_google_api_key();
$google_include="https://maps.googleapis.com/maps/api/js?"
   . 'v=3.exp&key='.$google_api_key;
$script_id = $this->plugin_name.'_googlemaps';
wp_enqueue_script( $script_id,  
   $google_include, 
   array( 'jquery' ), $this->version, true );
wp_add_inline_script($script_id, 
   $my_dynamic_js_string, 'after' ); 

....
return($my_html);

I hope this helps. I’m new to the etiquette here.