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

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

Issue 3522015: Implement new strategy for default apps (Closed)
Patch Set: all done Created 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/default_apps.h"
6
7 #include "base/command_line.h"
8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/pref_names.h"
11
12 const int DefaultApps::kAppsPromoCounterMax = 10;
13
14 // static
15 void DefaultApps::RegisterUserPrefs(PrefService* prefs) {
16 prefs->RegisterBooleanPref(prefs::kDefaultAppsInstalled, false);
17 prefs->RegisterIntegerPref(prefs::kAppsPromoCounter, 0);
18 }
19
20 DefaultApps::DefaultApps(PrefService* prefs)
21 : prefs_(prefs) {
22 // gmail, calendar, docs
23 ids_.insert("pjkljhegncpnkpknbcohdijeoejaedia");
24 ids_.insert("ejjicmeblgpmajnghnpcppodonldlgfn");
25 ids_.insert("apdfllckaahabafndbhieahigkjlhalf");
26 }
27
28 const ExtensionIdSet* DefaultApps::GetAppsToInstall() const {
29 if (GetDefaultAppsInstalled())
30 return NULL;
31 else
32 return &ids_;
33 }
34
35 void DefaultApps::DidInstallApp(const ExtensionIdSet& installed_ids) {
36 // If all the default apps have been installed, stop trying to install them.
37 // Note that we use std::includes here instead of == because apps might have
38 // been manually installed while the the default apps were installing and we
39 // wouldn't want to keep trying to install them in that case.
40 if (!GetDefaultAppsInstalled() &&
41 std::includes(installed_ids.begin(), installed_ids.end(),
42 ids_.begin(), ids_.end())) {
43 SetDefaultAppsInstalled(true);
44 }
45 }
46
47 bool DefaultApps::ShouldShowPromo(const ExtensionIdSet& installed_ids) {
48 if (CommandLine::ForCurrentProcess()->HasSwitch(
49 switches::kForceAppsPromoVisible)) {
50 return true;
51 }
52
53 if (GetDefaultAppsInstalled() && GetPromoCounter() < kAppsPromoCounterMax) {
54 // If we have the exact set of default apps, show the promo. If we don't
55 // have the exact set of default apps, this means that the user manually
56 // installed one. The promo doesn't make sense if it shows apps the user
57 // manually installed, so expire it immediately in that situation.
58 if (installed_ids == ids_)
59 return true;
60 else
61 SetPromoHidden();
62 }
63
64 return false;
65 }
66
67 void DefaultApps::DidShowPromo() {
68 if (!GetDefaultAppsInstalled()) {
69 NOTREACHED() << "Should not show promo until default apps are installed.";
70 return;
71 }
72
73 int promo_counter = GetPromoCounter();
74 if (promo_counter == kAppsPromoCounterMax) {
75 NOTREACHED() << "Promo has already been shown the maximum number of times.";
76 return;
77 }
78
79 if (promo_counter < kAppsPromoCounterMax)
80 SetPromoCounter(++promo_counter);
81 else
82 SetPromoHidden();
83 }
84
85 void DefaultApps::SetPromoHidden() {
86 SetPromoCounter(kAppsPromoCounterMax);
87 }
88
89 int DefaultApps::GetPromoCounter() const {
90 return prefs_->GetInteger(prefs::kAppsPromoCounter);
91 }
92
93 void DefaultApps::SetPromoCounter(int val) {
94 prefs_->SetInteger(prefs::kAppsPromoCounter, val);
95 prefs_->ScheduleSavePersistentPrefs();
96 }
97
98 bool DefaultApps::GetDefaultAppsInstalled() const {
99 return prefs_->GetBoolean(prefs::kDefaultAppsInstalled);
100 }
101
102 void DefaultApps::SetDefaultAppsInstalled(bool val) {
103 prefs_->SetBoolean(prefs::kDefaultAppsInstalled, val);
104 prefs_->ScheduleSavePersistentPrefs();
105 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/default_apps.h ('k') | chrome/browser/extensions/default_apps_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698