| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } | 341 } |
| 342 } else { | 342 } else { |
| 343 // We only care about the source URL when this fetches the logo. | 343 // We only care about the source URL when this fetches the logo. |
| 344 AppsPromo::SetSourcePromoLogoURL(GURL()); | 344 AppsPromo::SetSourcePromoLogoURL(GURL()); |
| 345 SavePromo(); | 345 SavePromo(); |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 | 348 |
| 349 AppsPromoLogoFetcher::~AppsPromoLogoFetcher() {} | 349 AppsPromoLogoFetcher::~AppsPromoLogoFetcher() {} |
| 350 | 350 |
| 351 void AppsPromoLogoFetcher::OnURLFetchComplete(const URLFetcher* source) { | 351 void AppsPromoLogoFetcher::OnURLFetchComplete( |
| 352 const content::URLFetcher* source) { |
| 352 std::string data; | 353 std::string data; |
| 353 std::string base64_data; | 354 std::string base64_data; |
| 354 | 355 |
| 355 CHECK(source == url_fetcher_.get()); | 356 CHECK(source == url_fetcher_.get()); |
| 356 source->GetResponseAsString(&data); | 357 source->GetResponseAsString(&data); |
| 357 | 358 |
| 358 if (source->status().is_success() && | 359 if (source->GetStatus().is_success() && |
| 359 source->response_code() == kHttpSuccess && | 360 source->GetResponseCode() == kHttpSuccess && |
| 360 base::Base64Encode(data, &base64_data)) { | 361 base::Base64Encode(data, &base64_data)) { |
| 361 AppsPromo::SetSourcePromoLogoURL(promo_data_.logo); | 362 AppsPromo::SetSourcePromoLogoURL(promo_data_.logo); |
| 362 promo_data_.logo = GURL(kPNGDataURLPrefix + base64_data); | 363 promo_data_.logo = GURL(kPNGDataURLPrefix + base64_data); |
| 363 } else { | 364 } else { |
| 364 // The logo wasn't downloaded correctly or we failed to encode it in | 365 // The logo wasn't downloaded correctly or we failed to encode it in |
| 365 // base64. Reset the source URL so we fetch it again next time. AppsPromo | 366 // base64. Reset the source URL so we fetch it again next time. AppsPromo |
| 366 // will revert to the default logo. | 367 // will revert to the default logo. |
| 367 AppsPromo::SetSourcePromoLogoURL(GURL()); | 368 AppsPromo::SetSourcePromoLogoURL(GURL()); |
| 368 } | 369 } |
| 369 | 370 |
| 370 SavePromo(); | 371 SavePromo(); |
| 371 } | 372 } |
| 372 | 373 |
| 373 void AppsPromoLogoFetcher::FetchLogo() { | 374 void AppsPromoLogoFetcher::FetchLogo() { |
| 374 CHECK(promo_data_.logo.scheme() == chrome::kHttpsScheme); | 375 CHECK(promo_data_.logo.scheme() == chrome::kHttpsScheme); |
| 375 | 376 |
| 376 url_fetcher_.reset(URLFetcher::Create( | 377 url_fetcher_.reset(URLFetcher::Create( |
| 377 0, promo_data_.logo, URLFetcher::GET, this)); | 378 0, promo_data_.logo, URLFetcher::GET, this)); |
| 378 url_fetcher_->set_request_context( | 379 url_fetcher_->SetRequestContext( |
| 379 g_browser_process->system_request_context()); | 380 g_browser_process->system_request_context()); |
| 380 url_fetcher_->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES | | 381 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 381 net::LOAD_DO_NOT_SAVE_COOKIES); | 382 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 382 url_fetcher_->Start(); | 383 url_fetcher_->Start(); |
| 383 } | 384 } |
| 384 | 385 |
| 385 bool AppsPromoLogoFetcher::HaveCachedLogo() { | 386 bool AppsPromoLogoFetcher::HaveCachedLogo() { |
| 386 return promo_data_.logo == AppsPromo::GetSourcePromoLogoURL(); | 387 return promo_data_.logo == AppsPromo::GetSourcePromoLogoURL(); |
| 387 } | 388 } |
| 388 | 389 |
| 389 void AppsPromoLogoFetcher::SavePromo() { | 390 void AppsPromoLogoFetcher::SavePromo() { |
| 390 AppsPromo::SetPromo(promo_data_); | 391 AppsPromo::SetPromo(promo_data_); |
| 391 | 392 |
| 392 content::NotificationService::current()->Notify( | 393 content::NotificationService::current()->Notify( |
| 393 chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, | 394 chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, |
| 394 content::Source<Profile>(profile_), | 395 content::Source<Profile>(profile_), |
| 395 content::NotificationService::NoDetails()); | 396 content::NotificationService::NoDetails()); |
| 396 } | 397 } |
| 397 | 398 |
| 398 bool AppsPromoLogoFetcher::SupportsLogoURL() { | 399 bool AppsPromoLogoFetcher::SupportsLogoURL() { |
| 399 URLPattern allowed_urls(URLPattern::SCHEME_HTTPS, kValidLogoPattern); | 400 URLPattern allowed_urls(URLPattern::SCHEME_HTTPS, kValidLogoPattern); |
| 400 return allowed_urls.MatchesURL(promo_data_.logo); | 401 return allowed_urls.MatchesURL(promo_data_.logo); |
| 401 } | 402 } |
| OLD | NEW |