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

Side by Side Diff: chrome/browser/extensions/apps_promo.cc

Issue 10831058: Delete AppPromoLogoFetcher (dead code) (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/apps_promo.h" 5 #include "chrome/browser/extensions/apps_promo.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 17 matching lines...) Expand all
28 const char kDefaultLogo[] = "chrome://theme/IDR_WEBSTORE_ICON"; 28 const char kDefaultLogo[] = "chrome://theme/IDR_WEBSTORE_ICON";
29 29
30 // The default promo data (this is only used for testing with 30 // The default promo data (this is only used for testing with
31 // --force-apps-promo-visible). 31 // --force-apps-promo-visible).
32 const char kDefaultHeader[] = "Browse thousands of apps and games for Chrome"; 32 const char kDefaultHeader[] = "Browse thousands of apps and games for Chrome";
33 const char kDefaultButton[] = "Visit the Chrome Web Store"; 33 const char kDefaultButton[] = "Visit the Chrome Web Store";
34 const char kDefaultExpire[] = "No thanks"; 34 const char kDefaultExpire[] = "No thanks";
35 const char kDefaultLink[] = "https://chrome.google.com/webstore"; 35 const char kDefaultLink[] = "https://chrome.google.com/webstore";
36 36
37 // Http success status code. 37 // Http success status code.
38 const int kHttpSuccess = 200; 38 const int kHttpSuccess = 200;
Mihai Parparita -not on Chrome 2012/07/29 18:17:16 And this constant (and kValidLogoPattern, and poss
39 39
40 // The match pattern for valid logo URLs. 40 // The match pattern for valid logo URLs.
41 const char kValidLogoPattern[] = "https://*.google.com/*.png"; 41 const char kValidLogoPattern[] = "https://*.google.com/*.png";
42 42
43 // The prefix for 'data' URL images. 43 // The prefix for 'data' URL images.
44 const char kPNGDataURLPrefix[] = "data:image/png;base64,"; 44 const char kPNGDataURLPrefix[] = "data:image/png;base64,";
45 45
46 // Returns the string pref at |path|, using |fallback| as the default (if there 46 // Returns the string pref at |path|, using |fallback| as the default (if there
47 // is no pref value present). |fallback| is used for debugging in concert with 47 // is no pref value present). |fallback| is used for debugging in concert with
48 // --force-apps-promo-visible. 48 // --force-apps-promo-visible.
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 bool AppsPromo::GetDefaultAppsInstalled() const { 302 bool AppsPromo::GetDefaultAppsInstalled() const {
303 return prefs_->GetBoolean(prefs::kDefaultAppsInstalled); 303 return prefs_->GetBoolean(prefs::kDefaultAppsInstalled);
304 } 304 }
305 305
306 AppsPromo::UserGroup AppsPromo::GetCurrentUserGroup() const { 306 AppsPromo::UserGroup AppsPromo::GetCurrentUserGroup() const {
307 const PrefService::Preference* last_promo_id 307 const PrefService::Preference* last_promo_id
308 = prefs_->FindPreference(prefs::kNtpWebStorePromoLastId); 308 = prefs_->FindPreference(prefs::kNtpWebStorePromoLastId);
309 CHECK(last_promo_id); 309 CHECK(last_promo_id);
310 return last_promo_id->IsDefaultValue() ? USERS_NEW : USERS_EXISTING; 310 return last_promo_id->IsDefaultValue() ? USERS_NEW : USERS_EXISTING;
311 } 311 }
312
313 AppsPromoLogoFetcher::AppsPromoLogoFetcher(
314 Profile* profile,
315 const AppsPromo::PromoData& promo_data)
316 : profile_(profile),
317 promo_data_(promo_data) {
318 if (SupportsLogoURL()) {
319 if (HaveCachedLogo()) {
320 promo_data_.logo = AppsPromo::GetPromo().logo;
321 SavePromo();
322 } else {
323 FetchLogo();
324 }
325 } else {
326 // We only care about the source URL when this fetches the logo.
327 AppsPromo::SetSourcePromoLogoURL(GURL());
328 SavePromo();
329 }
330 }
331
332 AppsPromoLogoFetcher::~AppsPromoLogoFetcher() {}
333
334 void AppsPromoLogoFetcher::OnURLFetchComplete(
335 const net::URLFetcher* source) {
336 std::string data;
337 std::string base64_data;
338
339 CHECK(source == url_fetcher_.get());
340 source->GetResponseAsString(&data);
341
342 if (source->GetStatus().is_success() &&
343 source->GetResponseCode() == kHttpSuccess &&
344 base::Base64Encode(data, &base64_data)) {
345 AppsPromo::SetSourcePromoLogoURL(promo_data_.logo);
346 promo_data_.logo = GURL(kPNGDataURLPrefix + base64_data);
347 } else {
348 // The logo wasn't downloaded correctly or we failed to encode it in
349 // base64. Reset the source URL so we fetch it again next time. AppsPromo
350 // will revert to the default logo.
351 AppsPromo::SetSourcePromoLogoURL(GURL());
352 }
353
354 SavePromo();
355 }
356
357 void AppsPromoLogoFetcher::FetchLogo() {
358 CHECK(promo_data_.logo.scheme() == chrome::kHttpsScheme);
359
360 url_fetcher_.reset(net::URLFetcher::Create(
361 0, promo_data_.logo, net::URLFetcher::GET, this));
362 url_fetcher_->SetRequestContext(
363 g_browser_process->system_request_context());
364 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
365 net::LOAD_DO_NOT_SAVE_COOKIES);
366 url_fetcher_->Start();
367 }
368
369 bool AppsPromoLogoFetcher::HaveCachedLogo() {
370 return promo_data_.logo == AppsPromo::GetSourcePromoLogoURL();
371 }
372
373 void AppsPromoLogoFetcher::SavePromo() {
374 AppsPromo::SetPromo(promo_data_);
375
376 content::NotificationService::current()->Notify(
377 chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED,
378 content::Source<Profile>(profile_),
379 content::NotificationService::NoDetails());
380 }
381
382 bool AppsPromoLogoFetcher::SupportsLogoURL() {
383 URLPattern allowed_urls(URLPattern::SCHEME_HTTPS, kValidLogoPattern);
384 return allowed_urls.MatchesURL(promo_data_.logo);
385 }
OLDNEW
« chrome/browser/extensions/apps_promo.h ('K') | « chrome/browser/extensions/apps_promo.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698