topics: Fix Model Update Race Condition

When a model update comes in, it will trigger any pending calculator
requests to start. This will happen during the execution of
`AnnotatorImpl::OnModelUpdated` in between `is_valid_model_` being set
to false and later to true.

Note that if the annotations request finishes in the same stack
(e.g.: all use the override list) then this race condition will always
happen.

To resolve this, the added check of `is_valid_model_` is removed. This
check is redundant anyways since the calculator also checks whether the
incoming taxonomy version is supported, and whether `GetModelInfo()`
returns a non-null value has it's source of truth further down in the
OptGuide model execution code, which is doing the correct thing.

Furthermore, the AnnotatorImpl class takes over the model available
callbacks to check for the correct taxonomy version.

Adds a regression test

Bug: 1495959
Change-Id: I29f24a81c6af15ebc8d41d302cb1a1865371b415
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4977545
Commit-Queue: Robert Ogden <[email protected]>
Reviewed-by: Yao Xiao <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1215821}
diff --git a/components/browsing_topics/annotator_impl.h b/components/browsing_topics/annotator_impl.h
index 4cc8820..4689819 100644
--- a/components/browsing_topics/annotator_impl.h
+++ b/components/browsing_topics/annotator_impl.h
@@ -9,6 +9,7 @@
 #include <unordered_map>
 #include <vector>
 
+#include "base/callback_list.h"
 #include "base/files/file_path.h"
 #include "base/functional/callback.h"
 #include "base/memory/weak_ptr.h"
@@ -141,9 +142,9 @@
   // memory.
   size_t in_progess_batches_ = 0;
 
-  // Indicates whether the model received was valid. Model will be invalid when
-  // metadata versions are unsupported.
-  bool is_valid_model_ = false;
+  // Callbacks that are run when the model is updated with the correct taxonomy
+  // version.
+  base::OnceClosureList model_available_callbacks_;
 
   SEQUENCE_CHECKER(sequence_checker_);