ui: Remove state from controller/globals.ts

Previously the code under controller ran in a separate Worker.
This necessitated a bunch of complexity:
- The controller maintained a separate copy of the state
- Which it updated using 'patches' generated by applying actions
  on the main thread
- These patches had to be postMessage'd from the main thread to
  the controller thread

Since the controller code now runs on the main thread much of this
can be removed. Specifically:
- We no longer have to use a `Channel` and `postMessage` to trigger
  the controllers to run.
- The Controller code no longer needs to maintain a separate
  state object - instead all controller code can look at the
  'frontend' state object.
- A long unused `errorReportingChannel` can also be removed.

This change is very almost a noop. There is one specific behaviour
change I foresee. Prior to this change in the rare case where
controller code dispatches an action that action did not immediately
effect the state as seen by the controller - after this CL it does.

The continues the plan to:
- Remove unnecessary complexity of the controller/frontend distinction
- Remove controller/globals.ts entirely

Change-Id: I8ed10e1fcbebbdd6aa3abed45f64e294700c703c
diff --git a/ui/src/controller/flamegraph_controller.ts b/ui/src/controller/flamegraph_controller.ts
index 6d4f36d..e94531d 100644
--- a/ui/src/controller/flamegraph_controller.ts
+++ b/ui/src/controller/flamegraph_controller.ts
@@ -28,10 +28,7 @@
 import {NUM, STR} from '../common/query_result';
 import {CallsiteInfo, FlamegraphState, ProfileType} from '../common/state';
 import {toNs} from '../common/time';
-import {
-  FlamegraphDetails,
-  globals as frontendGlobals,
-} from '../frontend/globals';
+import {FlamegraphDetails, globals} from '../frontend/globals';
 import {publishFlamegraphDetails} from '../frontend/publish';
 import {
   Config as PerfSampleConfig,
@@ -40,7 +37,6 @@
 
 import {AreaSelectionHandler} from './area_selection_handler';
 import {Controller} from './controller';
-import {globals} from './globals';
 
 export function profileType(s: string): ProfileType {
   if (isProfileType(s)) {
@@ -131,11 +127,11 @@
       const upids = [];
       if (!area) {
         this.checkCompletionAndPublishFlamegraph(
-            {...frontendGlobals.flamegraphDetails, isInAreaSelection: false});
+            {...globals.flamegraphDetails, isInAreaSelection: false});
         return;
       }
       for (const trackId of area.tracks) {
-        const trackState = frontendGlobals.state.tracks[trackId];
+        const trackState = globals.state.tracks[trackId];
         if (!trackState ||
             trackState.kind !== PERF_SAMPLES_PROFILE_TRACK_KIND) {
           continue;
@@ -144,10 +140,10 @@
       }
       if (upids.length === 0) {
         this.checkCompletionAndPublishFlamegraph(
-            {...frontendGlobals.flamegraphDetails, isInAreaSelection: false});
+            {...globals.flamegraphDetails, isInAreaSelection: false});
         return;
       }
-      frontendGlobals.dispatch(Actions.openFlamegraph({
+      globals.dispatch(Actions.openFlamegraph({
         upids,
         startNs: toNs(area.startSec),
         endNs: toNs(area.endSec),
@@ -155,7 +151,7 @@
         viewingOption: PERF_SAMPLES_KEY,
       }));
     }
-    const selection = frontendGlobals.state.currentFlamegraphState;
+    const selection = globals.state.currentFlamegraphState;
     if (!selection || !this.shouldRequestData(selection)) {
       return;
     }