title: how does the tensorflow c++ code SessionFactory::GetFactory choose which session to use?Direct or Grpc Session?
body: <p>In tensorflow c++ code, there are two session types, </p>
  
  <p><strong>tensorflow/core/common_runtime/direct_session.cc 
  tensorflow/core/distributed_runtime/rpc/grpc_session.cc</strong></p>
  
  <p>I can find the session was initialized by method </p>
  
  <p><strong>Status NewSession(const SessionOptions&amp; options, Session out_session)</strong> </p>
  
  <p>in
  <strong>/tensorflow/core/common_runtime/session.cc</strong>,</p>
  
  <p>the question is, I don't know when was the *session_factories filled with "DIRECT_SESSION" in the following code:</p>
  
  <pre><code>for (const auto&amp; session_factory : *session_factories()) {
     if (session_factory.second-&gt;AcceptsOptions(options)) {
         VLOG(0) &lt;&lt; "SessionFactory type " &lt;&lt; session_factory.first
            &lt;&lt; " accepts target: " &lt;&lt; options.target;
    candidate_factories.push_back(session_factory);
  } else {
    VLOG(0) &lt;&lt; "SessionFactory type " &lt;&lt; session_factory.first
            &lt;&lt; " does not accept target: " &lt;&lt; options.target;
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>/tensorflow/core/common_runtime/session_factory.cc</strong>, </p>