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

Side by Side Diff: chrome/browser/chromeos/app_mode/startup_app_launcher.cc

Issue 149843004: kiosk: Skip network check for offline enabled app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 10 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/app_mode/startup_app_launcher.h" 5 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/json/json_file_value_serializer.h" 9 #include "base/json/json_file_value_serializer.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/ui/extensions/application_launch.h" 27 #include "chrome/browser/ui/extensions/application_launch.h"
28 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/chrome_version_info.h" 30 #include "chrome/common/chrome_version_info.h"
31 #include "chrome/common/extensions/manifest_url_handler.h" 31 #include "chrome/common/extensions/manifest_url_handler.h"
32 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
33 #include "content/public/browser/notification_service.h" 33 #include "content/public/browser/notification_service.h"
34 #include "extensions/browser/extension_system.h" 34 #include "extensions/browser/extension_system.h"
35 #include "extensions/common/extension.h" 35 #include "extensions/common/extension.h"
36 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" 36 #include "extensions/common/manifest_handlers/kiosk_mode_info.h"
37 #include "extensions/common/manifest_handlers/offline_enabled_info.h"
37 #include "google_apis/gaia/gaia_auth_consumer.h" 38 #include "google_apis/gaia/gaia_auth_consumer.h"
38 #include "google_apis/gaia/gaia_constants.h" 39 #include "google_apis/gaia/gaia_constants.h"
39 #include "net/base/load_flags.h" 40 #include "net/base/load_flags.h"
40 #include "net/url_request/url_fetcher.h" 41 #include "net/url_request/url_fetcher.h"
41 #include "net/url_request/url_fetcher_delegate.h" 42 #include "net/url_request/url_fetcher_delegate.h"
42 #include "net/url_request/url_request_context_getter.h" 43 #include "net/url_request/url_request_context_getter.h"
43 #include "net/url_request/url_request_status.h" 44 #include "net/url_request/url_request_status.h"
44 #include "url/gurl.h" 45 #include "url/gurl.h"
45 46
46 using content::BrowserThread; 47 using content::BrowserThread;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 Version browser_min_version(update.browser_min_version); 128 Version browser_min_version(update.browser_min_version);
128 if (browser_version.IsValid() && 129 if (browser_version.IsValid() &&
129 browser_min_version.IsValid() && 130 browser_min_version.IsValid() &&
130 browser_min_version.CompareTo(browser_version) > 0) { 131 browser_min_version.CompareTo(browser_version) > 0) {
131 launcher_->OnUpdateCheckNoUpdate(); 132 launcher_->OnUpdateCheckNoUpdate();
132 return; 133 return;
133 } 134 }
134 } 135 }
135 136
136 const Version& existing_version = *GetInstalledApp()->version(); 137 const Version& existing_version = *GetInstalledApp()->version();
137 Version update_version(update.version); 138 const Version update_version(update.version);
138 if (existing_version.IsValid() && 139 if (!update_version.IsValid() ||
139 update_version.IsValid() && 140 (existing_version.IsValid() &&
140 update_version.CompareTo(existing_version) <= 0) { 141 update_version.CompareTo(existing_version) <= 0)) {
141 launcher_->OnUpdateCheckNoUpdate(); 142 launcher_->OnUpdateCheckNoUpdate();
142 return; 143 return;
143 } 144 }
144 145
145 launcher_->OnUpdateCheckUpdateAvailable(); 146 launcher_->OnUpdateCheckUpdateAvailable();
146 } 147 }
147 148
148 // net::URLFetcherDelegate implementation. 149 // net::URLFetcherDelegate implementation.
149 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { 150 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE {
150 DCHECK_EQ(source, manifest_fetcher_.get()); 151 DCHECK_EQ(source, manifest_fetcher_.get());
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 UserManager::Get()->SetAppModeChromeClientOAuthInfo( 255 UserManager::Get()->SetAppModeChromeClientOAuthInfo(
255 auth_params_.client_id, 256 auth_params_.client_id,
256 auth_params_.client_secret); 257 auth_params_.client_secret);
257 } 258 }
258 259
259 // If we are restarting chrome (i.e. on crash), we need to initialize 260 // If we are restarting chrome (i.e. on crash), we need to initialize
260 // OAuth2TokenService as well. 261 // OAuth2TokenService as well.
261 InitializeTokenService(); 262 InitializeTokenService();
262 } 263 }
263 264
264 void StartupAppLauncher::InitializeNetwork() { 265 void StartupAppLauncher::MaybeInitializeNetwork() {
265 delegate_->InitializeNetwork(); 266 const Extension* extension = extensions::ExtensionSystem::Get(profile_)->
267 extension_service()->GetInstalledExtension(app_id_);
268 const bool requires_network = !extension ||
269 !extensions::OfflineEnabledInfo::IsOfflineEnabled(extension);
270
271 if (requires_network) {
272 delegate_->InitializeNetwork();
273 return;
274 }
275
276 // Offline enabled app attempts update if network is ready. Otherwise,
277 // go directly to launch.
278 if (delegate_->IsNetworkReady())
279 ContinueWithNetworkReady();
280 else
281 OnReadyToLaunch();
266 } 282 }
267 283
268 void StartupAppLauncher::InitializeTokenService() { 284 void StartupAppLauncher::InitializeTokenService() {
269 delegate_->OnInitializingTokenService(); 285 delegate_->OnInitializingTokenService();
270 286
271 ProfileOAuth2TokenService* profile_token_service = 287 ProfileOAuth2TokenService* profile_token_service =
272 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 288 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
273 SigninManagerBase* signin_manager = 289 SigninManagerBase* signin_manager =
274 SigninManagerFactory::GetForProfile(profile_); 290 SigninManagerFactory::GetForProfile(profile_);
275 if (profile_token_service->RefreshTokenIsAvailable( 291 if (profile_token_service->RefreshTokenIsAvailable(
276 signin_manager->GetAuthenticatedAccountId()) || 292 signin_manager->GetAuthenticatedAccountId()) ||
277 auth_params_.refresh_token.empty()) { 293 auth_params_.refresh_token.empty()) {
278 InitializeNetwork(); 294 MaybeInitializeNetwork();
279 } else { 295 } else {
280 // Pass oauth2 refresh token from the auth file. 296 // Pass oauth2 refresh token from the auth file.
281 // TODO(zelidrag): We should probably remove this option after M27. 297 // TODO(zelidrag): We should probably remove this option after M27.
282 // TODO(fgorski): This can go when we have persistence implemented on PO2TS. 298 // TODO(fgorski): This can go when we have persistence implemented on PO2TS.
283 // Unless the code is no longer needed. 299 // Unless the code is no longer needed.
284 // TODO(rogerta): Now that this CL implements token persistence in PO2TS, is 300 // TODO(rogerta): Now that this CL implements token persistence in PO2TS, is
285 // this code still needed? See above two TODOs. 301 // this code still needed? See above two TODOs.
286 // 302 //
287 // ProfileOAuth2TokenService triggers either OnRefreshTokenAvailable or 303 // ProfileOAuth2TokenService triggers either OnRefreshTokenAvailable or
288 // OnRefreshTokensLoaded. Given that we want to handle exactly one event, 304 // OnRefreshTokensLoaded. Given that we want to handle exactly one event,
289 // whichever comes first, both handlers call RemoveObserver on PO2TS. 305 // whichever comes first, both handlers call RemoveObserver on PO2TS.
290 // Handling any of the two events is the only way to resume the execution 306 // Handling any of the two events is the only way to resume the execution
291 // and enable Cleanup method to be called, self-invoking a destructor. 307 // and enable Cleanup method to be called, self-invoking a destructor.
292 profile_token_service->AddObserver(this); 308 profile_token_service->AddObserver(this);
293 309
294 profile_token_service->UpdateCredentials( 310 profile_token_service->UpdateCredentials(
295 "kiosk_mode@localhost", 311 "kiosk_mode@localhost",
296 auth_params_.refresh_token); 312 auth_params_.refresh_token);
297 } 313 }
298 } 314 }
299 315
300 void StartupAppLauncher::OnRefreshTokenAvailable( 316 void StartupAppLauncher::OnRefreshTokenAvailable(
301 const std::string& account_id) { 317 const std::string& account_id) {
302 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) 318 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)
303 ->RemoveObserver(this); 319 ->RemoveObserver(this);
304 InitializeNetwork(); 320 MaybeInitializeNetwork();
305 } 321 }
306 322
307 void StartupAppLauncher::OnRefreshTokensLoaded() { 323 void StartupAppLauncher::OnRefreshTokensLoaded() {
308 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) 324 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)
309 ->RemoveObserver(this); 325 ->RemoveObserver(this);
310 InitializeNetwork(); 326 MaybeInitializeNetwork();
311 } 327 }
312 328
313 void StartupAppLauncher::LaunchApp() { 329 void StartupAppLauncher::LaunchApp() {
314 if (!ready_to_launch_) { 330 if (!ready_to_launch_) {
315 NOTREACHED(); 331 NOTREACHED();
316 LOG(ERROR) << "LaunchApp() called but launcher is not initialized."; 332 LOG(ERROR) << "LaunchApp() called but launcher is not initialized.";
317 } 333 }
318 334
319 const Extension* extension = extensions::ExtensionSystem::Get(profile_)-> 335 const Extension* extension = extensions::ExtensionSystem::Get(profile_)->
320 extension_service()->GetInstalledExtension(app_id_); 336 extension_service()->GetInstalledExtension(app_id_);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 ready_to_launch_ = true; 435 ready_to_launch_ = true;
420 delegate_->OnReadyToLaunch(); 436 delegate_->OnReadyToLaunch();
421 } 437 }
422 438
423 void StartupAppLauncher::UpdateAppData() { 439 void StartupAppLauncher::UpdateAppData() {
424 KioskAppManager::Get()->ClearAppData(app_id_); 440 KioskAppManager::Get()->ClearAppData(app_id_);
425 KioskAppManager::Get()->UpdateAppDataFromProfile(app_id_, profile_, NULL); 441 KioskAppManager::Get()->UpdateAppDataFromProfile(app_id_, profile_, NULL);
426 } 442 }
427 443
428 } // namespace chromeos 444 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/app_mode/startup_app_launcher.h ('k') | chrome/browser/chromeos/login/app_launch_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698