Prevent imbalanced keepalive counts in ProcessManager

URLRequests can be canceled (e.g. on destruction) before
they're ever started, meaning that a NetworkDelegate
may be notified of request completion without ever being
notified of request start.

extensions::ProcessManager was making the incorrect assumption
that this couldn't happen (i.e. that a completion notification
must always follow a corresponding start notification), and was
indiscriminately decrementing keepalive count on all URLRequest
completion notifications.

This CL fixes the glitch.

BUG=535716
[email protected]

Review URL: https://codereview.chromium.org/1366393002

Cr-Commit-Position: refs/heads/master@{#351198}
diff --git a/extensions/browser/process_manager.h b/extensions/browser/process_manager.h
index 85f2def..9d44453 100644
--- a/extensions/browser/process_manager.h
+++ b/extensions/browser/process_manager.h
@@ -314,6 +314,13 @@
   // reset.
   uint64 last_background_close_sequence_id_;
 
+  // Tracks pending network requests by opaque ID. This is used to ensure proper
+  // keepalive counting in response to request status updates; e.g., if an
+  // extension URLRequest is constructed and then destroyed without ever
+  // starting, we can receive a completion notification without a corresponding
+  // start notification. In that case we want to avoid decrementing keepalive.
+  std::set<int> pending_network_requests_;
+
   // Must be last member, see doc on WeakPtrFactory.
   base::WeakPtrFactory<ProcessManager> weak_ptr_factory_;