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

Side by Side Diff: chrome/browser/ui/webui/sync_promo_ui.cc

Issue 8093016: Show sync promo at startup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build error Created 9 years, 2 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/sync_promo_ui.h ('k') | chrome/common/pref_names.h » ('j') | 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) 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/ui/webui/sync_promo_ui.h" 5 #include "chrome/browser/ui/webui/sync_promo_ui.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/first_run/first_run.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 11 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
10 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 12 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
11 #include "chrome/browser/ui/webui/sync_promo_handler.h" 13 #include "chrome/browser/ui/webui/sync_promo_handler.h"
12 #include "chrome/browser/ui/webui/theme_source.h" 14 #include "chrome/browser/ui/webui/theme_source.h"
13 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/pref_names.h"
14 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
15 #include "content/browser/tab_contents/tab_contents.h" 18 #include "content/browser/tab_contents/tab_contents.h"
16 #include "grit/browser_resources.h" 19 #include "grit/browser_resources.h"
17 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
18 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
20 23
21 namespace { 24 namespace {
22 25
23 const char kStringsJsFile[] = "strings.js"; 26 const char kStringsJsFile[] = "strings.js";
24 const char kSyncPromoJsFile[] = "sync_promo.js"; 27 const char kSyncPromoJsFile[] = "sync_promo.js";
25 28
29 // The maximum number of times we want to show the sync promo at startup.
30 const int kSyncPromoShowAtStartupMaxiumum = 10;
31
32 void RegisterSyncPromoPrefs(Profile* profile) {
33 if (!profile->GetPrefs()->FindPreference(prefs::kSyncPromoStartupCount)) {
34 profile->GetPrefs()->RegisterIntegerPref(
35 prefs::kSyncPromoStartupCount, 0, PrefService::UNSYNCABLE_PREF);
36 }
37 }
38
26 // The Web UI data source for the sync promo page. 39 // The Web UI data source for the sync promo page.
27 class SyncPromoUIHTMLSource : public ChromeWebUIDataSource { 40 class SyncPromoUIHTMLSource : public ChromeWebUIDataSource {
28 public: 41 public:
29 SyncPromoUIHTMLSource(); 42 SyncPromoUIHTMLSource();
30 43
31 private: 44 private:
32 ~SyncPromoUIHTMLSource() {} 45 ~SyncPromoUIHTMLSource() {}
33 DISALLOW_COPY_AND_ASSIGN(SyncPromoUIHTMLSource); 46 DISALLOW_COPY_AND_ASSIGN(SyncPromoUIHTMLSource);
34 }; 47 };
35 48
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #if defined(OS_CHROMEOS) 80 #if defined(OS_CHROMEOS)
68 // There's no need to show the sync promo on cros since cros users are logged 81 // There's no need to show the sync promo on cros since cros users are logged
69 // into sync already. 82 // into sync already.
70 return false; 83 return false;
71 #endif 84 #endif
72 85
73 // Temporarily hide this feature behind a command line flag. 86 // Temporarily hide this feature behind a command line flag.
74 CommandLine* command_line = CommandLine::ForCurrentProcess(); 87 CommandLine* command_line = CommandLine::ForCurrentProcess();
75 return command_line->HasSwitch(switches::kSyncShowPromo); 88 return command_line->HasSwitch(switches::kSyncShowPromo);
76 } 89 }
90
91 bool IsFirstRun(Profile* profile) {
92 return FirstRun::IsChromeFirstRun();
93 }
94
95 bool SyncPromoUI::ShouldShowSyncPromoAtStartup(Profile* profile,
96 bool is_new_profile) {
97 if (!ShouldShowSyncPromo())
98 return false;
99
100 RegisterSyncPromoPrefs(profile);
101 if (!is_new_profile) {
102 if (!profile->GetPrefs()->HasPrefPath(prefs::kSyncPromoStartupCount))
103 return false;
104 }
105
106 int show_count = profile->GetPrefs()->GetInteger(
107 prefs::kSyncPromoStartupCount);
108 return show_count < kSyncPromoShowAtStartupMaxiumum;
109 }
110
111 void SyncPromoUI::DidShowSyncPromoAtStartup(Profile* profile) {
112 RegisterSyncPromoPrefs(profile);
113 int show_count = profile->GetPrefs()->GetInteger(
114 prefs::kSyncPromoStartupCount);
115 show_count++;
116 profile->GetPrefs()->SetInteger(prefs::kSyncPromoStartupCount, show_count);
117 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_promo_ui.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698