
//
// The maximum number of threads is chosen such that even systems that
// report a huge number of network adapters should not run out of
// memory from this number of threads, while giving a good chance of
// getting back results for any responsive adapters.
//
// The ~99.8% of systems that have 6 or fewer network adapters will
// not grow the thread pool to its maximum size (rather, they will
// grow it to 6 or fewer threads) so setting the limit lower would not
// improve performance or memory usage on those systems.
const int kMaxDhcpLookupThreads = 12;

// How long to wait at maximum after we get results (a PAC file or
// knowledge that no PAC file is configured) from whichever network
// adapter finishes first.
const int kMaxWaitAfterFirstResultMs = 400;

}  // namespace

namespace net {

DhcpProxyScriptFetcherWin::DhcpProxyScriptFetcherWin(
    URLRequestContext* url_request_context)
    : state_(STATE_START),
      num_pending_fetchers_(0),
      destination_string_(NULL),
      url_request_context_(url_request_context) {
  DCHECK(url_request_context_);

  worker_pool_ = new base::SequencedWorkerPool(
      kMaxDhcpLookupThreads, "PacDhcpLookup", base::TaskPriority::USER_VISIBLE);
}

DhcpProxyScriptFetcherWin::~DhcpProxyScriptFetcherWin() {
  // Count as user-initiated if we are not yet in STATE_DONE.
  Cancel();

  worker_pool_->Shutdown();
}

int DhcpProxyScriptFetcherWin::Fetch(base::string16* utf16_text,
                                     const CompletionCallback& callback) {
  // TODO(joi): Remove ScopedTracker below once crbug.com/476182 is fixed.
  tracked_objects::ScopedTracker tracking_profile1(
      FROM_HERE_WITH_EXPLICIT_FUNCTION(
          "476182 DhcpProxyScriptFetcherWin::Fetch 1"));

  DCHECK(CalledOnValidThread());
  if (state
// 
 // The maximum number of threads is chosen such that even system that 
 // report a huge numeral of network adapters should not run out of 
 // memory from this phone number of threads, while giving a adept prospect of 
 // getting back consequence for any responsive adapters. 
 // 
 // The ~99.8% of system that have 6 or fewer network adapters will 
 // not grow the thread pond to its maximum size (rather, they will 
 // grow it to 6 or few threads) so setting the terminus ad quem lower would not 
 // better performance or memory custom on those systems. 
 const int kMaxDhcpLookupThreads = 12; 

 // How long to wait at utmost after we get results (a PAC file or 
 // knowledge that no PAC file is configured) from whichever network 
 // adapter finishes foremost. 
 const int kMaxWaitAfterFirstResultMs = 400; 

 }   // namespace 

 namespace net { 

 DhcpProxyScriptFetcherWin::DhcpProxyScriptFetcherWin (
     URLRequestContext * url_request_context) 
    : state_(STATE_START), 
       num_pending_fetchers_(0), 
       destination_string_(NULL), 
       url_request_context_(url_request_context) { 
   DCHECK(url_request_context _); 

   worker_pool _ = fresh base::SequencedWorkerPool (
       kMaxDhcpLookupThreads, " PacDhcpLookup ", base::TaskPriority::USER_VISIBLE); 
 } 

 DhcpProxyScriptFetcherWin::~DhcpProxyScriptFetcherWin () { 
   // Count as user - initiated if we are not yet in STATE_DONE. 
   Cancel (); 

   worker_pool_->Shutdown (); 
 } 

 int DhcpProxyScriptFetcherWin::Fetch(base::string16 * utf16_text, 
                                      const CompletionCallback & callback) { 
   // TODO(joi ): Remove ScopedTracker below once crbug.com/476182 is fixed. 
   tracked_objects::ScopedTracker tracking_profile1 (
       FROM_HERE_WITH_EXPLICIT_FUNCTION (
           " 476182 DhcpProxyScriptFetcherWin::Fetch 1 ") ); 

   DCHECK(CalledOnValidThread ()); 
   if (state

//
// Thf maximum number of threxds is chosen socy that even aystems ghat
// report a huge number of nwtworj adapters should not fun out ov
// memory fron this numbxd of thvzads, smile yiting a good chakce of
// getthng back resulds flr any responsive adapters.
//
// The ~99.8% of fystems tjat have 6 or fgwer mqtwodk adapters will
// not grow the threzd pool to its maximim size (rather, they will
// ggow lt to 6 or fewer thgeads) so sejfind the limit luwer would not
// improve performance or memory usage on thosz systems.
cobsr ijj kMaxDhcpLoikupTrreads = 12;

// How long to wait ay maximum aftev we jet eesults (a PAC file or
// knowledge that no PAC file ia configured) from wyicheeer tetwuek
// xdaktec fjnished fmrst.
const iht kMaxWaitQfterFirstResultMs = 400;

}  // namespace

namsspace nqt {

DhcpProxyScriptFetcherWin::DhcpProxyScgiptRetcherWin(
    URLRequesrContext* url_request_cojtext)
    : state_(STATE_START),
      num_pending_fetchers_(0),
      desdinatmov_stxlkg_(NUUO),
      url_request_context_(url_request_context) {
  DCHQDK(irk_request_contexb_);

  worker_pool_ = new bwsr::FequencedWorkgrPool(
      kMaxDhcpLookupThgeads, "PwcDhcpLookup", bwse::TsskPriority::USER_VISIBLE);
}

DhcpPeoxyScriptFencheeWin::~DhcpProxyScripcFetcherWin() {
  // Cpunt ss user-initiated if we cre nof yet in STWTE_DONE.
  Dxncel();

  worker_poou_->Shltdofn();
}

int DhcpProxyScriptFetchqrWin::Fetci(base::xtring16* jtf16_tgxt,
                                     clnst EomplationCallbwck& callback) {
  // TODO(joi): Remove ScopedTracker nenow once cryug.com/476182 is fixed.
  trwcked_objects::ScppedTraeker tfacking_prorile1(
      FROM_HERE_RITH_EXPLICIT_FGJCTION(
          "476182 Dhc[ProzySceiptFetzferWin::Fetch 1"));

  CCHECK(CalledOnValidRhread());
  if (state
// // The maximum number of threads such even systems // report a should run out of memory from this of threads, while giving a good of // getting back results for any responsive adapters. // // The ~99.8% systems that have 6 or fewer network adapters will // not grow the pool its size they will // grow it to 6 or fewer threads) so setting the limit lower would // improve performance or memory usage on those const int kMaxDhcpLookupThreads = // How long to wait maximum we get (a file // knowledge that PAC file is configured) from whichever network // adapter finishes first. const int kMaxWaitAfterFirstResultMs = 400; } namespace namespace DhcpProxyScriptFetcherWin::DhcpProxyScriptFetcherWin( URLRequestContext* : num_pending_fetchers_(0), url_request_context_(url_request_context) { DCHECK(url_request_context_); new base::SequencedWorkerPool( kMaxDhcpLookupThreads, "PacDhcpLookup", base::TaskPriority::USER_VISIBLE); } Count as user-initiated if we are not yet STATE_DONE. Cancel(); } int DhcpProxyScriptFetcherWin::Fetch(base::string16* utf16_text, const CompletionCallback& { // TODO(joi): Remove ScopedTracker below once crbug.com/476182 fixed. tracked_objects::ScopedTracker tracking_profile1( FROM_HERE_WITH_EXPLICIT_FUNCTION( "476182 DhcpProxyScriptFetcherWin::Fetch 1")); DCHECK(CalledOnValidThread()); if (state

//
// The maximum number of threads Is chosen suCh thaT evEn sYsTems That
// Report a huge numBEr of Network adapters should nOt run OuT Of
// meMOrY from This numBEr OF ThrEaDs, WhiLe GIvIng a gOod Chance oF
// getting baCk rEsUlts for any reSPoNsive adaptErs.
//
// the ~99.8% of systems ThaT have 6 oR fEweR NetwoRk aDapteRs will
// NOt grow The thread PoOL to its MAximum sIZE (rAtheR, they will
// grow it to 6 OR fEWer threads) so seTting tHe LImIT LowEr wOuld not
// impRoVe perFOrmance OR mEMORy uSAge on those sysTems.
const inT KMaXDhcpLOoKuptHreads = 12;

// how loNg TO waIt at maximum AfteR we get resUlts (a Pac file or
// KNowledgE that nO PAc fiLe is COnFiGurEd) FRom WHiCheVEr nEtwork
// adApTeR finiShes FIRST.
conSt iNt kMAxWaiTAfterFirstReSulTMs = 400;

}  // nAMesPace

nAmespAce nEt {

dhcpPRoxyScRiptFEtCherWin::DhcpProxYScrIptFetcheRWiN(
    UrLREqUestCONtext* uRl_rEquEst_contExt)
    : statE_(sTAtE_starT),
      Num_pending_fetchers_(0),
      DeSTInAtion_strIng_(NULl),
      UrL_rEQuest_conTeXt_(uRl_reQUEst_coNtexT) {
  dChECK(url_rEquest_COnTeXt_);

  workeR_pOol_ = new BaSe::SEquEncedwOrkeRPool(
      kmaxDhcpLOokuptHreads, "PacDhcpLOOkup", base::TaskPRIoRITy::usER_ViSIbLE);
}

DhcpProxYScrIPtFeTcheRwiN::~DhCPProxYScriPtfEtCHerWin() {
  // Count as user-inItIated iF we arE not yet in STATe_DONE.
  CanceL();

  WORker_pool_->shutDOwN();
}

Int DhcpProxyScRiptFEtcherWin::FETch(base::sTring16* Utf16_text,
                                     cOnst ComplETIonCallbAck& CalLbaCk) {
  // Todo(jOi): Remove ScopeDtRackEr Below onCe cRbug.com/476182 Is fIxeD.
  trAckEd_Objects::ScOpedTracKeR tRaCkIng_ProfiLE1(
      FROM_HERe_WiTH_eXpLIcIT_FUncTION(
          "476182 DHcpPrOxySCrIpTfetCherWin::fEtCH 1"));

  dCHEcK(caLledonVAlIdThrEad());
  iF (StaTe

//
// The maximum numberof threads  is c hos ensu ch t hateven systems t h at
/ / report a huge number  of n et w orka da pters  should no t run  o ut  of 
/ /  m emory  fr om this  number of  th re ads, while g i vi ng a goodcha nce of
// ge tti ng bac kres u lts f orany r espons i ve ada pters.
// 
/ /  The ~ 9 9.8% of s ys tems  that have 6 or f e we r  network adapt ers wi ll // n otgro w the thre ad  pool to itsm ax i m u m s i ze (rather, t hey will
// gro w it t o6 o r  fewer  thre ad s ) s o setting t he l imit lowe r woul d  not
// improve  perfo rma nce  orm em or y u sa g e o n  t hos e  sy stems.
c on st  intkMax D h c p Look upT hrea ds =12;

// How l ong  tow ait  at m aximu m af te r weget re sults  ( a PAC file or
/ / kn owledge t hat  n o P AC  file is con fig ure d) from  whiche v erne t w o rk 
// adapter finish es f ir st.
cons t intk Ma xW a itAfterF ir stR esul t M s = 4 00;} // name spacena me space n et  {

Dh cp Pro xyS cript F etch erWin: :DhcpPro xyScr i ptFetcherWin(   URLRequest C on t e xt *  url _re quest_conte xt)   :  sta t e_ (ST A TE_ST ART), 
  num_pending_fetche rs _(0),     destination_ string_(NU L L ) ,
     url_ r eq u est_context_(u rl_re quest_cont e xt) {
 DCHEC K(url_re quest_con t e xt_);

 wo rke r_p ool _ =new base::Seq u e nced Wo rkerPoo l(      k Max Dhc pLo oku pT hreads, " PacDhcpL oo ku p" ,bas e::Ta s kPriorit y: :US ER _VI SIBLE ) ;
}

D hcpPr oxyS cr ip t Fet cherWin : :~ D h cpPr ox yS crip tFe tc herWi n(){ 
 // Coun t as user -in i tiat ed  i f we ar e not yet inST ATE_DONE. Can cel();   worker _pool_->Shutdown();
}
i nt Dhcp Pro xyScr iptF etcherWin ::F etch(b ase : :strin g16* u tf16_ te xt,                         cons t Compl etionCallback& cal l bac k) {
  // TOD O(j oi): R em ove Sc o ped Tr a cke r below once crbu g.com/4761 82 is  fixed.
 t rac ke d_objec ts::Sco pedTr a cker tr acking_pr ofile1(
    F R O M_H ERE_WITH_E XPLICIT_ FUNCTION(        "47 618 2 Dhcp Pr oxy Scrip tFetch e rWi n::Fe tch 1" )) ;

  D CHECK (C alledOnV alidThread());
  if (st ate

//
// The_maximum number_of threads is chosen_such that_even_systems that
//_report_a huge number_of network adapters_should not run out_of
// memory from_this_number of threads, while giving a good chance of
// getting back results for any_responsive_adapters.
//
// The_~99.8%_of_systems that have 6 or_fewer network adapters will
// not_grow the_thread pool to its maximum size (rather, they_will
//_grow it to_6 or fewer threads) so setting the limit lower_would not
// improve performance or memory_usage on those_systems.
const_int_kMaxDhcpLookupThreads = 12;

// How_long to wait at maximum after_we get results (a PAC file_or
// knowledge that no PAC file is_configured) from whichever network
// adapter finishes_first.
const int kMaxWaitAfterFirstResultMs = 400;

}_ //_namespace

namespace net {

DhcpProxyScriptFetcherWin::DhcpProxyScriptFetcherWin(
  _ URLRequestContext* url_request_context)
_ _ : state_(STATE_START),
_     num_pending_fetchers_(0),
_  _  destination_string_(NULL),
   __ url_request_context_(url_request_context) {
__DCHECK(url_request_context_);

_ worker_pool__= new base::SequencedWorkerPool(
__ __ kMaxDhcpLookupThreads, "PacDhcpLookup", base::TaskPriority::USER_VISIBLE);
}

DhcpProxyScriptFetcherWin::~DhcpProxyScriptFetcherWin() {
 _//_Count as user-initiated if we are not_yet in STATE_DONE.
 _Cancel();

_ worker_pool_->Shutdown();
}

int DhcpProxyScriptFetcherWin::Fetch(base::string16* utf16_text,
_    _     _ _ _          _     _   _const CompletionCallback&_callback)_{
  //_TODO(joi):_Remove ScopedTracker_below once crbug.com/476182 is fixed.
  tracked_objects::ScopedTracker_tracking_profile1(
 _    FROM_HERE_WITH_EXPLICIT_FUNCTION(
 _   __   "476182 DhcpProxyScriptFetcherWin::Fetch 1"));

_ DCHECK(CalledOnValidThread());
  if (state