Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: chrome/browser/chromeos/login/auth/auth_prewarmer.cc

Issue 2063863002: Use DCHECKs when observing only a single notification. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/login/auth/auth_prewarmer.h" 5 #include "chrome/browser/chromeos/login/auth/auth_prewarmer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/chromeos/login/helper.h" 10 #include "chrome/browser/chromeos/login/helper.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 NetworkHandler::Get()->network_state_handler() 71 NetworkHandler::Get()->network_state_handler()
72 ->RemoveObserver(this, FROM_HERE); 72 ->RemoveObserver(this, FROM_HERE);
73 if (GetRequestContext()) 73 if (GetRequestContext())
74 DoPrewarm(); 74 DoPrewarm();
75 } 75 }
76 76
77 void AuthPrewarmer::Observe(int type, 77 void AuthPrewarmer::Observe(int type,
78 const content::NotificationSource& source, 78 const content::NotificationSource& source,
79 const content::NotificationDetails& details) { 79 const content::NotificationDetails& details) {
80 switch (type) { 80 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED,
81 case chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED: 81 type);
82 registrar_.Remove( 82 registrar_.Remove(
83 this, 83 this, chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED,
84 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, 84 content::Source<Profile>(ProfileHelper::GetSigninProfile()));
85 content::Source<Profile>(ProfileHelper::GetSigninProfile())); 85 if (IsNetworkConnected())
86 if (IsNetworkConnected()) 86 DoPrewarm();
87 DoPrewarm();
88 break;
89 default:
90 NOTREACHED();
91 }
92 } 87 }
93 88
94 void AuthPrewarmer::DoPrewarm() { 89 void AuthPrewarmer::DoPrewarm() {
95 const int kConnectionsNeeded = 1; 90 const int kConnectionsNeeded = 1;
96 const GURL& url = GaiaUrls::GetInstance()->service_login_url(); 91 const GURL& url = GaiaUrls::GetInstance()->service_login_url();
97 content::BrowserThread::PostTask( 92 content::BrowserThread::PostTask(
98 content::BrowserThread::IO, FROM_HERE, 93 content::BrowserThread::IO, FROM_HERE,
99 base::Bind(&content::PreconnectUrl, 94 base::Bind(&content::PreconnectUrl,
100 ProfileHelper::GetSigninProfile()->GetResourceContext(), url, 95 ProfileHelper::GetSigninProfile()->GetResourceContext(), url,
101 url, kConnectionsNeeded, true, 96 url, kConnectionsNeeded, true,
102 net::HttpRequestInfo::EARLY_LOAD_MOTIVATED)); 97 net::HttpRequestInfo::EARLY_LOAD_MOTIVATED));
103 if (!completion_callback_.is_null()) { 98 if (!completion_callback_.is_null()) {
104 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 99 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
105 completion_callback_); 100 completion_callback_);
106 } 101 }
107 } 102 }
108 103
109 bool AuthPrewarmer::IsNetworkConnected() const { 104 bool AuthPrewarmer::IsNetworkConnected() const {
110 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); 105 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler();
111 return (nsh->ConnectedNetworkByType(NetworkTypePattern::Default()) != NULL); 106 return (nsh->ConnectedNetworkByType(NetworkTypePattern::Default()) != NULL);
112 } 107 }
113 108
114 net::URLRequestContextGetter* AuthPrewarmer::GetRequestContext() const { 109 net::URLRequestContextGetter* AuthPrewarmer::GetRequestContext() const {
115 return login::GetSigninContext(); 110 return login::GetSigninContext();
116 } 111 }
117 112
118 } // namespace chromeos 113 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698