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

Side by Side Diff: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc

Issue 2768083004: Use OneShotTimer in AddToHomescreenDataFetcher (Closed)
Patch Set: Timer addressing comments 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
« no previous file with comments | « chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/android/webapps/add_to_homescreen_data_fetcher.h" 5 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 18 matching lines...) Expand all
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 #include "content/public/browser/web_contents_observer.h" 30 #include "content/public/browser/web_contents_observer.h"
31 #include "content/public/common/manifest.h" 31 #include "content/public/common/manifest.h"
32 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" 32 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h"
33 #include "ui/gfx/codec/png_codec.h" 33 #include "ui/gfx/codec/png_codec.h"
34 #include "ui/gfx/favicon_size.h" 34 #include "ui/gfx/favicon_size.h"
35 #include "url/gurl.h" 35 #include "url/gurl.h"
36 36
37 namespace { 37 namespace {
38 38
39 // The default number of milliseconds to wait for the data download to complete.
40 const int kDataTimeoutInMilliseconds = 4000;
41
39 // Looks up the original, online URL of the site requested. The URL from the 42 // Looks up the original, online URL of the site requested. The URL from the
40 // WebContents may be a distilled article which is not appropriate for a home 43 // WebContents may be a distilled article which is not appropriate for a home
41 // screen shortcut. 44 // screen shortcut.
42 GURL GetShortcutUrl(content::BrowserContext* browser_context, 45 GURL GetShortcutUrl(content::BrowserContext* browser_context,
43 const GURL& actual_url) { 46 const GURL& actual_url) {
44 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); 47 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url);
45 } 48 }
46 49
47 InstallableParams ParamsToPerformInstallableCheck( 50 InstallableParams ParamsToPerformInstallableCheck(
48 int ideal_icon_size_in_px, 51 int ideal_icon_size_in_px,
(...skipping 25 matching lines...) Expand all
74 bool check_webapk_compatibility, 77 bool check_webapk_compatibility,
75 Observer* observer) 78 Observer* observer)
76 : WebContentsObserver(web_contents), 79 : WebContentsObserver(web_contents),
77 background_task_runner_( 80 background_task_runner_(
78 content::BrowserThread::GetBlockingPool() 81 content::BrowserThread::GetBlockingPool()
79 ->GetTaskRunnerWithShutdownBehavior( 82 ->GetTaskRunnerWithShutdownBehavior(
80 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), 83 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
81 weak_observer_(observer), 84 weak_observer_(observer),
82 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(), 85 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(),
83 web_contents->GetLastCommittedURL())), 86 web_contents->GetLastCommittedURL())),
84 data_timeout_timer_(false, false),
85 ideal_icon_size_in_px_(ideal_icon_size_in_px), 87 ideal_icon_size_in_px_(ideal_icon_size_in_px),
86 minimum_icon_size_in_px_(minimum_icon_size_in_px), 88 minimum_icon_size_in_px_(minimum_icon_size_in_px),
87 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px), 89 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px),
88 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px), 90 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px),
89 badge_size_in_px_(badge_size_in_px), 91 badge_size_in_px_(badge_size_in_px),
90 check_webapk_compatibility_(check_webapk_compatibility), 92 check_webapk_compatibility_(check_webapk_compatibility),
91 is_waiting_for_web_application_info_(true), 93 is_waiting_for_web_application_info_(true),
92 is_installable_check_complete_(false), 94 is_installable_check_complete_(false),
93 is_icon_saved_(false), 95 is_icon_saved_(false),
94 is_ready_(false) { 96 is_ready_(false) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 143 }
142 144
143 InstallableManager::CreateForWebContents(web_contents()); 145 InstallableManager::CreateForWebContents(web_contents());
144 InstallableManager* manager = 146 InstallableManager* manager =
145 InstallableManager::FromWebContents(web_contents()); 147 InstallableManager::FromWebContents(web_contents());
146 DCHECK(manager); 148 DCHECK(manager);
147 149
148 // Kick off a timeout for downloading data. If we haven't finished within the 150 // Kick off a timeout for downloading data. If we haven't finished within the
149 // timeout, fall back to using a dynamically-generated launcher icon. 151 // timeout, fall back to using a dynamically-generated launcher icon.
150 data_timeout_timer_.Start( 152 data_timeout_timer_.Start(
151 FROM_HERE, base::TimeDelta::FromMilliseconds(4000), 153 FROM_HERE, base::TimeDelta::FromMilliseconds(kDataTimeoutInMilliseconds),
152 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this)); 154 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this));
153 155
154 manager->GetData( 156 manager->GetData(
155 ParamsToPerformInstallableCheck(ideal_icon_size_in_px_, 157 ParamsToPerformInstallableCheck(ideal_icon_size_in_px_,
156 minimum_icon_size_in_px_, 158 minimum_icon_size_in_px_,
157 badge_size_in_px_, 159 badge_size_in_px_,
158 check_webapk_compatibility_), 160 check_webapk_compatibility_),
159 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, 161 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck,
160 this)); 162 this));
161 } 163 }
(...skipping 22 matching lines...) Expand all
184 if (!web_contents() || !weak_observer_) 186 if (!web_contents() || !weak_observer_)
185 return; 187 return;
186 188
187 if (!is_installable_check_complete_) { 189 if (!is_installable_check_complete_) {
188 is_installable_check_complete_ = true; 190 is_installable_check_complete_ = true;
189 if (check_webapk_compatibility_) 191 if (check_webapk_compatibility_)
190 weak_observer_->OnDidDetermineWebApkCompatibility(false); 192 weak_observer_->OnDidDetermineWebApkCompatibility(false);
191 weak_observer_->OnUserTitleAvailable(base::string16()); 193 weak_observer_->OnUserTitleAvailable(base::string16());
192 } 194 }
193 195
194 if (!is_icon_saved_) { 196 badge_icon_.reset();
195 badge_icon_.reset(); 197 CreateLauncherIcon(SkBitmap());
196 CreateLauncherIcon(SkBitmap());
197 }
198 } 198 }
199 199
200 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( 200 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck(
201 const InstallableData& data) { 201 const InstallableData& data) {
202 data_timeout_timer_.Stop();
202 badge_icon_.reset(); 203 badge_icon_.reset();
203 204
204 if (!web_contents() || !weak_observer_ || is_installable_check_complete_) 205 if (!web_contents() || !weak_observer_ || is_installable_check_complete_)
205 return; 206 return;
206 207
207 is_installable_check_complete_ = true; 208 is_installable_check_complete_ = true;
208 209
209 bool webapk_compatible = false; 210 bool webapk_compatible = false;
210 if (check_webapk_compatibility_) { 211 if (check_webapk_compatibility_) {
211 webapk_compatible = (data.error_code == NO_ERROR_DETECTED && 212 webapk_compatible = (data.error_code == NO_ERROR_DETECTED &&
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { 340 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) {
340 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 341 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
341 if (!web_contents() || !weak_observer_ || is_icon_saved_) 342 if (!web_contents() || !weak_observer_ || is_icon_saved_)
342 return; 343 return;
343 344
344 is_icon_saved_ = true; 345 is_icon_saved_ = true;
345 primary_icon_ = primary_icon; 346 primary_icon_ = primary_icon;
346 is_ready_ = true; 347 is_ready_ = true;
347 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); 348 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_);
348 } 349 }
OLDNEW
« no previous file with comments | « chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698