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" |
11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" | |
14 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
18 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
19 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
20 #include "content/public/common/url_fetcher.h" | 19 #include "content/public/common/url_fetcher.h" |
21 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
22 #include "net/url_request/url_request_status.h" | 21 #include "net/url_request/url_request_status.h" |
23 | 22 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 // Otherwise, only show the app launcher if the web store is supported for the | 267 // Otherwise, only show the app launcher if the web store is supported for the |
269 // current locale. | 268 // current locale. |
270 return IsWebStoreSupportedForLocale(); | 269 return IsWebStoreSupportedForLocale(); |
271 #endif | 270 #endif |
272 } | 271 } |
273 | 272 |
274 void AppsPromo::ExpireDefaultApps() { | 273 void AppsPromo::ExpireDefaultApps() { |
275 SetPromoCounter(kDefaultAppsCounterMax + 1); | 274 SetPromoCounter(kDefaultAppsCounterMax + 1); |
276 } | 275 } |
277 | 276 |
278 void AppsPromo::MaximizeAppsIfNecessary() { | |
279 PromoData promo = GetPromo(); | |
280 | |
281 // Maximize the apps section of the NTP if this is the first time viewing the | |
282 // specific promo and the current user group is targetted. | |
283 if (GetLastPromoId() != promo.id) { | |
284 if ((promo.user_group & GetCurrentUserGroup()) != 0) | |
285 ShownSectionsHandler::SetShownSection(prefs_, APPS); | |
286 SetLastPromoId(promo.id); | |
287 } | |
288 } | |
289 | |
290 void AppsPromo::HidePromo() { | 277 void AppsPromo::HidePromo() { |
291 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, | 278 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
292 extension_misc::PROMO_CLOSE, | 279 extension_misc::PROMO_CLOSE, |
293 extension_misc::PROMO_BUCKET_BOUNDARY); | 280 extension_misc::PROMO_BUCKET_BOUNDARY); |
294 | 281 |
295 // Put the apps section into menu mode, and maximize the recent section. | |
296 ShownSectionsHandler::SetShownSection(prefs_, MENU_APPS); | |
297 ShownSectionsHandler::SetShownSection(prefs_, THUMB); | |
298 | |
299 ExpireDefaultApps(); | 282 ExpireDefaultApps(); |
300 } | 283 } |
301 | 284 |
302 std::string AppsPromo::GetLastPromoId() { | 285 std::string AppsPromo::GetLastPromoId() { |
303 return prefs_->GetString(prefs::kNTPWebStorePromoLastId); | 286 return prefs_->GetString(prefs::kNTPWebStorePromoLastId); |
304 } | 287 } |
305 | 288 |
306 void AppsPromo::SetLastPromoId(const std::string& id) { | 289 void AppsPromo::SetLastPromoId(const std::string& id) { |
307 prefs_->SetString(prefs::kNTPWebStorePromoLastId, id); | 290 prefs_->SetString(prefs::kNTPWebStorePromoLastId, id); |
308 } | 291 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 content::NotificationService::current()->Notify( | 376 content::NotificationService::current()->Notify( |
394 chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, | 377 chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, |
395 content::Source<Profile>(profile_), | 378 content::Source<Profile>(profile_), |
396 content::NotificationService::NoDetails()); | 379 content::NotificationService::NoDetails()); |
397 } | 380 } |
398 | 381 |
399 bool AppsPromoLogoFetcher::SupportsLogoURL() { | 382 bool AppsPromoLogoFetcher::SupportsLogoURL() { |
400 URLPattern allowed_urls(URLPattern::SCHEME_HTTPS, kValidLogoPattern); | 383 URLPattern allowed_urls(URLPattern::SCHEME_HTTPS, kValidLogoPattern); |
401 return allowed_urls.MatchesURL(promo_data_.logo); | 384 return allowed_urls.MatchesURL(promo_data_.logo); |
402 } | 385 } |
OLD | NEW |