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

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_resource_cache.cc

Issue 12985002: Add a new App launcher promo to the apps page / NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: OWNERS review round 4. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_resource_cache.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 (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/ui/webui/ntp/ntp_resource_cache.h" 5 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "apps/app_launcher.h" 10 #include "apps/app_launcher.h"
11 #include "apps/field_trial_names.h"
12 #include "apps/pref_names.h"
11 #include "base/command_line.h" 13 #include "base/command_line.h"
12 #include "base/file_util.h" 14 #include "base/file_util.h"
13 #include "base/memory/ref_counted_memory.h" 15 #include "base/memory/ref_counted_memory.h"
16 #include "base/metrics/field_trial.h"
14 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
15 #include "base/string16.h" 18 #include "base/string16.h"
16 #include "base/stringprintf.h" 19 #include "base/stringprintf.h"
17 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
18 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
19 #include "base/values.h" 22 #include "base/values.h"
20 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/first_run/first_run.h" 24 #include "chrome/browser/first_run/first_run.h"
22 #include "chrome/browser/google/google_util.h" 25 #include "chrome/browser/google/google_util.h"
23 #include "chrome/browser/policy/browser_policy_connector.h" 26 #include "chrome/browser/policy/browser_policy_connector.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 176 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
174 content::Source<ThemeService>( 177 content::Source<ThemeService>(
175 ThemeServiceFactory::GetForProfile(profile))); 178 ThemeServiceFactory::GetForProfile(profile)));
176 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, 179 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
177 content::NotificationService::AllSources()); 180 content::NotificationService::AllSources());
178 181
179 base::Closure callback = base::Bind(&NTPResourceCache::OnPreferenceChanged, 182 base::Closure callback = base::Bind(&NTPResourceCache::OnPreferenceChanged,
180 base::Unretained(this)); 183 base::Unretained(this));
181 184
182 // Watch for pref changes that cause us to need to invalidate the HTML cache. 185 // Watch for pref changes that cause us to need to invalidate the HTML cache.
183 pref_change_registrar_.Init(profile_->GetPrefs()); 186 profile_pref_change_registrar_.Init(profile_->GetPrefs());
184 pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, callback); 187 profile_pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes,
185 pref_change_registrar_.Add(prefs::kShowBookmarkBar, callback); 188 callback);
186 pref_change_registrar_.Add(prefs::kNtpShownPage, callback); 189 profile_pref_change_registrar_.Add(prefs::kShowBookmarkBar, callback);
187 pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, callback); 190 profile_pref_change_registrar_.Add(prefs::kNtpShownPage, callback);
188 pref_change_registrar_.Add(prefs::kHideWebStoreIcon, callback); 191 profile_pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, callback);
192 profile_pref_change_registrar_.Add(prefs::kHideWebStoreIcon, callback);
193
194 // Some tests don't have a local state.
195 if (g_browser_process->local_state()) {
196 local_state_pref_change_registrar_.Init(g_browser_process->local_state());
197 local_state_pref_change_registrar_.Add(apps::prefs::kShowAppLauncherPromo,
198 callback);
199 }
189 } 200 }
190 201
191 NTPResourceCache::~NTPResourceCache() {} 202 NTPResourceCache::~NTPResourceCache() {}
192 203
193 bool NTPResourceCache::NewTabCacheNeedsRefresh() { 204 bool NTPResourceCache::NewTabCacheNeedsRefresh() {
194 #if defined(OS_MACOSX) 205 #if defined(OS_MACOSX)
195 // Invalidate if the current value is different from the cached value. 206 // Invalidate if the current value is different from the cached value.
196 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled(); 207 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled();
197 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) { 208 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) {
198 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled; 209 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 325
315 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); 326 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html);
316 } 327 }
317 328
318 void NTPResourceCache::CreateNewTabHTML() { 329 void NTPResourceCache::CreateNewTabHTML() {
319 // TODO(estade): these strings should be defined in their relevant handlers 330 // TODO(estade): these strings should be defined in their relevant handlers
320 // (in GetLocalizedValues) and should have more legible names. 331 // (in GetLocalizedValues) and should have more legible names.
321 // Show the profile name in the title and most visited labels if the current 332 // Show the profile name in the title and most visited labels if the current
322 // profile is not the default. 333 // profile is not the default.
323 PrefService* prefs = profile_->GetPrefs(); 334 PrefService* prefs = profile_->GetPrefs();
335 PrefService* local_state = g_browser_process->local_state();
324 DictionaryValue load_time_data; 336 DictionaryValue load_time_data;
325 load_time_data.SetBoolean("bookmarkbarattached", 337 load_time_data.SetBoolean("bookmarkbarattached",
326 prefs->GetBoolean(prefs::kShowBookmarkBar)); 338 prefs->GetBoolean(prefs::kShowBookmarkBar));
327 load_time_data.SetBoolean("hasattribution", 339 load_time_data.SetBoolean("hasattribution",
328 ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage( 340 ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage(
329 IDR_THEME_NTP_ATTRIBUTION)); 341 IDR_THEME_NTP_ATTRIBUTION));
330 load_time_data.SetBoolean("showMostvisited", should_show_most_visited_page_); 342 load_time_data.SetBoolean("showMostvisited", should_show_most_visited_page_);
343 std::string app_launcher_promo_group_name =
344 base::FieldTrialList::FindFullName(apps::kLauncherPromoTrialName);
345 bool show_app_launcher_promo =
346 local_state->GetBoolean(apps::prefs::kShowAppLauncherPromo) &&
347 (app_launcher_promo_group_name == apps::kShowLauncherPromoOnceGroupName ||
348 app_launcher_promo_group_name ==
349 apps::kResetShowLauncherPromoPrefGroupName);
350 load_time_data.SetBoolean("showAppLauncherPromo", show_app_launcher_promo);
331 load_time_data.SetBoolean("showRecentlyClosed", 351 load_time_data.SetBoolean("showRecentlyClosed",
332 should_show_recently_closed_menu_); 352 should_show_recently_closed_menu_);
333 load_time_data.SetString("title", 353 load_time_data.SetString("title",
334 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); 354 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
335 load_time_data.SetString("mostvisited", 355 load_time_data.SetString("mostvisited",
336 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED)); 356 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED));
337 load_time_data.SetString("suggestions", 357 load_time_data.SetString("suggestions",
338 l10n_util::GetStringUTF16(IDS_NEW_TAB_SUGGESTIONS)); 358 l10n_util::GetStringUTF16(IDS_NEW_TAB_SUGGESTIONS));
339 load_time_data.SetString("restoreThumbnailsShort", 359 load_time_data.SetString("restoreThumbnailsShort",
340 l10n_util::GetStringUTF16(IDS_NEW_TAB_RESTORE_THUMBNAILS_SHORT_LINK)); 360 l10n_util::GetStringUTF16(IDS_NEW_TAB_RESTORE_THUMBNAILS_SHORT_LINK));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 load_time_data.SetString("restoreSessionMenuItemText", 419 load_time_data.SetString("restoreSessionMenuItemText",
400 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_OPEN_ALL)); 420 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_OPEN_ALL));
401 load_time_data.SetString("learn_more", 421 load_time_data.SetString("learn_more",
402 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); 422 l10n_util::GetStringUTF16(IDS_LEARN_MORE));
403 load_time_data.SetString("tile_grid_screenreader_accessible_description", 423 load_time_data.SetString("tile_grid_screenreader_accessible_description",
404 l10n_util::GetStringUTF16(IDS_NEW_TAB_TILE_GRID_ACCESSIBLE_DESCRIPTION)); 424 l10n_util::GetStringUTF16(IDS_NEW_TAB_TILE_GRID_ACCESSIBLE_DESCRIPTION));
405 load_time_data.SetString("page_switcher_change_title", 425 load_time_data.SetString("page_switcher_change_title",
406 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_CHANGE_TITLE)); 426 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_CHANGE_TITLE));
407 load_time_data.SetString("page_switcher_same_title", 427 load_time_data.SetString("page_switcher_same_title",
408 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_SAME_TITLE)); 428 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_SAME_TITLE));
429 load_time_data.SetString("appsPromoTitle",
430 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_APPS_PROMO_TITLE));
409 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or 431 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or
410 // forward gesture. Pass through a flag that indicates whether or not that 432 // forward gesture. Pass through a flag that indicates whether or not that
411 // feature is enabled. 433 // feature is enabled.
412 load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", 434 load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled",
413 is_swipe_tracking_from_scroll_events_enabled_); 435 is_swipe_tracking_from_scroll_events_enabled_);
414 load_time_data.SetBoolean("showApps", should_show_apps_page_); 436 load_time_data.SetBoolean("showApps", should_show_apps_page_);
415 load_time_data.SetBoolean("showWebStoreIcon", 437 load_time_data.SetBoolean("showWebStoreIcon",
416 !prefs->GetBoolean(prefs::kHideWebStoreIcon)); 438 !prefs->GetBoolean(prefs::kHideWebStoreIcon));
417 439
418 #if defined(OS_CHROMEOS) 440 #if defined(OS_CHROMEOS)
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // Get our template. 615 // Get our template.
594 static const base::StringPiece new_tab_theme_css( 616 static const base::StringPiece new_tab_theme_css(
595 ResourceBundle::GetSharedInstance().GetRawDataResource( 617 ResourceBundle::GetSharedInstance().GetRawDataResource(
596 IDR_NEW_TAB_4_THEME_CSS)); 618 IDR_NEW_TAB_4_THEME_CSS));
597 619
598 // Create the string from our template and the replacements. 620 // Create the string from our template and the replacements.
599 std::string css_string; 621 std::string css_string;
600 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); 622 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL);
601 new_tab_css_ = base::RefCountedString::TakeString(&css_string); 623 new_tab_css_ = base::RefCountedString::TakeString(&css_string);
602 } 624 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_resource_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698