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

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

Issue 23684042: Eliminate NetworkManagerChanged (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_prewarmer.h" 5 #include "chrome/browser/chromeos/login/auth_prewarmer.h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/chromeos/profiles/profile_helper.h" 8 #include "chrome/browser/chromeos/profiles/profile_helper.h"
9 #include "chrome/browser/net/chrome_url_request_context.h" 9 #include "chrome/browser/net/chrome_url_request_context.h"
10 #include "chrome/browser/net/preconnect.h" 10 #include "chrome/browser/net/preconnect.h"
(...skipping 29 matching lines...) Expand all
40 if (doing_prewarm_) { 40 if (doing_prewarm_) {
41 LOG(ERROR) << "PrewarmAuthentication called twice."; 41 LOG(ERROR) << "PrewarmAuthentication called twice.";
42 return; 42 return;
43 } 43 }
44 doing_prewarm_ = true; 44 doing_prewarm_ = true;
45 completion_callback_ = completion_callback; 45 completion_callback_ = completion_callback;
46 if (GetRequestContext() && IsNetworkConnected()) { 46 if (GetRequestContext() && IsNetworkConnected()) {
47 DoPrewarm(); 47 DoPrewarm();
48 return; 48 return;
49 } 49 }
50 if (!IsNetworkConnected()) 50 if (!IsNetworkConnected()) {
51 NetworkHandler::Get()->network_state_handler()->AddObserver(this, 51 // DefaultNetworkChanged will get called when a network becomes connected.
52 FROM_HERE); 52 NetworkHandler::Get()->network_state_handler()
53 ->AddObserver(this, FROM_HERE);
54 }
53 if (!GetRequestContext()) { 55 if (!GetRequestContext()) {
54 registrar_.Add( 56 registrar_.Add(
55 this, 57 this,
56 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, 58 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED,
57 content::Source<Profile>(ProfileHelper::GetSigninProfile())); 59 content::Source<Profile>(ProfileHelper::GetSigninProfile()));
58 } 60 }
59 } 61 }
60 62
61 void AuthPrewarmer::NetworkManagerChanged() {
62 if (IsNetworkConnected()) {
63 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
64 FROM_HERE);
65 if (GetRequestContext())
66 DoPrewarm();
67 }
68 }
69
70 void AuthPrewarmer::DefaultNetworkChanged(const NetworkState* network) { 63 void AuthPrewarmer::DefaultNetworkChanged(const NetworkState* network) {
71 NetworkManagerChanged(); 64 if (!network)
65 return; // Still no default (connected) network.
66
67 NetworkHandler::Get()->network_state_handler()
68 ->RemoveObserver(this, FROM_HERE);
69 if (GetRequestContext())
70 DoPrewarm();
72 } 71 }
73 72
74 void AuthPrewarmer::Observe(int type, 73 void AuthPrewarmer::Observe(int type,
75 const content::NotificationSource& source, 74 const content::NotificationSource& source,
76 const content::NotificationDetails& details) { 75 const content::NotificationDetails& details) {
77 switch (type) { 76 switch (type) {
78 case chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED: 77 case chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED:
79 registrar_.Remove( 78 registrar_.Remove(
80 this, 79 this,
81 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, 80 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); 113 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler();
115 return (nsh->ConnectedNetworkByType(NetworkStateHandler::kMatchTypeDefault) != 114 return (nsh->ConnectedNetworkByType(NetworkStateHandler::kMatchTypeDefault) !=
116 NULL); 115 NULL);
117 } 116 }
118 117
119 net::URLRequestContextGetter* AuthPrewarmer::GetRequestContext() const { 118 net::URLRequestContextGetter* AuthPrewarmer::GetRequestContext() const {
120 return ProfileHelper::GetSigninProfile()->GetRequestContext(); 119 return ProfileHelper::GetSigninProfile()->GetRequestContext();
121 } 120 }
122 121
123 } // namespace chromeos 122 } // namespace chromeos
124
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698