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

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

Issue 6040005: More cleanup of DefaultApps code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unnecessary change, add comments Created 9 years, 11 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 #ifndef CHROME_BROWSER_EXTENSIONS_DEFAULT_APPS_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_DEFAULT_APPS_H_
6 #define CHROME_BROWSER_EXTENSIONS_DEFAULT_APPS_H_ 6 #define CHROME_BROWSER_EXTENSIONS_DEFAULT_APPS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 13
14 class PrefService; 14 class PrefService;
15 15
16 // Manages the installation of the set of default apps into Chrome, and the 16 // Encapsulates business logic for:
17 // promotion of those apps in the launcher. 17 // - Whether to install default apps on Chrome startup
18 // 18 // - Whether to show the app launcher
19 // It implements the following rules: 19 // - Whether to show the apps promo in the launcher
20 //
21 // - Only install default apps once per-profile.
22 // - Don't install default apps if any apps are already installed.
23 // - Do not start showing the promo until all default apps have been installed.
24 // - Do not show the promo if it has been hidden by the user.
25 // - Do not show promo after one app has been manually installed or uninstalled.
26 // - Do not show promo if the set of installed apps is different than the set of
27 // default apps.
28 // - Only show promo a certain amount of times.
29 //
30 // The promo can also be forced on with --force-apps-promo-visible.
31 class DefaultApps { 20 class DefaultApps {
32 public: 21 public:
33 // The maximum number of times to show the apps promo. 22 // The maximum number of times to show the apps promo.
34 static const int kAppsPromoCounterMax; 23 static const int kAppsPromoCounterMax;
35 24
36 // Register our preferences. 25 // Register our preferences.
37 static void RegisterUserPrefs(PrefService* prefs); 26 static void RegisterUserPrefs(PrefService* prefs);
38 27
39 explicit DefaultApps(PrefService* prefs); 28 explicit DefaultApps(PrefService* prefs,
29 const std::string& application_locale);
40 ~DefaultApps(); 30 ~DefaultApps();
41 31
42 // Gets the list of default apps that should be installed. Can return NULL if 32 // Gets the set of default apps.
43 // no apps need to be installed. 33 const ExtensionIdSet& default_apps() const;
44 const ExtensionIdSet* GetAppsToInstall() const;
45 34
46 // Gets the list of default apps. 35 // Returns true if the default apps should be installed.
47 const ExtensionIdSet* GetDefaultApps() const; 36 bool ShouldInstallDefaultApps(const ExtensionIdSet& installed_ids);
48 37
49 // Returns true if the default apps have been installed. False otherwise. 38 // Returns true if the app launcher in the NTP should be shown.
50 bool GetDefaultAppsInstalled() const; 39 bool ShouldShowAppLauncher(const ExtensionIdSet& installed_ids);
40
41 // Returns true if the apps promo should be displayed in the launcher.
42 //
43 // NOTE: If the default apps have been installed, but |installed_ids| is
44 // different than GetDefaultApps(), this will permanently expire the promo.
45 bool ShouldShowPromo(const ExtensionIdSet& installed_ids);
51 46
52 // Should be called after each app is installed. Once installed_ids contains 47 // Should be called after each app is installed. Once installed_ids contains
53 // all the default apps, GetAppsToInstall() will start returning NULL. 48 // all the default apps, GetAppsToInstall() will start returning NULL.
54 void DidInstallApp(const ExtensionIdSet& installed_ids); 49 void DidInstallApp(const ExtensionIdSet& installed_ids);
55 50
56 // Returns true if the apps promo should be displayed in the launcher.
57 //
58 // NOTE: If the default apps have been installed, but |installed_ids| is
59 // different than GetDefaultApps(), this will permanently expire the promo.
60 bool CheckShouldShowPromo(const ExtensionIdSet& installed_ids);
61
62 // Should be called after each time the promo is installed. 51 // Should be called after each time the promo is installed.
63 void DidShowPromo(); 52 void DidShowPromo();
64 53
65 // Force the promo to be hidden. 54 // Force the promo to be hidden.
66 void SetPromoHidden(); 55 void SetPromoHidden();
67 56
68 private: 57 private:
69 FRIEND_TEST_ALL_PREFIXES(ExtensionDefaultApps, Basics); 58 FRIEND_TEST_ALL_PREFIXES(ExtensionDefaultApps, HappyPath);
59 FRIEND_TEST_ALL_PREFIXES(ExtensionDefaultApps, UnsupportedLocale);
70 FRIEND_TEST_ALL_PREFIXES(ExtensionDefaultApps, HidePromo); 60 FRIEND_TEST_ALL_PREFIXES(ExtensionDefaultApps, HidePromo);
71 FRIEND_TEST_ALL_PREFIXES(ExtensionDefaultApps, InstallingAnAppHidesPromo); 61 FRIEND_TEST_ALL_PREFIXES(ExtensionDefaultApps, InstallingAnAppHidesPromo);
72 FRIEND_TEST_ALL_PREFIXES(ExtensionDefaultApps, 62 FRIEND_TEST_ALL_PREFIXES(ExtensionDefaultApps,
73 ManualAppInstalledWhileInstallingDefaultApps); 63 ManualAppInstalledWhileInstallingDefaultApps);
74 64
65 bool DefaultAppSupported();
66 bool DefaultAppsSupportedForLanguage();
67
68 bool NonDefaultAppIsInstalled(const ExtensionIdSet& installed_ids) const;
69
70 bool GetDefaultAppsInstalled() const;
75 void SetDefaultAppsInstalled(bool val); 71 void SetDefaultAppsInstalled(bool val);
76 72
77 int GetPromoCounter() const; 73 int GetPromoCounter() const;
78 void SetPromoCounter(int val); 74 void SetPromoCounter(int val);
79 75
80 // Our permanent state is stored in this PrefService instance. 76 // Our permanent state is stored in this PrefService instance.
81 PrefService* prefs_; 77 PrefService* prefs_;
82 78
79 // The locale the browser is currently in.
80 std::string application_locale_;
81
83 // The set of default extensions. Initialized to a static list in the 82 // The set of default extensions. Initialized to a static list in the
84 // constructor. 83 // constructor.
85 ExtensionIdSet ids_; 84 ExtensionIdSet ids_;
86 85
87 DISALLOW_COPY_AND_ASSIGN(DefaultApps); 86 DISALLOW_COPY_AND_ASSIGN(DefaultApps);
88 }; 87 };
89 88
90 #endif // CHROME_BROWSER_EXTENSIONS_DEFAULT_APPS_H_ 89 #endif // CHROME_BROWSER_EXTENSIONS_DEFAULT_APPS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698