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

Side by Side Diff: chrome/browser/installable/installable_manager.cc

Issue 2751343002: Adds a basic offline check to InstallableManager. (Closed)
Patch Set: Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/installable/installable_manager.h" 5 #include "chrome/browser/installable/installable_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "chrome/browser/manifest/manifest_icon_downloader.h" 10 #include "chrome/browser/manifest/manifest_icon_downloader.h"
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 content::WebContents* web_contents = GetWebContents(); 399 content::WebContents* web_contents = GetWebContents();
400 400
401 // Check to see if there is a single service worker controlling this page 401 // Check to see if there is a single service worker controlling this page
402 // and the manifest's start url. 402 // and the manifest's start url.
403 content::StoragePartition* storage_partition = 403 content::StoragePartition* storage_partition =
404 content::BrowserContext::GetStoragePartition( 404 content::BrowserContext::GetStoragePartition(
405 Profile::FromBrowserContext(web_contents->GetBrowserContext()), 405 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
406 web_contents->GetSiteInstance()); 406 web_contents->GetSiteInstance());
407 DCHECK(storage_partition); 407 DCHECK(storage_partition);
408 408
409 storage_partition->GetServiceWorkerContext()->CheckHasServiceWorker( 409 storage_partition->GetServiceWorkerContext()->CheckServiceWorkerStatus(
410 web_contents->GetLastCommittedURL(), manifest().start_url, 410 web_contents->GetLastCommittedURL(), manifest().start_url,
411 base::Bind(&InstallableManager::OnDidCheckHasServiceWorker, 411 base::Bind(&InstallableManager::OnDidCheckServiceWorkerStatus,
412 weak_factory_.GetWeakPtr())); 412 weak_factory_.GetWeakPtr()));
413 } 413 }
414 414
415 void InstallableManager::OnDidCheckHasServiceWorker(bool has_service_worker) { 415 void InstallableManager::OnDidCheckServiceWorkerStatus(
416 content::ServiceWorkerStatus sw_status) {
dominickn 2017/03/16 06:21:56 Nit: Call the variable status for consistency with
piotrs 2017/03/17 02:21:37 Done.
416 if (!GetWebContents()) 417 if (!GetWebContents())
417 return; 418 return;
418 419
419 if (has_service_worker) { 420 switch (sw_status) {
420 installable_->installable = true; 421 case content::ServiceWorkerStatus::SERVICE_WORKER_WITH_FETCH_HANDLER:
421 } else { 422 installable_->installable = true;
422 installable_->installable = false; 423 break;
423 installable_->error = NO_MATCHING_SERVICE_WORKER; 424 case content::ServiceWorkerStatus::SERVICE_WORKER_NO_FETCH_HANDLER:
425 installable_->installable = false;
426 installable_->error = NO_SERVICE_WORKER_FETCH_HANDLER;
427 break;
428 case content::ServiceWorkerStatus::NO_SERVICE_WORKER:
429 installable_->installable = false;
430 installable_->error = NO_MATCHING_SERVICE_WORKER;
431 break;
424 } 432 }
425 433
426 installable_->fetched = true; 434 installable_->fetched = true;
427 WorkOnTask(); 435 WorkOnTask();
428 } 436 }
429 437
430 void InstallableManager::CheckAndFetchBestIcon(const IconParams& params) { 438 void InstallableManager::CheckAndFetchBestIcon(const IconParams& params) {
431 DCHECK(!manifest().IsEmpty()); 439 DCHECK(!manifest().IsEmpty());
432 440
433 int ideal_icon_size_in_px = std::get<0>(params); 441 int ideal_icon_size_in_px = std::get<0>(params);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 return manifest_->url; 499 return manifest_->url;
492 } 500 }
493 501
494 const content::Manifest& InstallableManager::manifest() const { 502 const content::Manifest& InstallableManager::manifest() const {
495 return manifest_->manifest; 503 return manifest_->manifest;
496 } 504 }
497 505
498 bool InstallableManager::is_installable() const { 506 bool InstallableManager::is_installable() const {
499 return installable_->installable; 507 return installable_->installable;
500 } 508 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698